Skip to content

Latest commit

 

History

History
45 lines (30 loc) · 1.12 KB

File metadata and controls

45 lines (30 loc) · 1.12 KB
title LangChainAdapter
description CopilotKit Adapter for LangChain

{/* GENERATE-DOCS path=packages/backend/src/lib/langchain-adapter.ts class=LangChainAdapter */}

Use this adapter to use LangChain as a backend.

return copilotKit.response(
  req,
  new LangChainAdapter(async (forwardedProps) => {
    const model = new ChatOpenAI({ modelName: "gpt-4o" });
    return model.stream(forwardedProps.messages, {
      tools: forwardedProps.tools,
    });
  })
);

The async handler function can return:

  • a simple string response
  • a LangChain stream IterableReadableStream
  • a LangChain BaseMessageChunk object
  • a LangChain AIMessage object

Constructor

constructor(private chainFn: (forwardedProps: any) => Promise<LangChainReturnType>)

To use LangChain as a backend, provide a handler function to the adapter with your custom LangChain logic.

getResponse(forwardedProps: any)