@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 5.18 kB
Source Map (JSON)
{"version":3,"file":"branch.d.cts","names":["Runnable","RunnableLike","RunnableConfig","CallbackManagerForChainRun","Branch","RunInput","RunOutput","BranchLike","RunnableBranch","Partial","Promise","Awaited","AsyncGenerator"],"sources":["../../src/runnables/branch.d.ts"],"sourcesContent":["import { Runnable, RunnableLike } from \"./base.js\";\nimport { RunnableConfig } from \"./config.js\";\nimport { CallbackManagerForChainRun } from \"../callbacks/manager.js\";\n/**\n * Type for a branch in the RunnableBranch. It consists of a condition\n * runnable and a branch runnable. The condition runnable is used to\n * determine whether the branch should be executed, and the branch runnable\n * is executed if the condition is true.\n */\nexport type Branch<RunInput, RunOutput> = [\n Runnable<RunInput, boolean>,\n Runnable<RunInput, RunOutput>\n];\nexport type BranchLike<RunInput, RunOutput> = [\n RunnableLike<RunInput, boolean>,\n RunnableLike<RunInput, RunOutput>\n];\n/**\n * Class that represents a runnable branch. The RunnableBranch is\n * initialized with an array of branches and a default branch. When invoked,\n * it evaluates the condition of each branch in order and executes the\n * corresponding branch if the condition is true. If none of the conditions\n * are true, it executes the default branch.\n * @example\n * ```typescript\n * const branch = RunnableBranch.from([\n * [\n * (x: { topic: string; question: string }) =>\n * x.topic.toLowerCase().includes(\"anthropic\"),\n * anthropicChain,\n * ],\n * [\n * (x: { topic: string; question: string }) =>\n * x.topic.toLowerCase().includes(\"langchain\"),\n * langChainChain,\n * ],\n * generalChain,\n * ]);\n *\n * const fullChain = RunnableSequence.from([\n * {\n * topic: classificationChain,\n * question: (input: { question: string }) => input.question,\n * },\n * branch,\n * ]);\n *\n * const result = await fullChain.invoke({\n * question: \"how do I use LangChain?\",\n * });\n * ```\n */\nexport declare class RunnableBranch<RunInput = any, RunOutput = any> extends Runnable<RunInput, RunOutput> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n default: Runnable<RunInput, RunOutput>;\n branches: Branch<RunInput, RunOutput>[];\n constructor(fields: {\n branches: Branch<RunInput, RunOutput>[];\n default: Runnable<RunInput, RunOutput>;\n });\n /**\n * Convenience method for instantiating a RunnableBranch from\n * RunnableLikes (objects, functions, or Runnables).\n *\n * Each item in the input except for the last one should be a\n * tuple with two items. The first is a \"condition\" RunnableLike that\n * returns \"true\" if the second RunnableLike in the tuple should run.\n *\n * The final item in the input should be a RunnableLike that acts as a\n * default branch if no other branches match.\n *\n * @example\n * ```ts\n * import { RunnableBranch } from \"@langchain/core/runnables\";\n *\n * const branch = RunnableBranch.from([\n * [(x: number) => x > 0, (x: number) => x + 1],\n * [(x: number) => x < 0, (x: number) => x - 1],\n * (x: number) => x\n * ]);\n * ```\n * @param branches An array where the every item except the last is a tuple of [condition, runnable]\n * pairs. The last item is a default runnable which is invoked if no other condition matches.\n * @returns A new RunnableBranch.\n */\n static from<RunInput = any, RunOutput = any>(branches: [\n ...BranchLike<RunInput, RunOutput>[],\n RunnableLike<RunInput, RunOutput>\n ]): RunnableBranch<RunInput, RunOutput>;\n _invoke(input: RunInput, config?: Partial<RunnableConfig>, runManager?: CallbackManagerForChainRun): Promise<RunOutput>;\n invoke(input: RunInput, config?: RunnableConfig): Promise<RunOutput>;\n _streamIterator(input: RunInput, config?: Partial<RunnableConfig>): AsyncGenerator<Awaited<RunOutput>, void, unknown>;\n}\n//# sourceMappingURL=branch.d.ts.map"],"mappings":";;;;;;;;AASA;;;;AAEuBM,KAFXF,MAEWE,CAAAA,QAAAA,EAAAA,SAAAA,CAAAA,GAAAA,CADnBN,QACAA,CADSK,QACTL,EAAAA,OAAAA,CAAAA,EAAAA,QAAQ,CAACK,QAAD,EAAWC,SAAX,CAAA,CAEZ;AACiBD,KADLE,UACKF,CAAAA,QAAAA,EAAAA,SAAAA,CAAAA,GAAAA,CAAbJ,YAAAA,CAAaI,QAAbJ,EAAAA,OAAAA,CAAAA,EACAA,YAAaI,CAAAA,QAAAA,EAAUC,SAAVD,CAAAA,CAAUC;;AAAX;AAqChB;;;;;;;;;;;;;;;;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