{"version":3,"file":"llm_router.cjs","names":["RouterChain","LLMChain"],"sources":["../../../src/chains/router/llm_router.ts"],"sourcesContent":["import type { BaseLanguageModelInterface } from \"@langchain/core/language_models/base\";\nimport { ChainValues } from \"@langchain/core/utils/types\";\nimport { BasePromptTemplate } from \"@langchain/core/prompts\";\nimport { CallbackManagerForChainRun } from \"@langchain/core/callbacks/manager\";\nimport { LLMChain } from \"../../chains/llm_chain.js\";\nimport { RouterChain } from \"./multi_route.js\";\nimport { ChainInputs } from \"../../chains/base.js\";\n\n/**\n * A type that represents the output schema of a router chain. It defines\n * the structure of the output data returned by the router chain.\n */\nexport type RouterOutputSchema = {\n  destination: string;\n  next_inputs: { [key: string]: string };\n};\n\n/**\n * An interface that extends the default ChainInputs interface and adds an\n * additional \"llmChain\" property.\n */\nexport interface LLMRouterChainInput extends ChainInputs {\n  llmChain: LLMChain<RouterOutputSchema>;\n}\n\n/**\n * A class that represents an LLM router chain in the LangChain framework.\n * It extends the RouterChain class and implements the LLMRouterChainInput\n * interface. It provides additional functionality specific to LLMs and\n * routing based on LLM predictions.\n */\nexport class LLMRouterChain extends RouterChain implements LLMRouterChainInput {\n  llmChain: LLMChain<RouterOutputSchema>;\n\n  constructor(fields: LLMRouterChainInput) {\n    super(fields);\n    this.llmChain = fields.llmChain;\n  }\n\n  get inputKeys(): string[] {\n    return this.llmChain.inputKeys;\n  }\n\n  async _call(\n    values: ChainValues,\n    runManager?: CallbackManagerForChainRun | undefined\n  ): Promise<RouterOutputSchema> {\n    return this.llmChain.predict(values, runManager?.getChild());\n  }\n\n  _chainType(): string {\n    return \"llm_router_chain\";\n  }\n\n  /**\n   * A static method that creates an instance of LLMRouterChain from a\n   * BaseLanguageModel and a BasePromptTemplate. It takes in an optional\n   * options object and returns an instance of LLMRouterChain with the\n   * specified LLMChain.\n   * @param llm A BaseLanguageModel instance.\n   * @param prompt A BasePromptTemplate instance.\n   * @param options Optional LLMRouterChainInput object, excluding \"llmChain\".\n   * @returns An instance of LLMRouterChain.\n   */\n  static fromLLM(\n    llm: BaseLanguageModelInterface,\n    prompt: BasePromptTemplate,\n    options?: Omit<LLMRouterChainInput, \"llmChain\">\n  ) {\n    const llmChain = new LLMChain<RouterOutputSchema>({ llm, prompt });\n    return new LLMRouterChain({ ...options, llmChain });\n  }\n}\n"],"mappings":";;;;;;;;;AA+BA,IAAa,iBAAb,MAAa,uBAAuBA,oBAAAA,YAA2C;CAC7E;CAEA,YAAY,QAA6B;AACvC,QAAM,OAAO;AACb,OAAK,WAAW,OAAO;;CAGzB,IAAI,YAAsB;AACxB,SAAO,KAAK,SAAS;;CAGvB,MAAM,MACJ,QACA,YAC6B;AAC7B,SAAO,KAAK,SAAS,QAAQ,QAAQ,YAAY,UAAU,CAAC;;CAG9D,aAAqB;AACnB,SAAO;;;;;;;;;;;;CAaT,OAAO,QACL,KACA,QACA,SACA;EACA,MAAM,WAAW,IAAIC,kBAAAA,SAA6B;GAAE;GAAK;GAAQ,CAAC;AAClE,SAAO,IAAI,eAAe;GAAE,GAAG;GAAS;GAAU,CAAC"}