Skip to content

Latest commit

 

History

History
41 lines (28 loc) · 1017 Bytes

File metadata and controls

41 lines (28 loc) · 1017 Bytes
title LangChainAdapter
description CopilotKit Adapter for LangChain

{/* GENERATE-DOCS path=packages/runtime/src/service-adapters/langchain/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

process(request: CopilotRuntimeChatCompletionRequest)