UNPKG

@langchain/core

Version:
1 lines 4.32 kB
{"version":3,"file":"passthrough.d.ts","names":["Runnable","RunnableAssign","RunnableMapLike","RunnableConfig","RunnablePassthroughFunc","RunInput","Promise","RunnablePassthrough","RunOutput","Partial","AsyncGenerator","Record"],"sources":["../../src/runnables/passthrough.d.ts"],"sourcesContent":["import { Runnable, RunnableAssign, RunnableMapLike } from \"./base.js\";\nimport { type RunnableConfig } from \"./config.js\";\ntype RunnablePassthroughFunc<RunInput = any> = ((input: RunInput) => void) | ((input: RunInput, config?: RunnableConfig) => void) | ((input: RunInput) => Promise<void>) | ((input: RunInput, config?: RunnableConfig) => Promise<void>);\n/**\n * A runnable to passthrough inputs unchanged or with additional keys.\n *\n * This runnable behaves almost like the identity function, except that it\n * can be configured to add additional keys to the output, if the input is\n * an object.\n *\n * The example below demonstrates how to use `RunnablePassthrough to\n * passthrough the input from the `.invoke()`\n *\n * @example\n * ```typescript\n * const chain = RunnableSequence.from([\n * {\n * question: new RunnablePassthrough(),\n * context: async () => loadContextFromStore(),\n * },\n * prompt,\n * llm,\n * outputParser,\n * ]);\n * const response = await chain.invoke(\n * \"I can pass a single string instead of an object since I'm using `RunnablePassthrough`.\"\n * );\n * ```\n */\nexport declare class RunnablePassthrough<RunInput = any> extends Runnable<RunInput, RunInput> {\n static lc_name(): string;\n lc_namespace: string[];\n lc_serializable: boolean;\n func?: RunnablePassthroughFunc<RunInput>;\n constructor(fields?: {\n func?: RunnablePassthroughFunc<RunInput>;\n });\n invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;\n transform(generator: AsyncGenerator<RunInput>, options: Partial<RunnableConfig>): AsyncGenerator<RunInput>;\n /**\n * A runnable that assigns key-value pairs to the input.\n *\n * The example below shows how you could use it with an inline function.\n *\n * @example\n * ```typescript\n * const prompt =\n * PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}\n * Question: {question}\n * SQL Query:`);\n *\n * // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`\n * // call (in this example it's the question), along with any inputs passed to the `.assign()` method.\n * // In this case, we're passing the schema.\n * const sqlQueryGeneratorChain = RunnableSequence.from([\n * RunnablePassthrough.assign({\n * schema: async () => db.getTableInfo(),\n * }),\n * prompt,\n * new ChatOpenAI({ model: \"gpt-4o-mini\" }).withConfig({ stop: [\"\\nSQLResult:\"] }),\n * new StringOutputParser(),\n * ]);\n * const result = await sqlQueryGeneratorChain.invoke({\n * question: \"How many employees are there?\",\n * });\n * ```\n */\n static assign<RunInput extends Record<string, unknown> = Record<string, unknown>, RunOutput extends Record<string, unknown> = Record<string, unknown>>(mapping: RunnableMapLike<RunInput, RunOutput>): RunnableAssign<RunInput, RunInput & RunOutput>;\n}\nexport {};\n//# sourceMappingURL=passthrough.d.ts.map"],"mappings":";;;;;KAEKI,mDAAmDC,8BAA8BA,mBAAmBF,oCAAoCE,aAAaC,0BAA0BD,mBAAmBF,mBAAmBG;;;AADxK;;;;;;;;;AAC+K;AA2BjO;;;;;;;;;;;;;;AASoEH,cAT/CI,mBAS+CJ,CAAAA,WAAAA,GAAAA,CAAAA,SATHH,QASGG,CATME,QASNF,EATgBE,QAShBF,CAAAA,CAAAA;EAARM,OAAAA,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAyCJ,YAAAA,EAAAA,MAAAA,EAAAA;EAAfK,eAAAA,EAAAA,OAAAA;EA6BnDC,IAAAA,CAAAA,EAlCxBP,uBAkCwBO,CAlCAN,QAkCAM,CAAAA;EAA0BA,WAAAA,CAAAA,MAAqEA,CAArEA,EAAAA;IAA2CA,IAAAA,CAAAA,EAhCzFP,uBAgCyFO,CAhCjEN,QAgCiEM,CAAAA;EAA0BA,CAAAA;EAAkDN,MAAAA,CAAAA,KAAAA,EA9BlKA,QA8BkKA,EAAAA,OAAAA,CAAAA,EA9B9II,OA8B8IJ,CA9BtIF,cA8BsIE,CAAAA,CAAAA,EA9BpHC,OA8BoHD,CA9B5GA,QA8B4GA,CAAAA;EAAUG,SAAAA,CAAAA,SAAAA,EA7BrKE,cA6BqKF,CA7BtJH,QA6BsJG,CAAAA,EAAAA,OAAAA,EA7BlIC,OA6BkID,CA7B1HL,cA6B0HK,CAAAA,CAAAA,EA7BxGE,cA6BwGF,CA7BzFH,QA6ByFG,CAAAA;EAA1BN;;;;;;AAtC3F;;;;;;;;;;;;;;;;;;;;;;iCAsCtCS,0BAA0BA,2CAA2CA,0BAA0BA,kCAAkCT,gBAAgBG,UAAUG,aAAaP,eAAeI,UAAUA,WAAWG"}