UNPKG

@langchain/core

Version:
1 lines 4.39 kB
{"version":3,"file":"passthrough.d.ts","names":["Runnable","RunnableAssign","RunnableMapLike","RunnableConfig","RunnablePassthroughFunc","RunInput","Promise","RunnablePassthrough","Partial","AsyncGenerator","Record","RunOutput"],"sources":["../../src/runnables/passthrough.d.ts"],"sourcesContent":["import { Runnable, RunnableAssign, RunnableMapLike } from \"./base.js\";\nimport { type RunnableConfig } from \"./config.js\";\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\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 */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\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"],"mappings":";;;;;KAGKI,mDAAmDC,8BAA8BA,mBAAmBF,oCAAoCE,aAAaC,0BAA0BD,mBAAmBF,mBAAmBG;AAFxK;;;;;;;;;;AAE+K;AA4BjO;;;;;;;;;;;;;;;;AAS4DE,cATvCD,mBASuCC,CAAAA,WAAAA,GAAAA,CAAAA,SATKR,QASLQ,CATcH,QASdG,EATwBH,QASxBG,CAAAA,CAAAA;EAAO,OAAkCH,OAAAA,CAAAA,CAAAA,EAAAA,MAAAA;EAAQ,YAAvBI,EAAAA,MAAAA,EAAAA;EAAc,eA6BjEC,EAAAA,OAAAA;EAAM,IAAoBA,CAAAA,EAlClDN,uBAkCkDM,CAlC1BL,QAkC0BK,CAAAA;EAAM,WAAqCA,CAAAA,MAAgC,CAAhCA,EAAAA;IAA0BA,IAAAA,CAAAA,EAhCnHN,uBAgCmHM,CAhC3FL,QAgC2FK,CAAAA;EAAM,CAAA;EAAoD,MAAEC,CAAAA,KAAAA,EA9B5KN,QA8B4KM,EAAAA,OAAAA,CAAAA,EA9BxJH,OA8BwJG,CA9BhJR,cA8BgJQ,CAAAA,CAAAA,EA9B9HL,OA8B8HK,CA9BtHN,QA8BsHM,CAAAA;EAAS,SAAnCT,CAAAA,SAAAA,EA7B3IO,cA6B2IP,CA7B5HG,QA6B4HH,CAAAA,EAAAA,OAAAA,EA7BxGM,OA6BwGN,CA7BhGC,cA6BgGD,CAAAA,CAAAA,EA7B9EO,cA6B8EP,CA7B/DG,QA6B+DH,CAAAA;EAAe;;;;;AAtC1G;;;;;;;;;;;;;;;;;;;;;;;iCAsCtCQ,0BAA0BA,2CAA2CA,0BAA0BA,kCAAkCR,gBAAgBG,UAAUM,aAAaV,eAAeI,UAAUA,WAAWM"}