Files
Markus Ecker 004353f67b QA / fixes (#409)
* add debug configuration

* gracefully handle server actions without return values

* remove log

* update langserve QA

* rename interface

* update langchain streaming

* fix langserve bugs

* langchain adapter plus streaming

* make gemini work

* clean up

* update pages router qa
2024-06-27 14:58:42 +00:00

42 lines
1001 B
TypeScript

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;