forked from CopilotKit/CopilotKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathroute.ts
More file actions
43 lines (39 loc) · 1014 Bytes
/
Copy pathroute.ts
File metadata and controls
43 lines (39 loc) · 1014 Bytes
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
import {
CopilotRuntime,
LangChainAdapter,
copilotRuntimeNextJSAppRouterEndpoint,
} from "@copilotkit/runtime";
import { ChatOpenAI } from "@langchain/openai";
const runtime = new CopilotRuntime({
actions: [
{
name: "sayHello",
description: "Says hello to someone.",
parameters: [
{
name: "arg",
type: "string",
description: "The name of the person to say hello to.",
required: true,
},
],
handler: async ({ arg }) => {
console.log("Hello from the server", arg, "!");
},
},
],
});
const serviceAdapter = new LangChainAdapter({
chainFn: async ({ messages, tools }) => {
const model = new ChatOpenAI({ modelName: "gpt-4-1106-preview" }).bind(
tools as any,
);
return model.stream(messages);
},
});
export const { GET, POST, OPTIONS } = copilotRuntimeNextJSAppRouterEndpoint({
runtime,
serviceAdapter,
endpoint: "/api/copilotkit/langchain",
debug: true,
}) as any;