From 25a6a9c9ec96f48f38b57a8691c4230a78fa0bd7 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Sun, 3 Dec 2023 16:21:24 -0800 Subject: [PATCH 1/3] core[fix]: RunnableFunc config types --- examples/src/chains/map_reduce_lcel.ts | 8 +++++--- examples/src/embeddings/gradient_ai.ts | 2 +- langchain-core/src/runnables/base.ts | 7 ++++--- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/examples/src/chains/map_reduce_lcel.ts b/examples/src/chains/map_reduce_lcel.ts index ff0b9bec3c55..a6ff6fe02b6d 100644 --- a/examples/src/chains/map_reduce_lcel.ts +++ b/examples/src/chains/map_reduce_lcel.ts @@ -62,10 +62,12 @@ const collapseChain = RunnableSequence.from([ // Define a function to collapse a list of documents until the total number of tokens is within the limit const collapse = async ( documents: Document[], - config?: BaseCallbackConfig, + options?: { + config?: BaseCallbackConfig + }, tokenMax = 4000 ) => { - const editableConfig = config; + const editableConfig = options?.config; let docs = documents; let collapseCount = 1; while ((await getNumTokens(docs)) > tokenMax) { @@ -101,7 +103,7 @@ const mapReduceChain = RunnableSequence.from([ ]) .withConfig({ runName: "Summarize (return doc)" }) .map(), - collapse, + collapse, reduceChain, ]).withConfig({ runName: "Map reduce" }); diff --git a/examples/src/embeddings/gradient_ai.ts b/examples/src/embeddings/gradient_ai.ts index a749c2dc494e..f4957bf2d527 100644 --- a/examples/src/embeddings/gradient_ai.ts +++ b/examples/src/embeddings/gradient_ai.ts @@ -1,6 +1,6 @@ import { GradientEmbeddings } from "langchain/embeddings/gradient_ai"; -const model = new GradientEmbeddings(); +const model = new GradientEmbeddings({}); const res = await model.embedQuery( "What would be a good company name a company that makes colorful socks?" ); diff --git a/langchain-core/src/runnables/base.ts b/langchain-core/src/runnables/base.ts index 697bc59f095a..624a122fe00b 100644 --- a/langchain-core/src/runnables/base.ts +++ b/langchain-core/src/runnables/base.ts @@ -24,9 +24,10 @@ import { RootListenersTracer } from "../tracers/root_listener.js"; export type RunnableFunc = ( input: RunInput, // eslint-disable-next-line @typescript-eslint/no-explicit-any - options?: Record & { - config?: RunnableConfig; - } + options?: + | { config?: RunnableConfig } + | Record + | (Record & { config: RunnableConfig }) ) => RunOutput | Promise; // eslint-disable-next-line @typescript-eslint/no-explicit-any From 9de5944dcb21dcb572fa618681fa639e391f06d9 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Sun, 3 Dec 2023 16:24:52 -0800 Subject: [PATCH 2/3] cr --- examples/src/chains/map_reduce_lcel.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/src/chains/map_reduce_lcel.ts b/examples/src/chains/map_reduce_lcel.ts index a6ff6fe02b6d..5615a62500a3 100644 --- a/examples/src/chains/map_reduce_lcel.ts +++ b/examples/src/chains/map_reduce_lcel.ts @@ -63,7 +63,7 @@ const collapseChain = RunnableSequence.from([ const collapse = async ( documents: Document[], options?: { - config?: BaseCallbackConfig + config?: BaseCallbackConfig; }, tokenMax = 4000 ) => { @@ -103,7 +103,7 @@ const mapReduceChain = RunnableSequence.from([ ]) .withConfig({ runName: "Summarize (return doc)" }) .map(), - collapse, + collapse, reduceChain, ]).withConfig({ runName: "Map reduce" }); From ae16bdb55d3490809408a925fd716189191150f2 Mon Sep 17 00:00:00 2001 From: Brace Sproul Date: Sun, 3 Dec 2023 16:36:39 -0800 Subject: [PATCH 3/3] chore: lint files --- langchain-core/src/runnables/base.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/langchain-core/src/runnables/base.ts b/langchain-core/src/runnables/base.ts index 624a122fe00b..bd97724a15a0 100644 --- a/langchain-core/src/runnables/base.ts +++ b/langchain-core/src/runnables/base.ts @@ -23,10 +23,11 @@ import { RootListenersTracer } from "../tracers/root_listener.js"; export type RunnableFunc = ( input: RunInput, - // eslint-disable-next-line @typescript-eslint/no-explicit-any options?: | { config?: RunnableConfig } + // eslint-disable-next-line @typescript-eslint/no-explicit-any | Record + // eslint-disable-next-line @typescript-eslint/no-explicit-any | (Record & { config: RunnableConfig }) ) => RunOutput | Promise;