langchain 0.0.152 → 0.0.153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chat_models/fireworks.cjs +1 -0
- package/chat_models/fireworks.d.ts +1 -0
- package/chat_models/fireworks.js +1 -0
- package/dist/agents/executor.cjs +9 -2
- package/dist/agents/executor.js +9 -2
- package/dist/base_language/count_tokens.cjs +1 -1
- package/dist/base_language/count_tokens.js +1 -1
- package/dist/chains/openai_functions/structured_output.d.ts +2 -2
- package/dist/chat_models/base.d.ts +1 -1
- package/dist/chat_models/fireworks.cjs +81 -0
- package/dist/chat_models/fireworks.d.ts +33 -0
- package/dist/chat_models/fireworks.js +77 -0
- package/dist/chat_models/ollama.cjs +22 -5
- package/dist/chat_models/ollama.d.ts +1 -2
- package/dist/chat_models/ollama.js +22 -5
- package/dist/chat_models/openai.d.ts +2 -2
- package/dist/llms/fireworks.cjs +92 -0
- package/dist/llms/fireworks.d.ts +33 -0
- package/dist/llms/fireworks.js +88 -0
- package/dist/llms/ollama.cjs +24 -8
- package/dist/llms/ollama.d.ts +1 -2
- package/dist/llms/ollama.js +24 -8
- package/dist/llms/openai-chat.cjs +1 -5
- package/dist/llms/openai-chat.d.ts +1 -1
- package/dist/llms/openai-chat.js +1 -5
- package/dist/llms/openai.cjs +1 -1
- package/dist/llms/openai.d.ts +2 -2
- package/dist/llms/openai.js +1 -1
- package/dist/load/import_map.cjs +4 -2
- package/dist/load/import_map.d.ts +2 -0
- package/dist/load/import_map.js +2 -0
- package/dist/schema/output_parser.cjs +38 -6
- package/dist/schema/output_parser.d.ts +20 -5
- package/dist/schema/output_parser.js +38 -6
- package/dist/schema/runnable/base.cjs +65 -10
- package/dist/schema/runnable/base.d.ts +17 -3
- package/dist/schema/runnable/base.js +65 -10
- package/dist/util/ollama.cjs +2 -2
- package/dist/util/ollama.d.ts +6 -0
- package/dist/util/ollama.js +2 -2
- package/llms/fireworks.cjs +1 -0
- package/llms/fireworks.d.ts +1 -0
- package/llms/fireworks.js +1 -0
- package/package.json +17 -1
package/dist/llms/ollama.js
CHANGED
|
@@ -287,14 +287,30 @@ export class Ollama extends LLM {
|
|
|
287
287
|
async *_streamResponseChunks(prompt, options, runManager) {
|
|
288
288
|
const stream = await this.caller.call(async () => createOllamaStream(this.baseUrl, { ...this.invocationParams(options), prompt }, options));
|
|
289
289
|
for await (const chunk of stream) {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
290
|
+
if (!chunk.done) {
|
|
291
|
+
yield new GenerationChunk({
|
|
292
|
+
text: chunk.response,
|
|
293
|
+
generationInfo: {
|
|
294
|
+
...chunk,
|
|
295
|
+
response: undefined,
|
|
296
|
+
},
|
|
297
|
+
});
|
|
298
|
+
await runManager?.handleLLMNewToken(chunk.response ?? "");
|
|
299
|
+
}
|
|
300
|
+
else {
|
|
301
|
+
yield new GenerationChunk({
|
|
302
|
+
text: "",
|
|
303
|
+
generationInfo: {
|
|
304
|
+
model: chunk.model,
|
|
305
|
+
total_duration: chunk.total_duration,
|
|
306
|
+
load_duration: chunk.load_duration,
|
|
307
|
+
prompt_eval_count: chunk.prompt_eval_count,
|
|
308
|
+
prompt_eval_duration: chunk.prompt_eval_duration,
|
|
309
|
+
eval_count: chunk.eval_count,
|
|
310
|
+
eval_duration: chunk.eval_duration,
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
}
|
|
298
314
|
}
|
|
299
315
|
}
|
|
300
316
|
/** @ignore */
|
|
@@ -35,11 +35,7 @@ class OpenAIChat extends base_js_1.LLM {
|
|
|
35
35
|
return "OpenAIChat";
|
|
36
36
|
}
|
|
37
37
|
get callKeys() {
|
|
38
|
-
return [
|
|
39
|
-
...super.callKeys,
|
|
40
|
-
"options",
|
|
41
|
-
"promptIndex",
|
|
42
|
-
];
|
|
38
|
+
return [...super.callKeys, "options", "promptIndex"];
|
|
43
39
|
}
|
|
44
40
|
get lc_secrets() {
|
|
45
41
|
return {
|
|
@@ -36,7 +36,7 @@ export interface OpenAIChatCallOptions extends OpenAICallOptions {
|
|
|
36
36
|
*/
|
|
37
37
|
export declare class OpenAIChat extends LLM<OpenAIChatCallOptions> implements OpenAIChatInput, AzureOpenAIInput {
|
|
38
38
|
static lc_name(): string;
|
|
39
|
-
get callKeys():
|
|
39
|
+
get callKeys(): string[];
|
|
40
40
|
lc_serializable: boolean;
|
|
41
41
|
get lc_secrets(): {
|
|
42
42
|
[key: string]: string;
|
package/dist/llms/openai-chat.js
CHANGED
|
@@ -32,11 +32,7 @@ export class OpenAIChat extends LLM {
|
|
|
32
32
|
return "OpenAIChat";
|
|
33
33
|
}
|
|
34
34
|
get callKeys() {
|
|
35
|
-
return [
|
|
36
|
-
...super.callKeys,
|
|
37
|
-
"options",
|
|
38
|
-
"promptIndex",
|
|
39
|
-
];
|
|
35
|
+
return [...super.callKeys, "options", "promptIndex"];
|
|
40
36
|
}
|
|
41
37
|
get lc_secrets() {
|
|
42
38
|
return {
|
package/dist/llms/openai.cjs
CHANGED
|
@@ -59,7 +59,7 @@ class OpenAI extends base_js_1.BaseLLM {
|
|
|
59
59
|
if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
|
|
60
60
|
fields?.modelName?.startsWith("gpt-4")) &&
|
|
61
61
|
!fields?.modelName?.includes("-instruct")) {
|
|
62
|
-
// eslint-disable-next-line no-constructor-return
|
|
62
|
+
// eslint-disable-next-line no-constructor-return
|
|
63
63
|
return new openai_chat_js_1.OpenAIChat(fields, configuration);
|
|
64
64
|
}
|
|
65
65
|
super(fields ?? {});
|
package/dist/llms/openai.d.ts
CHANGED
|
@@ -22,9 +22,9 @@ export { AzureOpenAIInput, OpenAICallOptions, OpenAIInput };
|
|
|
22
22
|
* `openai.createCompletion`} can be passed through {@link modelKwargs}, even
|
|
23
23
|
* if not explicitly available on this class.
|
|
24
24
|
*/
|
|
25
|
-
export declare class OpenAI extends BaseLLM<
|
|
25
|
+
export declare class OpenAI<CallOptions extends OpenAICallOptions = OpenAICallOptions> extends BaseLLM<CallOptions> implements OpenAIInput, AzureOpenAIInput {
|
|
26
26
|
static lc_name(): string;
|
|
27
|
-
get callKeys():
|
|
27
|
+
get callKeys(): string[];
|
|
28
28
|
lc_serializable: boolean;
|
|
29
29
|
get lc_secrets(): {
|
|
30
30
|
[key: string]: string;
|
package/dist/llms/openai.js
CHANGED
|
@@ -56,7 +56,7 @@ export class OpenAI extends BaseLLM {
|
|
|
56
56
|
if ((fields?.modelName?.startsWith("gpt-3.5-turbo") ||
|
|
57
57
|
fields?.modelName?.startsWith("gpt-4")) &&
|
|
58
58
|
!fields?.modelName?.includes("-instruct")) {
|
|
59
|
-
// eslint-disable-next-line no-constructor-return
|
|
59
|
+
// eslint-disable-next-line no-constructor-return
|
|
60
60
|
return new OpenAIChat(fields, configuration);
|
|
61
61
|
}
|
|
62
62
|
super(fields ?? {});
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -24,8 +24,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
return result;
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.
|
|
28
|
-
exports.evaluation = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = void 0;
|
|
27
|
+
exports.retrievers__databerry = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__fireworks = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__fireworks = exports.llms__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
+
exports.evaluation = exports.experimental__chat_models__bittensor = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = exports.retrievers__document_compressors = exports.retrievers__contextual_compression = void 0;
|
|
29
29
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
30
30
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
31
31
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
@@ -44,6 +44,7 @@ exports.llms__openai = __importStar(require("../llms/openai.cjs"));
|
|
|
44
44
|
exports.llms__ai21 = __importStar(require("../llms/ai21.cjs"));
|
|
45
45
|
exports.llms__aleph_alpha = __importStar(require("../llms/aleph_alpha.cjs"));
|
|
46
46
|
exports.llms__ollama = __importStar(require("../llms/ollama.cjs"));
|
|
47
|
+
exports.llms__fireworks = __importStar(require("../llms/fireworks.cjs"));
|
|
47
48
|
exports.prompts = __importStar(require("../prompts/index.cjs"));
|
|
48
49
|
exports.vectorstores__base = __importStar(require("../vectorstores/base.cjs"));
|
|
49
50
|
exports.vectorstores__memory = __importStar(require("../vectorstores/memory.cjs"));
|
|
@@ -60,6 +61,7 @@ exports.document_transformers__openai_functions = __importStar(require("../docum
|
|
|
60
61
|
exports.chat_models__base = __importStar(require("../chat_models/base.cjs"));
|
|
61
62
|
exports.chat_models__openai = __importStar(require("../chat_models/openai.cjs"));
|
|
62
63
|
exports.chat_models__anthropic = __importStar(require("../chat_models/anthropic.cjs"));
|
|
64
|
+
exports.chat_models__fireworks = __importStar(require("../chat_models/fireworks.cjs"));
|
|
63
65
|
exports.chat_models__baiduwenxin = __importStar(require("../chat_models/baiduwenxin.cjs"));
|
|
64
66
|
exports.chat_models__ollama = __importStar(require("../chat_models/ollama.cjs"));
|
|
65
67
|
exports.chat_models__minimax = __importStar(require("../chat_models/minimax.cjs"));
|
|
@@ -16,6 +16,7 @@ export * as llms__openai from "../llms/openai.js";
|
|
|
16
16
|
export * as llms__ai21 from "../llms/ai21.js";
|
|
17
17
|
export * as llms__aleph_alpha from "../llms/aleph_alpha.js";
|
|
18
18
|
export * as llms__ollama from "../llms/ollama.js";
|
|
19
|
+
export * as llms__fireworks from "../llms/fireworks.js";
|
|
19
20
|
export * as prompts from "../prompts/index.js";
|
|
20
21
|
export * as vectorstores__base from "../vectorstores/base.js";
|
|
21
22
|
export * as vectorstores__memory from "../vectorstores/memory.js";
|
|
@@ -32,6 +33,7 @@ export * as document_transformers__openai_functions from "../document_transforme
|
|
|
32
33
|
export * as chat_models__base from "../chat_models/base.js";
|
|
33
34
|
export * as chat_models__openai from "../chat_models/openai.js";
|
|
34
35
|
export * as chat_models__anthropic from "../chat_models/anthropic.js";
|
|
36
|
+
export * as chat_models__fireworks from "../chat_models/fireworks.js";
|
|
35
37
|
export * as chat_models__baiduwenxin from "../chat_models/baiduwenxin.js";
|
|
36
38
|
export * as chat_models__ollama from "../chat_models/ollama.js";
|
|
37
39
|
export * as chat_models__minimax from "../chat_models/minimax.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -17,6 +17,7 @@ export * as llms__openai from "../llms/openai.js";
|
|
|
17
17
|
export * as llms__ai21 from "../llms/ai21.js";
|
|
18
18
|
export * as llms__aleph_alpha from "../llms/aleph_alpha.js";
|
|
19
19
|
export * as llms__ollama from "../llms/ollama.js";
|
|
20
|
+
export * as llms__fireworks from "../llms/fireworks.js";
|
|
20
21
|
export * as prompts from "../prompts/index.js";
|
|
21
22
|
export * as vectorstores__base from "../vectorstores/base.js";
|
|
22
23
|
export * as vectorstores__memory from "../vectorstores/memory.js";
|
|
@@ -33,6 +34,7 @@ export * as document_transformers__openai_functions from "../document_transforme
|
|
|
33
34
|
export * as chat_models__base from "../chat_models/base.js";
|
|
34
35
|
export * as chat_models__openai from "../chat_models/openai.js";
|
|
35
36
|
export * as chat_models__anthropic from "../chat_models/anthropic.js";
|
|
37
|
+
export * as chat_models__fireworks from "../chat_models/fireworks.js";
|
|
36
38
|
export * as chat_models__baiduwenxin from "../chat_models/baiduwenxin.js";
|
|
37
39
|
export * as chat_models__ollama from "../chat_models/ollama.js";
|
|
38
40
|
export * as chat_models__minimax from "../chat_models/minimax.js";
|
|
@@ -162,20 +162,52 @@ class BytesOutputParser extends BaseTransformOutputParser {
|
|
|
162
162
|
}
|
|
163
163
|
exports.BytesOutputParser = BytesOutputParser;
|
|
164
164
|
/**
|
|
165
|
-
*
|
|
166
|
-
*
|
|
167
|
-
*
|
|
165
|
+
* Exception that output parsers should raise to signify a parsing error.
|
|
166
|
+
*
|
|
167
|
+
* This exists to differentiate parsing errors from other code or execution errors
|
|
168
|
+
* that also may arise inside the output parser. OutputParserExceptions will be
|
|
169
|
+
* available to catch and handle in ways to fix the parsing error, while other
|
|
170
|
+
* errors will be raised.
|
|
171
|
+
*
|
|
172
|
+
* @param message - The error that's being re-raised or an error message.
|
|
173
|
+
* @param llmOutput - String model output which is error-ing.
|
|
174
|
+
* @param observation - String explanation of error which can be passed to a
|
|
175
|
+
* model to try and remediate the issue.
|
|
176
|
+
* @param sendToLLM - Whether to send the observation and llm_output back to an Agent
|
|
177
|
+
* after an OutputParserException has been raised. This gives the underlying
|
|
178
|
+
* model driving the agent the context that the previous output was improperly
|
|
179
|
+
* structured, in the hopes that it will update the output to the correct
|
|
180
|
+
* format.
|
|
168
181
|
*/
|
|
169
182
|
class OutputParserException extends Error {
|
|
170
|
-
constructor(message,
|
|
183
|
+
constructor(message, llmOutput, observation, sendToLLM = false) {
|
|
171
184
|
super(message);
|
|
172
|
-
Object.defineProperty(this, "
|
|
185
|
+
Object.defineProperty(this, "llmOutput", {
|
|
173
186
|
enumerable: true,
|
|
174
187
|
configurable: true,
|
|
175
188
|
writable: true,
|
|
176
189
|
value: void 0
|
|
177
190
|
});
|
|
178
|
-
this
|
|
191
|
+
Object.defineProperty(this, "observation", {
|
|
192
|
+
enumerable: true,
|
|
193
|
+
configurable: true,
|
|
194
|
+
writable: true,
|
|
195
|
+
value: void 0
|
|
196
|
+
});
|
|
197
|
+
Object.defineProperty(this, "sendToLLM", {
|
|
198
|
+
enumerable: true,
|
|
199
|
+
configurable: true,
|
|
200
|
+
writable: true,
|
|
201
|
+
value: void 0
|
|
202
|
+
});
|
|
203
|
+
this.llmOutput = llmOutput;
|
|
204
|
+
this.observation = observation;
|
|
205
|
+
this.sendToLLM = sendToLLM;
|
|
206
|
+
if (sendToLLM) {
|
|
207
|
+
if (observation === undefined || llmOutput === undefined) {
|
|
208
|
+
throw new Error("Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
179
211
|
}
|
|
180
212
|
}
|
|
181
213
|
exports.OutputParserException = OutputParserException;
|
|
@@ -118,11 +118,26 @@ export declare class BytesOutputParser extends BaseTransformOutputParser<Uint8Ar
|
|
|
118
118
|
getFormatInstructions(): string;
|
|
119
119
|
}
|
|
120
120
|
/**
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
*
|
|
121
|
+
* Exception that output parsers should raise to signify a parsing error.
|
|
122
|
+
*
|
|
123
|
+
* This exists to differentiate parsing errors from other code or execution errors
|
|
124
|
+
* that also may arise inside the output parser. OutputParserExceptions will be
|
|
125
|
+
* available to catch and handle in ways to fix the parsing error, while other
|
|
126
|
+
* errors will be raised.
|
|
127
|
+
*
|
|
128
|
+
* @param message - The error that's being re-raised or an error message.
|
|
129
|
+
* @param llmOutput - String model output which is error-ing.
|
|
130
|
+
* @param observation - String explanation of error which can be passed to a
|
|
131
|
+
* model to try and remediate the issue.
|
|
132
|
+
* @param sendToLLM - Whether to send the observation and llm_output back to an Agent
|
|
133
|
+
* after an OutputParserException has been raised. This gives the underlying
|
|
134
|
+
* model driving the agent the context that the previous output was improperly
|
|
135
|
+
* structured, in the hopes that it will update the output to the correct
|
|
136
|
+
* format.
|
|
124
137
|
*/
|
|
125
138
|
export declare class OutputParserException extends Error {
|
|
126
|
-
|
|
127
|
-
|
|
139
|
+
llmOutput?: string;
|
|
140
|
+
observation?: string;
|
|
141
|
+
sendToLLM: boolean;
|
|
142
|
+
constructor(message: string, llmOutput?: string, observation?: string, sendToLLM?: boolean);
|
|
128
143
|
}
|
|
@@ -154,19 +154,51 @@ export class BytesOutputParser extends BaseTransformOutputParser {
|
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
156
|
/**
|
|
157
|
-
*
|
|
158
|
-
*
|
|
159
|
-
*
|
|
157
|
+
* Exception that output parsers should raise to signify a parsing error.
|
|
158
|
+
*
|
|
159
|
+
* This exists to differentiate parsing errors from other code or execution errors
|
|
160
|
+
* that also may arise inside the output parser. OutputParserExceptions will be
|
|
161
|
+
* available to catch and handle in ways to fix the parsing error, while other
|
|
162
|
+
* errors will be raised.
|
|
163
|
+
*
|
|
164
|
+
* @param message - The error that's being re-raised or an error message.
|
|
165
|
+
* @param llmOutput - String model output which is error-ing.
|
|
166
|
+
* @param observation - String explanation of error which can be passed to a
|
|
167
|
+
* model to try and remediate the issue.
|
|
168
|
+
* @param sendToLLM - Whether to send the observation and llm_output back to an Agent
|
|
169
|
+
* after an OutputParserException has been raised. This gives the underlying
|
|
170
|
+
* model driving the agent the context that the previous output was improperly
|
|
171
|
+
* structured, in the hopes that it will update the output to the correct
|
|
172
|
+
* format.
|
|
160
173
|
*/
|
|
161
174
|
export class OutputParserException extends Error {
|
|
162
|
-
constructor(message,
|
|
175
|
+
constructor(message, llmOutput, observation, sendToLLM = false) {
|
|
163
176
|
super(message);
|
|
164
|
-
Object.defineProperty(this, "
|
|
177
|
+
Object.defineProperty(this, "llmOutput", {
|
|
165
178
|
enumerable: true,
|
|
166
179
|
configurable: true,
|
|
167
180
|
writable: true,
|
|
168
181
|
value: void 0
|
|
169
182
|
});
|
|
170
|
-
this
|
|
183
|
+
Object.defineProperty(this, "observation", {
|
|
184
|
+
enumerable: true,
|
|
185
|
+
configurable: true,
|
|
186
|
+
writable: true,
|
|
187
|
+
value: void 0
|
|
188
|
+
});
|
|
189
|
+
Object.defineProperty(this, "sendToLLM", {
|
|
190
|
+
enumerable: true,
|
|
191
|
+
configurable: true,
|
|
192
|
+
writable: true,
|
|
193
|
+
value: void 0
|
|
194
|
+
});
|
|
195
|
+
this.llmOutput = llmOutput;
|
|
196
|
+
this.observation = observation;
|
|
197
|
+
this.sendToLLM = sendToLLM;
|
|
198
|
+
if (sendToLLM) {
|
|
199
|
+
if (observation === undefined || llmOutput === undefined) {
|
|
200
|
+
throw new Error("Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true");
|
|
201
|
+
}
|
|
202
|
+
}
|
|
171
203
|
}
|
|
172
204
|
}
|
|
@@ -37,7 +37,7 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
37
37
|
*/
|
|
38
38
|
bind(kwargs) {
|
|
39
39
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
40
|
-
return new RunnableBinding({ bound: this, kwargs });
|
|
40
|
+
return new RunnableBinding({ bound: this, kwargs, config: {} });
|
|
41
41
|
}
|
|
42
42
|
/**
|
|
43
43
|
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
@@ -48,19 +48,33 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
48
48
|
return new RunnableEach({ bound: this });
|
|
49
49
|
}
|
|
50
50
|
/**
|
|
51
|
-
*
|
|
51
|
+
* Add retry logic to an existing runnable.
|
|
52
52
|
* @param kwargs
|
|
53
|
-
* @returns A new
|
|
53
|
+
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
54
54
|
*/
|
|
55
55
|
withRetry(fields) {
|
|
56
56
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
57
57
|
return new RunnableRetry({
|
|
58
58
|
bound: this,
|
|
59
59
|
kwargs: {},
|
|
60
|
+
config: {},
|
|
60
61
|
maxAttemptNumber: fields?.stopAfterAttempt,
|
|
61
62
|
...fields,
|
|
62
63
|
});
|
|
63
64
|
}
|
|
65
|
+
/**
|
|
66
|
+
* Bind config to a Runnable, returning a new Runnable.
|
|
67
|
+
* @param config New configuration parameters to attach to the new runnable.
|
|
68
|
+
* @returns A new RunnableBinding with a config matching what's passed.
|
|
69
|
+
*/
|
|
70
|
+
withConfig(config) {
|
|
71
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
72
|
+
return new RunnableBinding({
|
|
73
|
+
bound: this,
|
|
74
|
+
config,
|
|
75
|
+
kwargs: {},
|
|
76
|
+
});
|
|
77
|
+
}
|
|
64
78
|
/**
|
|
65
79
|
* Create a new runnable from the current one that will try invoking
|
|
66
80
|
* other passed fallback runnables if the initial invocation fails.
|
|
@@ -312,6 +326,12 @@ class RunnableBinding extends Runnable {
|
|
|
312
326
|
writable: true,
|
|
313
327
|
value: void 0
|
|
314
328
|
});
|
|
329
|
+
Object.defineProperty(this, "config", {
|
|
330
|
+
enumerable: true,
|
|
331
|
+
configurable: true,
|
|
332
|
+
writable: true,
|
|
333
|
+
value: void 0
|
|
334
|
+
});
|
|
315
335
|
Object.defineProperty(this, "kwargs", {
|
|
316
336
|
enumerable: true,
|
|
317
337
|
configurable: true,
|
|
@@ -320,35 +340,70 @@ class RunnableBinding extends Runnable {
|
|
|
320
340
|
});
|
|
321
341
|
this.bound = fields.bound;
|
|
322
342
|
this.kwargs = fields.kwargs;
|
|
343
|
+
this.config = fields.config;
|
|
344
|
+
}
|
|
345
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
346
|
+
_mergeConfig(options) {
|
|
347
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
348
|
+
const copy = { ...this.config };
|
|
349
|
+
if (options) {
|
|
350
|
+
for (const key of Object.keys(options)) {
|
|
351
|
+
if (key === "metadata") {
|
|
352
|
+
copy[key] = { ...copy[key], ...options[key] };
|
|
353
|
+
}
|
|
354
|
+
else if (key === "tags") {
|
|
355
|
+
copy[key] = (copy[key] ?? []).concat(options[key] ?? []);
|
|
356
|
+
}
|
|
357
|
+
else {
|
|
358
|
+
copy[key] = options[key] ?? copy[key];
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
return copy;
|
|
323
363
|
}
|
|
324
364
|
bind(kwargs) {
|
|
325
|
-
return
|
|
365
|
+
return this.constructor({
|
|
326
366
|
bound: this.bound,
|
|
327
367
|
kwargs: { ...this.kwargs, ...kwargs },
|
|
368
|
+
config: this.config,
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
withConfig(config) {
|
|
372
|
+
return this.constructor({
|
|
373
|
+
bound: this.bound,
|
|
374
|
+
kwargs: this.kwargs,
|
|
375
|
+
config: { ...this.config, ...config },
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
withRetry(fields) {
|
|
379
|
+
return this.constructor({
|
|
380
|
+
bound: this.bound.withRetry(fields),
|
|
381
|
+
kwargs: this.kwargs,
|
|
382
|
+
config: this.config,
|
|
328
383
|
});
|
|
329
384
|
}
|
|
330
385
|
async invoke(input, options) {
|
|
331
|
-
return this.bound.invoke(input, { ...options, ...this.kwargs });
|
|
386
|
+
return this.bound.invoke(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
332
387
|
}
|
|
333
388
|
async batch(inputs, options, batchOptions) {
|
|
334
389
|
const mergedOptions = Array.isArray(options)
|
|
335
|
-
? options.map((individualOption) => ({
|
|
390
|
+
? options.map((individualOption) => this._mergeConfig({
|
|
336
391
|
...individualOption,
|
|
337
392
|
...this.kwargs,
|
|
338
393
|
}))
|
|
339
|
-
: { ...options, ...this.kwargs };
|
|
394
|
+
: this._mergeConfig({ ...options, ...this.kwargs });
|
|
340
395
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
341
396
|
}
|
|
342
397
|
async *_streamIterator(input, options) {
|
|
343
|
-
yield* this.bound._streamIterator(input, { ...options, ...this.kwargs });
|
|
398
|
+
yield* this.bound._streamIterator(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
344
399
|
}
|
|
345
400
|
async stream(input, options) {
|
|
346
|
-
return this.bound.stream(input, { ...options, ...this.kwargs });
|
|
401
|
+
return this.bound.stream(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
347
402
|
}
|
|
348
403
|
async *transform(
|
|
349
404
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
350
405
|
generator, options) {
|
|
351
|
-
yield* this.bound.transform(generator, options);
|
|
406
|
+
yield* this.bound.transform(generator, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
352
407
|
}
|
|
353
408
|
static isRunnableBinding(
|
|
354
409
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -33,14 +33,20 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
33
33
|
*/
|
|
34
34
|
map(): Runnable<RunInput[], RunOutput[], CallOptions>;
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Add retry logic to an existing runnable.
|
|
37
37
|
* @param kwargs
|
|
38
|
-
* @returns A new
|
|
38
|
+
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
39
39
|
*/
|
|
40
40
|
withRetry(fields?: {
|
|
41
41
|
stopAfterAttempt?: number;
|
|
42
42
|
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
43
43
|
}): RunnableRetry<RunInput, RunOutput, CallOptions>;
|
|
44
|
+
/**
|
|
45
|
+
* Bind config to a Runnable, returning a new Runnable.
|
|
46
|
+
* @param config New configuration parameters to attach to the new runnable.
|
|
47
|
+
* @returns A new RunnableBinding with a config matching what's passed.
|
|
48
|
+
*/
|
|
49
|
+
withConfig(config: RunnableConfig): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
44
50
|
/**
|
|
45
51
|
* Create a new runnable from the current one that will try invoking
|
|
46
52
|
* other passed fallback runnables if the initial invocation fails.
|
|
@@ -122,18 +128,26 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
122
128
|
export type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig> = {
|
|
123
129
|
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
124
130
|
kwargs: Partial<CallOptions>;
|
|
131
|
+
config: RunnableConfig;
|
|
125
132
|
};
|
|
126
133
|
/**
|
|
127
134
|
* A runnable that delegates calls to another runnable with a set of kwargs.
|
|
128
135
|
*/
|
|
129
|
-
export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends
|
|
136
|
+
export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
130
137
|
static lc_name(): string;
|
|
131
138
|
lc_namespace: string[];
|
|
132
139
|
lc_serializable: boolean;
|
|
133
140
|
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
141
|
+
config: RunnableConfig;
|
|
134
142
|
protected kwargs: Partial<CallOptions>;
|
|
135
143
|
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
|
|
144
|
+
_mergeConfig(options?: Record<string, any>): Partial<CallOptions>;
|
|
136
145
|
bind(kwargs: Partial<CallOptions>): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
146
|
+
withConfig(config: RunnableConfig): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
147
|
+
withRetry(fields?: {
|
|
148
|
+
stopAfterAttempt?: number;
|
|
149
|
+
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
150
|
+
}): RunnableRetry<RunInput, RunOutput, CallOptions>;
|
|
137
151
|
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
138
152
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
139
153
|
returnExceptions?: false;
|
|
@@ -31,7 +31,7 @@ export class Runnable extends Serializable {
|
|
|
31
31
|
*/
|
|
32
32
|
bind(kwargs) {
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
34
|
-
return new RunnableBinding({ bound: this, kwargs });
|
|
34
|
+
return new RunnableBinding({ bound: this, kwargs, config: {} });
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
@@ -42,19 +42,33 @@ export class Runnable extends Serializable {
|
|
|
42
42
|
return new RunnableEach({ bound: this });
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
|
-
*
|
|
45
|
+
* Add retry logic to an existing runnable.
|
|
46
46
|
* @param kwargs
|
|
47
|
-
* @returns A new
|
|
47
|
+
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
48
48
|
*/
|
|
49
49
|
withRetry(fields) {
|
|
50
50
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
51
51
|
return new RunnableRetry({
|
|
52
52
|
bound: this,
|
|
53
53
|
kwargs: {},
|
|
54
|
+
config: {},
|
|
54
55
|
maxAttemptNumber: fields?.stopAfterAttempt,
|
|
55
56
|
...fields,
|
|
56
57
|
});
|
|
57
58
|
}
|
|
59
|
+
/**
|
|
60
|
+
* Bind config to a Runnable, returning a new Runnable.
|
|
61
|
+
* @param config New configuration parameters to attach to the new runnable.
|
|
62
|
+
* @returns A new RunnableBinding with a config matching what's passed.
|
|
63
|
+
*/
|
|
64
|
+
withConfig(config) {
|
|
65
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
66
|
+
return new RunnableBinding({
|
|
67
|
+
bound: this,
|
|
68
|
+
config,
|
|
69
|
+
kwargs: {},
|
|
70
|
+
});
|
|
71
|
+
}
|
|
58
72
|
/**
|
|
59
73
|
* Create a new runnable from the current one that will try invoking
|
|
60
74
|
* other passed fallback runnables if the initial invocation fails.
|
|
@@ -305,6 +319,12 @@ export class RunnableBinding extends Runnable {
|
|
|
305
319
|
writable: true,
|
|
306
320
|
value: void 0
|
|
307
321
|
});
|
|
322
|
+
Object.defineProperty(this, "config", {
|
|
323
|
+
enumerable: true,
|
|
324
|
+
configurable: true,
|
|
325
|
+
writable: true,
|
|
326
|
+
value: void 0
|
|
327
|
+
});
|
|
308
328
|
Object.defineProperty(this, "kwargs", {
|
|
309
329
|
enumerable: true,
|
|
310
330
|
configurable: true,
|
|
@@ -313,35 +333,70 @@ export class RunnableBinding extends Runnable {
|
|
|
313
333
|
});
|
|
314
334
|
this.bound = fields.bound;
|
|
315
335
|
this.kwargs = fields.kwargs;
|
|
336
|
+
this.config = fields.config;
|
|
337
|
+
}
|
|
338
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
339
|
+
_mergeConfig(options) {
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
|
+
const copy = { ...this.config };
|
|
342
|
+
if (options) {
|
|
343
|
+
for (const key of Object.keys(options)) {
|
|
344
|
+
if (key === "metadata") {
|
|
345
|
+
copy[key] = { ...copy[key], ...options[key] };
|
|
346
|
+
}
|
|
347
|
+
else if (key === "tags") {
|
|
348
|
+
copy[key] = (copy[key] ?? []).concat(options[key] ?? []);
|
|
349
|
+
}
|
|
350
|
+
else {
|
|
351
|
+
copy[key] = options[key] ?? copy[key];
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
return copy;
|
|
316
356
|
}
|
|
317
357
|
bind(kwargs) {
|
|
318
|
-
return
|
|
358
|
+
return this.constructor({
|
|
319
359
|
bound: this.bound,
|
|
320
360
|
kwargs: { ...this.kwargs, ...kwargs },
|
|
361
|
+
config: this.config,
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
withConfig(config) {
|
|
365
|
+
return this.constructor({
|
|
366
|
+
bound: this.bound,
|
|
367
|
+
kwargs: this.kwargs,
|
|
368
|
+
config: { ...this.config, ...config },
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
withRetry(fields) {
|
|
372
|
+
return this.constructor({
|
|
373
|
+
bound: this.bound.withRetry(fields),
|
|
374
|
+
kwargs: this.kwargs,
|
|
375
|
+
config: this.config,
|
|
321
376
|
});
|
|
322
377
|
}
|
|
323
378
|
async invoke(input, options) {
|
|
324
|
-
return this.bound.invoke(input, { ...options, ...this.kwargs });
|
|
379
|
+
return this.bound.invoke(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
325
380
|
}
|
|
326
381
|
async batch(inputs, options, batchOptions) {
|
|
327
382
|
const mergedOptions = Array.isArray(options)
|
|
328
|
-
? options.map((individualOption) => ({
|
|
383
|
+
? options.map((individualOption) => this._mergeConfig({
|
|
329
384
|
...individualOption,
|
|
330
385
|
...this.kwargs,
|
|
331
386
|
}))
|
|
332
|
-
: { ...options, ...this.kwargs };
|
|
387
|
+
: this._mergeConfig({ ...options, ...this.kwargs });
|
|
333
388
|
return this.bound.batch(inputs, mergedOptions, batchOptions);
|
|
334
389
|
}
|
|
335
390
|
async *_streamIterator(input, options) {
|
|
336
|
-
yield* this.bound._streamIterator(input, { ...options, ...this.kwargs });
|
|
391
|
+
yield* this.bound._streamIterator(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
337
392
|
}
|
|
338
393
|
async stream(input, options) {
|
|
339
|
-
return this.bound.stream(input, { ...options, ...this.kwargs });
|
|
394
|
+
return this.bound.stream(input, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
340
395
|
}
|
|
341
396
|
async *transform(
|
|
342
397
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
343
398
|
generator, options) {
|
|
344
|
-
yield* this.bound.transform(generator, options);
|
|
399
|
+
yield* this.bound.transform(generator, this._mergeConfig({ ...options, ...this.kwargs }));
|
|
345
400
|
}
|
|
346
401
|
static isRunnableBinding(
|
|
347
402
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|