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
63 lines (55 loc) · 1.43 KB
/
Copy pathindex.ts
File metadata and controls
63 lines (55 loc) · 1.43 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
52
53
54
55
56
57
58
59
60
61
62
63
import express from "express";
import * as dotenv from "dotenv";
dotenv.config();
import {
CopilotRuntime,
OpenAIAdapter,
copilotRuntimeNodeExpressEndpoint,
} from "@copilotkit/runtime";
import OpenAI from "openai";
import { BuiltInAgent } from "@copilotkit/runtime/v2";
import cors from "cors";
const openai = new OpenAI();
const serviceAdapter = new OpenAIAdapter({ openai: openai as any });
const runtime = new CopilotRuntime({
agents: {
default: new BuiltInAgent({ model: "openai/gpt-4o-mini" }),
},
actions: [
{
name: "sayHello",
description: "say hello so someone by roasting their name",
parameters: [
{
name: "roast",
description: "A sentence or two roasting the name of the person",
type: "string",
required: true,
},
],
handler: ({ roast }: { roast: string }) => {
console.log(roast);
return "The person has been roasted.";
},
},
],
});
const copilotRuntime = copilotRuntimeNodeExpressEndpoint({
endpoint: "/",
runtime,
serviceAdapter,
});
const app = express();
app.use(
cors({
origin: "*",
methods: ["GET", "POST", "OPTIONS", "PUT", "DELETE", "PATCH"],
allowedHeaders: ["*"],
}),
);
// Uncomment this line to parse the request body
// app.use(express.json());
app.use("/copilotkit", copilotRuntime);
app.listen(4000, () => {
console.log("Listening at http://localhost:4000/copilotkit");
});