forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
51 lines (44 loc) · 1.06 KB
/
Copy pathindex.ts
File metadata and controls
51 lines (44 loc) · 1.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import express from "express";
import dotenv from "dotenv";
import { z } from "zod";
import {
CopilotRuntime,
createCopilotEndpointSingleRouteExpress,
BuiltInAgent,
defineTool,
ToolDefinition,
} from "@copilotkit/runtime/v2";
dotenv.config();
const roastTool = defineTool({
name: "sayHello",
description: "Say hello while roasting the user's name",
parameters: z.object({
roast: z.string().describe("A playful roast about the user's name"),
}),
execute: async ({ roast }) => {
console.log(roast);
return "The person has been roasted.";
},
}) as unknown as ToolDefinition;
const runtime = new CopilotRuntime({
agents: {
default: new BuiltInAgent({
model: "openai/gpt-4o-mini",
tools: [roastTool],
}),
},
});
const app = express();
app.use(
"/api/copilotkit",
createCopilotEndpointSingleRouteExpress({
runtime,
basePath: "/",
}),
);
const port = Number(process.env.PORT ?? 4000);
app.listen(port, () => {
console.log(
`CopilotKit v2 runtime listening at http://localhost:${port}/api/copilotkit`,
);
});