langchain 0.0.195 → 0.0.196
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/dist/agents/toolkits/conversational_retrieval/token_buffer_memory.d.ts +1 -1
- package/dist/base_language/count_tokens.cjs +5 -70
- package/dist/base_language/count_tokens.d.ts +1 -10
- package/dist/base_language/count_tokens.js +1 -65
- package/dist/base_language/index.cjs +6 -196
- package/dist/base_language/index.d.ts +1 -111
- package/dist/base_language/index.js +1 -191
- package/dist/cache/base.cjs +15 -37
- package/dist/cache/base.d.ts +1 -20
- package/dist/cache/base.js +1 -33
- package/dist/cache/index.cjs +2 -46
- package/dist/cache/index.d.ts +1 -29
- package/dist/cache/index.js +1 -45
- package/dist/callbacks/base.cjs +3 -139
- package/dist/callbacks/base.d.ts +1 -266
- package/dist/callbacks/base.js +1 -126
- package/dist/callbacks/handlers/console.cjs +14 -221
- package/dist/callbacks/handlers/console.d.ts +1 -117
- package/dist/callbacks/handlers/console.js +1 -217
- package/dist/callbacks/handlers/initialize.cjs +15 -30
- package/dist/callbacks/handlers/initialize.d.ts +1 -16
- package/dist/callbacks/handlers/initialize.js +1 -27
- package/dist/callbacks/handlers/log_stream.cjs +15 -293
- package/dist/callbacks/handlers/log_stream.d.ts +1 -100
- package/dist/callbacks/handlers/log_stream.js +1 -289
- package/dist/callbacks/handlers/run_collector.cjs +15 -48
- package/dist/callbacks/handlers/run_collector.d.ts +1 -26
- package/dist/callbacks/handlers/run_collector.js +1 -46
- package/dist/callbacks/handlers/tracer.cjs +15 -375
- package/dist/callbacks/handlers/tracer.d.ts +1 -70
- package/dist/callbacks/handlers/tracer.js +1 -373
- package/dist/callbacks/handlers/tracer_langchain.cjs +15 -104
- package/dist/callbacks/handlers/tracer_langchain.d.ts +1 -41
- package/dist/callbacks/handlers/tracer_langchain.js +1 -102
- package/dist/callbacks/handlers/tracer_langchain_v1.cjs +15 -197
- package/dist/callbacks/handlers/tracer_langchain_v1.d.ts +1 -57
- package/dist/callbacks/handlers/tracer_langchain_v1.js +1 -195
- package/dist/callbacks/manager.cjs +15 -676
- package/dist/callbacks/manager.d.ts +1 -180
- package/dist/callbacks/manager.js +1 -666
- package/dist/callbacks/promises.cjs +14 -42
- package/dist/callbacks/promises.d.ts +1 -11
- package/dist/callbacks/promises.js +1 -37
- package/dist/chains/graph_qa/prompts.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.cjs +2 -2
- package/dist/chains/openai_functions/structured_output.d.ts +1 -1
- package/dist/chains/openai_functions/structured_output.js +1 -1
- package/dist/chat_models/baiduwenxin.d.ts +1 -1
- package/dist/chat_models/base.cjs +15 -296
- package/dist/chat_models/base.d.ts +1 -122
- package/dist/chat_models/base.js +1 -292
- package/dist/chat_models/bedrock/web.d.ts +1 -1
- package/dist/chat_models/fireworks.d.ts +1 -1
- package/dist/document.cjs +2 -24
- package/dist/document.d.ts +1 -12
- package/dist/document.js +1 -23
- package/dist/document_loaders/web/azure_blob_storage_file.d.ts +1 -1
- package/dist/document_loaders/web/s3.d.ts +1 -1
- package/dist/embeddings/base.cjs +15 -22
- package/dist/embeddings/base.d.ts +1 -33
- package/dist/embeddings/base.js +1 -20
- package/dist/embeddings/cache_backed.cjs +2 -2
- package/dist/embeddings/cache_backed.js +1 -1
- package/dist/evaluation/agents/trajectory.d.ts +1 -1
- package/dist/evaluation/criteria/prompt.d.ts +2 -2
- package/dist/evaluation/qa/prompt.d.ts +2 -2
- package/dist/experimental/hubs/makersuite/googlemakersuitehub.d.ts +1 -1
- package/dist/experimental/plan_and_execute/prompt.d.ts +1 -1
- package/dist/llms/base.cjs +15 -278
- package/dist/llms/base.d.ts +1 -115
- package/dist/llms/base.js +1 -275
- package/dist/llms/bedrock/web.d.ts +1 -1
- package/dist/llms/fireworks.d.ts +1 -1
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/load/index.cjs +7 -148
- package/dist/load/index.js +7 -148
- package/dist/load/map_keys.cjs +0 -24
- package/dist/load/map_keys.d.ts +0 -6
- package/dist/load/map_keys.js +1 -17
- package/dist/load/serializable.cjs +15 -178
- package/dist/load/serializable.d.ts +1 -66
- package/dist/load/serializable.js +1 -175
- package/dist/memory/base.cjs +17 -92
- package/dist/memory/base.d.ts +2 -68
- package/dist/memory/base.js +2 -87
- package/dist/output_parsers/openai_functions.cjs +2 -2
- package/dist/output_parsers/openai_functions.d.ts +1 -1
- package/dist/output_parsers/openai_functions.js +1 -1
- package/dist/output_parsers/regex.d.ts +1 -1
- package/dist/output_parsers/structured.d.ts +1 -1
- package/dist/prompts/base.cjs +8 -183
- package/dist/prompts/base.d.ts +3 -132
- package/dist/prompts/base.js +3 -178
- package/dist/prompts/chat.cjs +15 -477
- package/dist/prompts/chat.d.ts +1 -219
- package/dist/prompts/chat.js +1 -466
- package/dist/prompts/few_shot.cjs +15 -353
- package/dist/prompts/few_shot.d.ts +1 -192
- package/dist/prompts/few_shot.js +1 -350
- package/dist/prompts/index.cjs +3 -2
- package/dist/prompts/index.d.ts +2 -1
- package/dist/prompts/index.js +2 -1
- package/dist/prompts/pipeline.cjs +15 -142
- package/dist/prompts/pipeline.d.ts +1 -98
- package/dist/prompts/pipeline.js +1 -140
- package/dist/prompts/prompt.cjs +15 -146
- package/dist/prompts/prompt.d.ts +1 -92
- package/dist/prompts/prompt.js +1 -144
- package/dist/prompts/selectors/LengthBasedExampleSelector.cjs +15 -148
- package/dist/prompts/selectors/LengthBasedExampleSelector.d.ts +1 -89
- package/dist/prompts/selectors/LengthBasedExampleSelector.js +1 -146
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.cjs +15 -137
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.d.ts +1 -91
- package/dist/prompts/selectors/SemanticSimilarityExampleSelector.js +1 -135
- package/dist/prompts/selectors/conditional.cjs +15 -74
- package/dist/prompts/selectors/conditional.d.ts +1 -63
- package/dist/prompts/selectors/conditional.js +1 -69
- package/dist/prompts/serde.cjs +15 -0
- package/dist/prompts/serde.d.ts +1 -43
- package/dist/prompts/serde.js +1 -1
- package/dist/prompts/template.cjs +14 -88
- package/dist/prompts/template.d.ts +1 -36
- package/dist/prompts/template.js +1 -83
- package/dist/{util/@cfworker/json-schema → runnables}/index.cjs +1 -1
- package/dist/runnables/index.d.ts +1 -0
- package/dist/runnables/index.js +1 -0
- package/dist/schema/document.cjs +3 -34
- package/dist/schema/document.d.ts +2 -29
- package/dist/schema/document.js +2 -32
- package/dist/schema/index.cjs +37 -612
- package/dist/schema/index.d.ts +11 -311
- package/dist/schema/index.js +8 -583
- package/dist/schema/output_parser.cjs +15 -309
- package/dist/schema/output_parser.d.ts +1 -173
- package/dist/schema/output_parser.js +1 -301
- package/dist/schema/retriever.cjs +15 -77
- package/dist/schema/retriever.d.ts +1 -43
- package/dist/schema/retriever.js +1 -75
- package/dist/schema/runnable/base.cjs +10 -1072
- package/dist/schema/runnable/base.d.ts +1 -356
- package/dist/schema/runnable/base.js +1 -1060
- package/dist/schema/runnable/branch.cjs +2 -131
- package/dist/schema/runnable/branch.d.ts +1 -94
- package/dist/schema/runnable/branch.js +1 -130
- package/dist/schema/runnable/config.cjs +0 -6
- package/dist/schema/runnable/config.d.ts +1 -3
- package/dist/schema/runnable/config.js +1 -4
- package/dist/schema/runnable/index.cjs +15 -16
- package/dist/schema/runnable/index.d.ts +1 -5
- package/dist/schema/runnable/index.js +1 -4
- package/dist/schema/runnable/passthrough.cjs +3 -113
- package/dist/schema/runnable/passthrough.d.ts +1 -72
- package/dist/schema/runnable/passthrough.js +1 -111
- package/dist/schema/runnable/router.cjs +2 -71
- package/dist/schema/runnable/router.d.ts +1 -29
- package/dist/schema/runnable/router.js +1 -70
- package/dist/schema/storage.cjs +15 -8
- package/dist/schema/storage.d.ts +1 -57
- package/dist/schema/storage.js +1 -6
- package/dist/tools/bingserpapi.d.ts +1 -1
- package/dist/tools/searchapi.d.ts +1 -1
- package/dist/tools/serpapi.d.ts +1 -1
- package/dist/tools/serper.d.ts +1 -1
- package/dist/util/async_caller.cjs +14 -128
- package/dist/util/async_caller.d.ts +1 -45
- package/dist/util/async_caller.js +1 -124
- package/package.json +11 -5
- package/runnables.cjs +1 -0
- package/runnables.d.ts +1 -0
- package/runnables.js +1 -0
- package/dist/util/@cfworker/json-schema/index.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/index.js +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.cjs +0 -43
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.d.ts +0 -1
- package/dist/util/@cfworker/json-schema/src/deep-compare-strict.js +0 -39
- package/dist/util/@cfworker/json-schema/src/dereference.cjs +0 -169
- package/dist/util/@cfworker/json-schema/src/dereference.d.ts +0 -12
- package/dist/util/@cfworker/json-schema/src/dereference.js +0 -165
- package/dist/util/@cfworker/json-schema/src/format.cjs +0 -139
- package/dist/util/@cfworker/json-schema/src/format.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/format.js +0 -136
- package/dist/util/@cfworker/json-schema/src/index.cjs +0 -24
- package/dist/util/@cfworker/json-schema/src/index.d.ts +0 -8
- package/dist/util/@cfworker/json-schema/src/index.js +0 -8
- package/dist/util/@cfworker/json-schema/src/pointer.cjs +0 -11
- package/dist/util/@cfworker/json-schema/src/pointer.d.ts +0 -2
- package/dist/util/@cfworker/json-schema/src/pointer.js +0 -6
- package/dist/util/@cfworker/json-schema/src/types.cjs +0 -2
- package/dist/util/@cfworker/json-schema/src/types.d.ts +0 -72
- package/dist/util/@cfworker/json-schema/src/types.js +0 -1
- package/dist/util/@cfworker/json-schema/src/ucs2-length.cjs +0 -28
- package/dist/util/@cfworker/json-schema/src/ucs2-length.d.ts +0 -6
- package/dist/util/@cfworker/json-schema/src/ucs2-length.js +0 -24
- package/dist/util/@cfworker/json-schema/src/validate.cjs +0 -808
- package/dist/util/@cfworker/json-schema/src/validate.d.ts +0 -3
- package/dist/util/@cfworker/json-schema/src/validate.js +0 -804
- package/dist/util/@cfworker/json-schema/src/validator.cjs +0 -44
- package/dist/util/@cfworker/json-schema/src/validator.d.ts +0 -10
- package/dist/util/@cfworker/json-schema/src/validator.js +0 -40
- package/dist/util/fast-json-patch/index.cjs +0 -49
- package/dist/util/fast-json-patch/index.d.ts +0 -22
- package/dist/util/fast-json-patch/index.js +0 -16
- package/dist/util/fast-json-patch/src/core.cjs +0 -469
- package/dist/util/fast-json-patch/src/core.d.ts +0 -111
- package/dist/util/fast-json-patch/src/core.js +0 -459
- package/dist/util/fast-json-patch/src/duplex.cjs +0 -237
- package/dist/util/fast-json-patch/src/duplex.d.ts +0 -23
- package/dist/util/fast-json-patch/src/duplex.js +0 -230
- package/dist/util/fast-json-patch/src/helpers.cjs +0 -194
- package/dist/util/fast-json-patch/src/helpers.d.ts +0 -36
- package/dist/util/fast-json-patch/src/helpers.js +0 -181
- package/dist/util/js-sha1/hash.cjs +0 -358
- package/dist/util/js-sha1/hash.d.ts +0 -1
- package/dist/util/js-sha1/hash.js +0 -355
|
@@ -1,111 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
|
|
4
|
-
*/
|
|
5
|
-
export class RunnableAssign extends Runnable {
|
|
6
|
-
constructor(mapper) {
|
|
7
|
-
super();
|
|
8
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
value: ["langchain", "schema", "runnable"]
|
|
13
|
-
});
|
|
14
|
-
Object.defineProperty(this, "mapper", {
|
|
15
|
-
enumerable: true,
|
|
16
|
-
configurable: true,
|
|
17
|
-
writable: true,
|
|
18
|
-
value: void 0
|
|
19
|
-
});
|
|
20
|
-
this.mapper = mapper;
|
|
21
|
-
}
|
|
22
|
-
async invoke(input, options) {
|
|
23
|
-
const mapperResult = await this.mapper.invoke(input, options);
|
|
24
|
-
return {
|
|
25
|
-
...input,
|
|
26
|
-
...mapperResult,
|
|
27
|
-
};
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
32
|
-
*
|
|
33
|
-
* This runnable behaves almost like the identity function, except that it
|
|
34
|
-
* can be configured to add additional keys to the output, if the input is
|
|
35
|
-
* an object.
|
|
36
|
-
*
|
|
37
|
-
* The example below demonstrates how to use `RunnablePassthrough to
|
|
38
|
-
* passthrough the input from the `.invoke()`
|
|
39
|
-
*
|
|
40
|
-
* @example
|
|
41
|
-
* ```typescript
|
|
42
|
-
* const chain = RunnableSequence.from([
|
|
43
|
-
* {
|
|
44
|
-
* question: new RunnablePassthrough(),
|
|
45
|
-
* context: async () => loadContextFromStore(),
|
|
46
|
-
* },
|
|
47
|
-
* prompt,
|
|
48
|
-
* llm,
|
|
49
|
-
* outputParser,
|
|
50
|
-
* ]);
|
|
51
|
-
* const response = await chain.invoke(
|
|
52
|
-
* "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
|
|
53
|
-
* );
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export class RunnablePassthrough extends Runnable {
|
|
57
|
-
constructor() {
|
|
58
|
-
super(...arguments);
|
|
59
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
60
|
-
enumerable: true,
|
|
61
|
-
configurable: true,
|
|
62
|
-
writable: true,
|
|
63
|
-
value: ["langchain", "schema", "runnable"]
|
|
64
|
-
});
|
|
65
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
66
|
-
enumerable: true,
|
|
67
|
-
configurable: true,
|
|
68
|
-
writable: true,
|
|
69
|
-
value: true
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
static lc_name() {
|
|
73
|
-
return "RunnablePassthrough";
|
|
74
|
-
}
|
|
75
|
-
async invoke(input, options) {
|
|
76
|
-
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* A runnable that assigns key-value pairs to the input.
|
|
80
|
-
*
|
|
81
|
-
* The example below shows how you could use it with an inline function.
|
|
82
|
-
*
|
|
83
|
-
* @example
|
|
84
|
-
* ```typescript
|
|
85
|
-
* const prompt =
|
|
86
|
-
* PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
|
|
87
|
-
* Question: {question}
|
|
88
|
-
* SQL Query:`);
|
|
89
|
-
*
|
|
90
|
-
* // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
|
|
91
|
-
* // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
|
|
92
|
-
* // In this case, we're passing the schema.
|
|
93
|
-
* const sqlQueryGeneratorChain = RunnableSequence.from([
|
|
94
|
-
* RunnablePassthrough.assign({
|
|
95
|
-
* schema: async () => db.getTableInfo(),
|
|
96
|
-
* }),
|
|
97
|
-
* prompt,
|
|
98
|
-
* new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
|
|
99
|
-
* new StringOutputParser(),
|
|
100
|
-
* ]);
|
|
101
|
-
* const result = await sqlQueryGeneratorChain.invoke({
|
|
102
|
-
* question: "How many employees are there?",
|
|
103
|
-
* });
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
|
-
static assign(
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
108
|
-
mapping) {
|
|
109
|
-
return new RunnableAssign(new RunnableMap({ steps: mapping }));
|
|
110
|
-
}
|
|
111
|
-
}
|
|
1
|
+
export { RunnableAssign, RunnablePassthrough } from "langchain-core/runnables";
|
|
@@ -1,74 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RouterRunnable = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* A runnable that routes to a set of runnables based on Input['key'].
|
|
7
|
-
* Returns the output of the selected runnable.
|
|
8
|
-
*/
|
|
9
|
-
class RouterRunnable extends base_js_1.Runnable {
|
|
10
|
-
static lc_name() {
|
|
11
|
-
return "RouterRunnable";
|
|
12
|
-
}
|
|
13
|
-
constructor(fields) {
|
|
14
|
-
super(fields);
|
|
15
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
16
|
-
enumerable: true,
|
|
17
|
-
configurable: true,
|
|
18
|
-
writable: true,
|
|
19
|
-
value: ["langchain", "schema", "runnable"]
|
|
20
|
-
});
|
|
21
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
configurable: true,
|
|
24
|
-
writable: true,
|
|
25
|
-
value: true
|
|
26
|
-
});
|
|
27
|
-
Object.defineProperty(this, "runnables", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: void 0
|
|
32
|
-
});
|
|
33
|
-
this.runnables = fields.runnables;
|
|
34
|
-
}
|
|
35
|
-
async invoke(input, options) {
|
|
36
|
-
const { key, input: actualInput } = input;
|
|
37
|
-
const runnable = this.runnables[key];
|
|
38
|
-
if (runnable === undefined) {
|
|
39
|
-
throw new Error(`No runnable associated with key "${key}".`);
|
|
40
|
-
}
|
|
41
|
-
return runnable.invoke(actualInput, options);
|
|
42
|
-
}
|
|
43
|
-
async batch(inputs, options, batchOptions) {
|
|
44
|
-
const keys = inputs.map((input) => input.key);
|
|
45
|
-
const actualInputs = inputs.map((input) => input.input);
|
|
46
|
-
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
47
|
-
if (missingKey !== undefined) {
|
|
48
|
-
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
49
|
-
}
|
|
50
|
-
const runnables = keys.map((key) => this.runnables[key]);
|
|
51
|
-
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
52
|
-
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
53
|
-
? batchOptions?.maxConcurrency
|
|
54
|
-
: inputs.length;
|
|
55
|
-
const batchResults = [];
|
|
56
|
-
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
57
|
-
const batchPromises = actualInputs
|
|
58
|
-
.slice(i, i + batchSize)
|
|
59
|
-
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
60
|
-
const batchResult = await Promise.all(batchPromises);
|
|
61
|
-
batchResults.push(batchResult);
|
|
62
|
-
}
|
|
63
|
-
return batchResults.flat();
|
|
64
|
-
}
|
|
65
|
-
async stream(input, options) {
|
|
66
|
-
const { key, input: actualInput } = input;
|
|
67
|
-
const runnable = this.runnables[key];
|
|
68
|
-
if (runnable === undefined) {
|
|
69
|
-
throw new Error(`No runnable associated with key "${key}".`);
|
|
70
|
-
}
|
|
71
|
-
return runnable.stream(actualInput, options);
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
exports.RouterRunnable = RouterRunnable;
|
|
4
|
+
var runnables_1 = require("langchain-core/runnables");
|
|
5
|
+
Object.defineProperty(exports, "RouterRunnable", { enumerable: true, get: function () { return runnables_1.RouterRunnable; } });
|
|
@@ -1,29 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { IterableReadableStream } from "../../util/stream.js";
|
|
3
|
-
import type { RunnableConfig } from "./config.js";
|
|
4
|
-
export type RouterInput = {
|
|
5
|
-
key: string;
|
|
6
|
-
input: any;
|
|
7
|
-
};
|
|
8
|
-
/**
|
|
9
|
-
* A runnable that routes to a set of runnables based on Input['key'].
|
|
10
|
-
* Returns the output of the selected runnable.
|
|
11
|
-
*/
|
|
12
|
-
export declare class RouterRunnable<RunInput extends RouterInput, RunnableInput, RunOutput> extends Runnable<RunInput, RunOutput> {
|
|
13
|
-
static lc_name(): string;
|
|
14
|
-
lc_namespace: string[];
|
|
15
|
-
lc_serializable: boolean;
|
|
16
|
-
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
17
|
-
constructor(fields: {
|
|
18
|
-
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
19
|
-
});
|
|
20
|
-
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
21
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
22
|
-
returnExceptions?: false;
|
|
23
|
-
}): Promise<RunOutput[]>;
|
|
24
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
25
|
-
returnExceptions: true;
|
|
26
|
-
}): Promise<(RunOutput | Error)[]>;
|
|
27
|
-
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
28
|
-
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
29
|
-
}
|
|
1
|
+
export { type RouterInput, RouterRunnable } from "langchain-core/runnables";
|
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* A runnable that routes to a set of runnables based on Input['key'].
|
|
4
|
-
* Returns the output of the selected runnable.
|
|
5
|
-
*/
|
|
6
|
-
export class RouterRunnable extends Runnable {
|
|
7
|
-
static lc_name() {
|
|
8
|
-
return "RouterRunnable";
|
|
9
|
-
}
|
|
10
|
-
constructor(fields) {
|
|
11
|
-
super(fields);
|
|
12
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
configurable: true,
|
|
15
|
-
writable: true,
|
|
16
|
-
value: ["langchain", "schema", "runnable"]
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
configurable: true,
|
|
21
|
-
writable: true,
|
|
22
|
-
value: true
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(this, "runnables", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
configurable: true,
|
|
27
|
-
writable: true,
|
|
28
|
-
value: void 0
|
|
29
|
-
});
|
|
30
|
-
this.runnables = fields.runnables;
|
|
31
|
-
}
|
|
32
|
-
async invoke(input, options) {
|
|
33
|
-
const { key, input: actualInput } = input;
|
|
34
|
-
const runnable = this.runnables[key];
|
|
35
|
-
if (runnable === undefined) {
|
|
36
|
-
throw new Error(`No runnable associated with key "${key}".`);
|
|
37
|
-
}
|
|
38
|
-
return runnable.invoke(actualInput, options);
|
|
39
|
-
}
|
|
40
|
-
async batch(inputs, options, batchOptions) {
|
|
41
|
-
const keys = inputs.map((input) => input.key);
|
|
42
|
-
const actualInputs = inputs.map((input) => input.input);
|
|
43
|
-
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
44
|
-
if (missingKey !== undefined) {
|
|
45
|
-
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
46
|
-
}
|
|
47
|
-
const runnables = keys.map((key) => this.runnables[key]);
|
|
48
|
-
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
49
|
-
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
50
|
-
? batchOptions?.maxConcurrency
|
|
51
|
-
: inputs.length;
|
|
52
|
-
const batchResults = [];
|
|
53
|
-
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
54
|
-
const batchPromises = actualInputs
|
|
55
|
-
.slice(i, i + batchSize)
|
|
56
|
-
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
57
|
-
const batchResult = await Promise.all(batchPromises);
|
|
58
|
-
batchResults.push(batchResult);
|
|
59
|
-
}
|
|
60
|
-
return batchResults.flat();
|
|
61
|
-
}
|
|
62
|
-
async stream(input, options) {
|
|
63
|
-
const { key, input: actualInput } = input;
|
|
64
|
-
const runnable = this.runnables[key];
|
|
65
|
-
if (runnable === undefined) {
|
|
66
|
-
throw new Error(`No runnable associated with key "${key}".`);
|
|
67
|
-
}
|
|
68
|
-
return runnable.stream(actualInput, options);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
1
|
+
export { RouterRunnable } from "langchain-core/runnables";
|
package/dist/schema/storage.cjs
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
2
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports
|
|
4
|
-
const serializable_js_1 = require("../load/serializable.cjs");
|
|
5
|
-
/**
|
|
6
|
-
* Abstract interface for a key-value store.
|
|
7
|
-
*/
|
|
8
|
-
class BaseStore extends serializable_js_1.Serializable {
|
|
9
|
-
}
|
|
10
|
-
exports.BaseStore = BaseStore;
|
|
17
|
+
__exportStar(require("langchain-core/schema/storage"), exports);
|
package/dist/schema/storage.d.ts
CHANGED
|
@@ -1,57 +1 @@
|
|
|
1
|
-
|
|
2
|
-
/** @deprecated For backwards compatibility only. Remove on next minor version upgrade. */
|
|
3
|
-
export interface BaseStoreInterface<K, V> {
|
|
4
|
-
/**
|
|
5
|
-
* Method to get multiple values for a set of keys.
|
|
6
|
-
* @param {K[]} keys - An array of keys.
|
|
7
|
-
* @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
|
|
8
|
-
*/
|
|
9
|
-
mget(keys: K[]): Promise<(V | undefined)[]>;
|
|
10
|
-
/**
|
|
11
|
-
* Method to set a value for multiple keys.
|
|
12
|
-
* @param {[K, V][]} keyValuePairs - An array of key-value pairs.
|
|
13
|
-
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
|
|
14
|
-
*/
|
|
15
|
-
mset(keyValuePairs: [K, V][]): Promise<void>;
|
|
16
|
-
/**
|
|
17
|
-
* Method to delete multiple keys.
|
|
18
|
-
* @param {K[]} keys - An array of keys to delete.
|
|
19
|
-
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
|
|
20
|
-
*/
|
|
21
|
-
mdelete(keys: K[]): Promise<void>;
|
|
22
|
-
/**
|
|
23
|
-
* Method to yield keys optionally based on a prefix.
|
|
24
|
-
* @param {string} prefix - Optional prefix to filter keys.
|
|
25
|
-
* @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
|
|
26
|
-
*/
|
|
27
|
-
yieldKeys(prefix?: string): AsyncGenerator<K | string>;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* Abstract interface for a key-value store.
|
|
31
|
-
*/
|
|
32
|
-
export declare abstract class BaseStore<K, V> extends Serializable implements BaseStoreInterface<K, V> {
|
|
33
|
-
/**
|
|
34
|
-
* Abstract method to get multiple values for a set of keys.
|
|
35
|
-
* @param {K[]} keys - An array of keys.
|
|
36
|
-
* @returns {Promise<(V | undefined)[]>} - A Promise that resolves with array of values or undefined if key not found.
|
|
37
|
-
*/
|
|
38
|
-
abstract mget(keys: K[]): Promise<(V | undefined)[]>;
|
|
39
|
-
/**
|
|
40
|
-
* Abstract method to set a value for multiple keys.
|
|
41
|
-
* @param {[K, V][]} keyValuePairs - An array of key-value pairs.
|
|
42
|
-
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
|
|
43
|
-
*/
|
|
44
|
-
abstract mset(keyValuePairs: [K, V][]): Promise<void>;
|
|
45
|
-
/**
|
|
46
|
-
* Abstract method to delete multiple keys.
|
|
47
|
-
* @param {K[]} keys - An array of keys to delete.
|
|
48
|
-
* @returns {Promise<void>} - A Promise that resolves when the operation is complete.
|
|
49
|
-
*/
|
|
50
|
-
abstract mdelete(keys: K[]): Promise<void>;
|
|
51
|
-
/**
|
|
52
|
-
* Abstract method to yield keys optionally based on a prefix.
|
|
53
|
-
* @param {string} prefix - Optional prefix to filter keys.
|
|
54
|
-
* @returns {AsyncGenerator<K | string>} - An asynchronous generator that yields keys on iteration.
|
|
55
|
-
*/
|
|
56
|
-
abstract yieldKeys(prefix?: string): AsyncGenerator<K | string>;
|
|
57
|
-
}
|
|
1
|
+
export * from "langchain-core/schema/storage";
|
package/dist/schema/storage.js
CHANGED
|
@@ -11,7 +11,7 @@ declare class BingSerpAPI extends Tool {
|
|
|
11
11
|
/**
|
|
12
12
|
* Not implemented. Will throw an error if called.
|
|
13
13
|
*/
|
|
14
|
-
toJSON(): import("
|
|
14
|
+
toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
|
|
15
15
|
name: string;
|
|
16
16
|
description: string;
|
|
17
17
|
key: string;
|
|
@@ -62,7 +62,7 @@ export declare class SearchApi extends Tool {
|
|
|
62
62
|
* and will throw an error if called.
|
|
63
63
|
* @returns Throws an error.
|
|
64
64
|
*/
|
|
65
|
-
toJSON(): import("
|
|
65
|
+
toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
|
|
66
66
|
protected apiKey: string;
|
|
67
67
|
protected params: Partial<SearchApiParameters>;
|
|
68
68
|
constructor(apiKey?: string | undefined, params?: Partial<SearchApiParameters>);
|
package/dist/tools/serpapi.d.ts
CHANGED
|
@@ -281,7 +281,7 @@ type UrlParameters = Record<string, string | number | boolean | undefined | null
|
|
|
281
281
|
*/
|
|
282
282
|
export declare class SerpAPI extends Tool {
|
|
283
283
|
static lc_name(): string;
|
|
284
|
-
toJSON(): import("
|
|
284
|
+
toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
|
|
285
285
|
protected key: string;
|
|
286
286
|
protected params: Partial<SerpAPIParameters>;
|
|
287
287
|
protected baseUrl: string;
|
package/dist/tools/serper.d.ts
CHANGED
|
@@ -21,7 +21,7 @@ export declare class Serper extends Tool {
|
|
|
21
21
|
* and will throw an error if called.
|
|
22
22
|
* @returns Throws an error.
|
|
23
23
|
*/
|
|
24
|
-
toJSON(): import("
|
|
24
|
+
toJSON(): import("langchain-core/load/serializable").SerializedNotImplemented;
|
|
25
25
|
protected key: string;
|
|
26
26
|
protected params: Partial<SerperParameters>;
|
|
27
27
|
constructor(apiKey?: string | undefined, params?: Partial<SerperParameters>);
|
|
@@ -1,131 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports
|
|
7
|
-
const p_retry_1 = __importDefault(require("p-retry"));
|
|
8
|
-
const p_queue_1 = __importDefault(require("p-queue"));
|
|
9
|
-
const STATUS_NO_RETRY = [
|
|
10
|
-
400,
|
|
11
|
-
401,
|
|
12
|
-
402,
|
|
13
|
-
403,
|
|
14
|
-
404,
|
|
15
|
-
405,
|
|
16
|
-
406,
|
|
17
|
-
407,
|
|
18
|
-
408,
|
|
19
|
-
409, // Conflict
|
|
20
|
-
];
|
|
21
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
22
|
-
const defaultFailedAttemptHandler = (error) => {
|
|
23
|
-
if (error.message.startsWith("Cancel") ||
|
|
24
|
-
error.message.startsWith("TimeoutError") ||
|
|
25
|
-
error.name === "TimeoutError" ||
|
|
26
|
-
error.message.startsWith("AbortError") ||
|
|
27
|
-
error.name === "AbortError") {
|
|
28
|
-
throw error;
|
|
29
|
-
}
|
|
30
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
31
|
-
if (error?.code === "ECONNABORTED") {
|
|
32
|
-
throw error;
|
|
33
|
-
}
|
|
34
|
-
const status =
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
error?.response?.status ?? error?.status;
|
|
37
|
-
if (status && STATUS_NO_RETRY.includes(+status)) {
|
|
38
|
-
throw error;
|
|
39
|
-
}
|
|
40
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
41
|
-
if (error?.error?.code === "insufficient_quota") {
|
|
42
|
-
const err = new Error(error?.message);
|
|
43
|
-
err.name = "InsufficientQuotaError";
|
|
44
|
-
throw err;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
/**
|
|
48
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
49
|
-
*
|
|
50
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
51
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
52
|
-
*
|
|
53
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
54
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
55
|
-
*
|
|
56
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 6. This
|
|
57
|
-
* means that by default, each call will be retried up to 6 times, with an
|
|
58
|
-
* exponential backoff between each attempt.
|
|
59
|
-
*/
|
|
60
|
-
class AsyncCaller {
|
|
61
|
-
constructor(params) {
|
|
62
|
-
Object.defineProperty(this, "maxConcurrency", {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
configurable: true,
|
|
65
|
-
writable: true,
|
|
66
|
-
value: void 0
|
|
67
|
-
});
|
|
68
|
-
Object.defineProperty(this, "maxRetries", {
|
|
69
|
-
enumerable: true,
|
|
70
|
-
configurable: true,
|
|
71
|
-
writable: true,
|
|
72
|
-
value: void 0
|
|
73
|
-
});
|
|
74
|
-
Object.defineProperty(this, "onFailedAttempt", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
configurable: true,
|
|
77
|
-
writable: true,
|
|
78
|
-
value: void 0
|
|
79
|
-
});
|
|
80
|
-
Object.defineProperty(this, "queue", {
|
|
81
|
-
enumerable: true,
|
|
82
|
-
configurable: true,
|
|
83
|
-
writable: true,
|
|
84
|
-
value: void 0
|
|
85
|
-
});
|
|
86
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
87
|
-
this.maxRetries = params.maxRetries ?? 6;
|
|
88
|
-
this.onFailedAttempt =
|
|
89
|
-
params.onFailedAttempt ?? defaultFailedAttemptHandler;
|
|
90
|
-
const PQueue = "default" in p_queue_1.default ? p_queue_1.default.default : p_queue_1.default;
|
|
91
|
-
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
92
|
-
}
|
|
93
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
94
|
-
call(callable, ...args) {
|
|
95
|
-
return this.queue.add(() => (0, p_retry_1.default)(() => callable(...args).catch((error) => {
|
|
96
|
-
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
97
|
-
if (error instanceof Error) {
|
|
98
|
-
throw error;
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
throw new Error(error);
|
|
102
|
-
}
|
|
103
|
-
}), {
|
|
104
|
-
onFailedAttempt: this.onFailedAttempt,
|
|
105
|
-
retries: this.maxRetries,
|
|
106
|
-
randomize: true,
|
|
107
|
-
// If needed we can change some of the defaults here,
|
|
108
|
-
// but they're quite sensible.
|
|
109
|
-
}), { throwOnTimeout: true });
|
|
110
|
-
}
|
|
111
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
112
|
-
callWithOptions(options, callable, ...args) {
|
|
113
|
-
// Note this doesn't cancel the underlying request,
|
|
114
|
-
// when available prefer to use the signal option of the underlying call
|
|
115
|
-
if (options.signal) {
|
|
116
|
-
return Promise.race([
|
|
117
|
-
this.call(callable, ...args),
|
|
118
|
-
new Promise((_, reject) => {
|
|
119
|
-
options.signal?.addEventListener("abort", () => {
|
|
120
|
-
reject(new Error("AbortError"));
|
|
121
|
-
});
|
|
122
|
-
}),
|
|
123
|
-
]);
|
|
124
|
-
}
|
|
125
|
-
return this.call(callable, ...args);
|
|
126
|
-
}
|
|
127
|
-
fetch(...args) {
|
|
128
|
-
return this.call(() => fetch(...args).then((res) => (res.ok ? res : Promise.reject(res))));
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
exports.AsyncCaller = AsyncCaller;
|
|
17
|
+
__exportStar(require("langchain-core/util/async_caller"), exports);
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
export interface AsyncCallerParams {
|
|
3
|
-
/**
|
|
4
|
-
* The maximum number of concurrent calls that can be made.
|
|
5
|
-
* Defaults to `Infinity`, which means no limit.
|
|
6
|
-
*/
|
|
7
|
-
maxConcurrency?: number;
|
|
8
|
-
/**
|
|
9
|
-
* The maximum number of retries that can be made for a single call,
|
|
10
|
-
* with an exponential backoff between each attempt. Defaults to 6.
|
|
11
|
-
*/
|
|
12
|
-
maxRetries?: number;
|
|
13
|
-
/**
|
|
14
|
-
* Custom handler to handle failed attempts. Takes the originally thrown
|
|
15
|
-
* error object as input, and should itself throw an error if the input
|
|
16
|
-
* error is not retryable.
|
|
17
|
-
*/
|
|
18
|
-
onFailedAttempt?: FailedAttemptHandler;
|
|
19
|
-
}
|
|
20
|
-
export interface AsyncCallerCallOptions {
|
|
21
|
-
signal?: AbortSignal;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A class that can be used to make async calls with concurrency and retry logic.
|
|
25
|
-
*
|
|
26
|
-
* This is useful for making calls to any kind of "expensive" external resource,
|
|
27
|
-
* be it because it's rate-limited, subject to network issues, etc.
|
|
28
|
-
*
|
|
29
|
-
* Concurrent calls are limited by the `maxConcurrency` parameter, which defaults
|
|
30
|
-
* to `Infinity`. This means that by default, all calls will be made in parallel.
|
|
31
|
-
*
|
|
32
|
-
* Retries are limited by the `maxRetries` parameter, which defaults to 6. This
|
|
33
|
-
* means that by default, each call will be retried up to 6 times, with an
|
|
34
|
-
* exponential backoff between each attempt.
|
|
35
|
-
*/
|
|
36
|
-
export declare class AsyncCaller {
|
|
37
|
-
protected maxConcurrency: AsyncCallerParams["maxConcurrency"];
|
|
38
|
-
protected maxRetries: AsyncCallerParams["maxRetries"];
|
|
39
|
-
protected onFailedAttempt: AsyncCallerParams["onFailedAttempt"];
|
|
40
|
-
private queue;
|
|
41
|
-
constructor(params: AsyncCallerParams);
|
|
42
|
-
call<A extends any[], T extends (...args: A) => Promise<any>>(callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
43
|
-
callWithOptions<A extends any[], T extends (...args: A) => Promise<any>>(options: AsyncCallerCallOptions, callable: T, ...args: Parameters<T>): Promise<Awaited<ReturnType<T>>>;
|
|
44
|
-
fetch(...args: Parameters<typeof fetch>): ReturnType<typeof fetch>;
|
|
45
|
-
}
|
|
1
|
+
export * from "langchain-core/util/async_caller";
|