mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
46 lines
1.2 KiB
TypeScript
46 lines
1.2 KiB
TypeScript
import { createHonoServer } from "react-router-hono-server/node";
|
|
import {
|
|
CopilotRuntime,
|
|
createCopilotEndpoint,
|
|
InMemoryAgentRunner,
|
|
} from "@copilotkit/runtime/v2";
|
|
import { BuiltInAgent } from "@copilotkit/runtime/v2";
|
|
import { chat } from "@tanstack/ai";
|
|
import { openaiText } from "@tanstack/ai-openai";
|
|
import { TanStackAIAgent } from "./agent";
|
|
|
|
export default await createHonoServer({
|
|
configure(app) {
|
|
const tanstackAgent = new TanStackAIAgent(
|
|
({ messages, systemPrompts, abortController }) =>
|
|
chat({
|
|
adapter: openaiText("gpt-4o"),
|
|
messages,
|
|
systemPrompts,
|
|
abortController,
|
|
}),
|
|
);
|
|
|
|
const builtinAgent = new BuiltInAgent({
|
|
model: "openai/gpt-4o",
|
|
prompt:
|
|
"You are a helpful assistant. When the user sends images or files, describe what you see or analyze the content.",
|
|
});
|
|
|
|
const runtime = new CopilotRuntime({
|
|
agents: {
|
|
tanstack: tanstackAgent,
|
|
builtin: builtinAgent,
|
|
},
|
|
runner: new InMemoryAgentRunner(),
|
|
});
|
|
|
|
const copilotEndpoint = createCopilotEndpoint({
|
|
runtime,
|
|
basePath: "/api/copilotkit",
|
|
});
|
|
|
|
app.route("/", copilotEndpoint);
|
|
},
|
|
});
|