langchain 0.0.194 → 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/embeddings/hf.cjs +1 -2
- package/dist/embeddings/hf.js +1 -2
- 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/openai_assistant/index.cjs +2 -1
- package/dist/experimental/openai_assistant/index.d.ts +2 -1
- package/dist/experimental/openai_assistant/index.js +2 -1
- package/dist/experimental/openai_files/index.cjs +88 -0
- package/dist/experimental/openai_files/index.d.ts +79 -0
- package/dist/experimental/openai_files/index.js +84 -0
- 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_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- 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/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/retrievers/chaindesk.cjs +9 -1
- package/dist/retrievers/chaindesk.d.ts +3 -1
- package/dist/retrievers/chaindesk.js +9 -1
- package/dist/retrievers/self_query/vectara.cjs +138 -0
- package/dist/retrievers/self_query/vectara.d.ts +41 -0
- package/dist/retrievers/self_query/vectara.js +134 -0
- 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/dist/vectorstores/vectara.cjs +77 -7
- package/dist/vectorstores/vectara.d.ts +9 -3
- package/dist/vectorstores/vectara.js +54 -7
- package/experimental/openai_files.cjs +1 -0
- package/experimental/openai_files.d.ts +1 -0
- package/experimental/openai_files.js +1 -0
- package/package.json +27 -5
- package/retrievers/self_query/vectara.cjs +1 -0
- package/retrievers/self_query/vectara.d.ts +1 -0
- package/retrievers/self_query/vectara.js +1 -0
- 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,311 +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
|
-
|
|
4
|
-
const index_js_1 = require("./index.cjs");
|
|
5
|
-
const index_js_2 = require("./runnable/index.cjs");
|
|
6
|
-
const index_js_3 = require("../util/@cfworker/json-schema/index.cjs");
|
|
7
|
-
/**
|
|
8
|
-
* Abstract base class for parsing the output of a Large Language Model
|
|
9
|
-
* (LLM) call. It provides methods for parsing the result of an LLM call
|
|
10
|
-
* and invoking the parser with a given input.
|
|
11
|
-
*/
|
|
12
|
-
class BaseLLMOutputParser extends index_js_2.Runnable {
|
|
13
|
-
/**
|
|
14
|
-
* Parses the result of an LLM call with a given prompt. By default, it
|
|
15
|
-
* simply calls `parseResult`.
|
|
16
|
-
* @param generations The generations from an LLM call.
|
|
17
|
-
* @param _prompt The prompt used in the LLM call.
|
|
18
|
-
* @param callbacks Optional callbacks.
|
|
19
|
-
* @returns A promise of the parsed output.
|
|
20
|
-
*/
|
|
21
|
-
parseResultWithPrompt(generations, _prompt, callbacks) {
|
|
22
|
-
return this.parseResult(generations, callbacks);
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Calls the parser with a given input and optional configuration options.
|
|
26
|
-
* If the input is a string, it creates a generation with the input as
|
|
27
|
-
* text and calls `parseResult`. If the input is a `BaseMessage`, it
|
|
28
|
-
* creates a generation with the input as a message and the content of the
|
|
29
|
-
* input as text, and then calls `parseResult`.
|
|
30
|
-
* @param input The input to the parser, which can be a string or a `BaseMessage`.
|
|
31
|
-
* @param options Optional configuration options.
|
|
32
|
-
* @returns A promise of the parsed output.
|
|
33
|
-
*/
|
|
34
|
-
async invoke(input, options) {
|
|
35
|
-
if (typeof input === "string") {
|
|
36
|
-
return this._callWithConfig(async (input) => this.parseResult([{ text: input }]), input, { ...options, runType: "parser" });
|
|
37
|
-
}
|
|
38
|
-
else {
|
|
39
|
-
return this._callWithConfig(async (input) => this.parseResult([
|
|
40
|
-
{
|
|
41
|
-
message: input,
|
|
42
|
-
text: typeof input.content === "string"
|
|
43
|
-
? input.content
|
|
44
|
-
: JSON.stringify(input.content),
|
|
45
|
-
},
|
|
46
|
-
]), input, { ...options, runType: "parser" });
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
exports.BaseLLMOutputParser = BaseLLMOutputParser;
|
|
51
|
-
/**
|
|
52
|
-
* Class to parse the output of an LLM call.
|
|
53
|
-
*/
|
|
54
|
-
class BaseOutputParser extends BaseLLMOutputParser {
|
|
55
|
-
parseResult(generations, callbacks) {
|
|
56
|
-
return this.parse(generations[0].text, callbacks);
|
|
57
|
-
}
|
|
58
|
-
async parseWithPrompt(text, _prompt, callbacks) {
|
|
59
|
-
return this.parse(text, callbacks);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Return the string type key uniquely identifying this class of parser
|
|
63
|
-
*/
|
|
64
|
-
_type() {
|
|
65
|
-
throw new Error("_type not implemented");
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
exports.BaseOutputParser = BaseOutputParser;
|
|
69
|
-
/**
|
|
70
|
-
* Class to parse the output of an LLM call that also allows streaming inputs.
|
|
71
|
-
*/
|
|
72
|
-
class BaseTransformOutputParser extends BaseOutputParser {
|
|
73
|
-
async *_transform(inputGenerator) {
|
|
74
|
-
for await (const chunk of inputGenerator) {
|
|
75
|
-
if (typeof chunk === "string") {
|
|
76
|
-
yield this.parseResult([{ text: chunk }]);
|
|
77
|
-
}
|
|
78
|
-
else {
|
|
79
|
-
yield this.parseResult([
|
|
80
|
-
{
|
|
81
|
-
message: chunk,
|
|
82
|
-
text: typeof chunk.content === "string"
|
|
83
|
-
? chunk.content
|
|
84
|
-
: JSON.stringify(chunk.content),
|
|
85
|
-
},
|
|
86
|
-
]);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Transforms an asynchronous generator of input into an asynchronous
|
|
92
|
-
* generator of parsed output.
|
|
93
|
-
* @param inputGenerator An asynchronous generator of input.
|
|
94
|
-
* @param options A configuration object.
|
|
95
|
-
* @returns An asynchronous generator of parsed output.
|
|
96
|
-
*/
|
|
97
|
-
async *transform(inputGenerator, options) {
|
|
98
|
-
yield* this._transformStreamWithConfig(inputGenerator, this._transform.bind(this), {
|
|
99
|
-
...options,
|
|
100
|
-
runType: "parser",
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
exports.BaseTransformOutputParser = BaseTransformOutputParser;
|
|
105
|
-
/**
|
|
106
|
-
* A base class for output parsers that can handle streaming input. It
|
|
107
|
-
* extends the `BaseTransformOutputParser` class and provides a method for
|
|
108
|
-
* converting parsed outputs into a diff format.
|
|
109
|
-
*/
|
|
110
|
-
class BaseCumulativeTransformOutputParser extends BaseTransformOutputParser {
|
|
111
|
-
constructor(fields) {
|
|
112
|
-
super(fields);
|
|
113
|
-
Object.defineProperty(this, "diff", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
configurable: true,
|
|
116
|
-
writable: true,
|
|
117
|
-
value: false
|
|
118
|
-
});
|
|
119
|
-
this.diff = fields?.diff ?? this.diff;
|
|
120
|
-
}
|
|
121
|
-
async *_transform(inputGenerator) {
|
|
122
|
-
let prevParsed;
|
|
123
|
-
let accGen;
|
|
124
|
-
for await (const chunk of inputGenerator) {
|
|
125
|
-
if (typeof chunk !== "string" && typeof chunk.content !== "string") {
|
|
126
|
-
throw new Error("Cannot handle non-string output.");
|
|
127
|
-
}
|
|
128
|
-
let chunkGen;
|
|
129
|
-
if ((0, index_js_1.isBaseMessageChunk)(chunk)) {
|
|
130
|
-
if (typeof chunk.content !== "string") {
|
|
131
|
-
throw new Error("Cannot handle non-string message output.");
|
|
132
|
-
}
|
|
133
|
-
chunkGen = new index_js_1.ChatGenerationChunk({
|
|
134
|
-
message: chunk,
|
|
135
|
-
text: chunk.content,
|
|
136
|
-
});
|
|
137
|
-
}
|
|
138
|
-
else if ((0, index_js_1.isBaseMessage)(chunk)) {
|
|
139
|
-
if (typeof chunk.content !== "string") {
|
|
140
|
-
throw new Error("Cannot handle non-string message output.");
|
|
141
|
-
}
|
|
142
|
-
chunkGen = new index_js_1.ChatGenerationChunk({
|
|
143
|
-
message: chunk.toChunk(),
|
|
144
|
-
text: chunk.content,
|
|
145
|
-
});
|
|
146
|
-
}
|
|
147
|
-
else {
|
|
148
|
-
chunkGen = new index_js_1.GenerationChunk({ text: chunk });
|
|
149
|
-
}
|
|
150
|
-
if (accGen === undefined) {
|
|
151
|
-
accGen = chunkGen;
|
|
152
|
-
}
|
|
153
|
-
else {
|
|
154
|
-
accGen = accGen.concat(chunkGen);
|
|
155
|
-
}
|
|
156
|
-
const parsed = await this.parsePartialResult([accGen]);
|
|
157
|
-
if (parsed !== undefined &&
|
|
158
|
-
parsed !== null &&
|
|
159
|
-
!(0, index_js_3.deepCompareStrict)(parsed, prevParsed)) {
|
|
160
|
-
if (this.diff) {
|
|
161
|
-
yield this._diff(prevParsed, parsed);
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
yield parsed;
|
|
165
|
-
}
|
|
166
|
-
prevParsed = parsed;
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
exports.BaseCumulativeTransformOutputParser = BaseCumulativeTransformOutputParser;
|
|
172
|
-
/**
|
|
173
|
-
* OutputParser that parses LLMResult into the top likely string.
|
|
174
|
-
* @example
|
|
175
|
-
* ```typescript
|
|
176
|
-
* const promptTemplate = PromptTemplate.fromTemplate(
|
|
177
|
-
* "Tell me a joke about {topic}",
|
|
178
|
-
* );
|
|
179
|
-
*
|
|
180
|
-
* const chain = RunnableSequence.from([
|
|
181
|
-
* promptTemplate,
|
|
182
|
-
* new ChatOpenAI({}),
|
|
183
|
-
* new StringOutputParser(),
|
|
184
|
-
* ]);
|
|
185
|
-
*
|
|
186
|
-
* const result = await chain.invoke({ topic: "bears" });
|
|
187
|
-
* console.log("What do you call a bear with no teeth? A gummy bear!");
|
|
188
|
-
* ```
|
|
189
|
-
*/
|
|
190
|
-
class StringOutputParser extends BaseTransformOutputParser {
|
|
191
|
-
constructor() {
|
|
192
|
-
super(...arguments);
|
|
193
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
194
|
-
enumerable: true,
|
|
195
|
-
configurable: true,
|
|
196
|
-
writable: true,
|
|
197
|
-
value: ["langchain", "schema", "output_parser"]
|
|
198
|
-
});
|
|
199
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
200
|
-
enumerable: true,
|
|
201
|
-
configurable: true,
|
|
202
|
-
writable: true,
|
|
203
|
-
value: true
|
|
204
|
-
});
|
|
205
|
-
}
|
|
206
|
-
static lc_name() {
|
|
207
|
-
return "StrOutputParser";
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Parses a string output from an LLM call. This method is meant to be
|
|
211
|
-
* implemented by subclasses to define how a string output from an LLM
|
|
212
|
-
* should be parsed.
|
|
213
|
-
* @param text The string output from an LLM call.
|
|
214
|
-
* @param callbacks Optional callbacks.
|
|
215
|
-
* @returns A promise of the parsed output.
|
|
216
|
-
*/
|
|
217
|
-
parse(text) {
|
|
218
|
-
return Promise.resolve(text);
|
|
219
|
-
}
|
|
220
|
-
getFormatInstructions() {
|
|
221
|
-
return "";
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
exports.StringOutputParser = StringOutputParser;
|
|
225
|
-
/**
|
|
226
|
-
* OutputParser that parses LLMResult into the top likely string and
|
|
227
|
-
* encodes it into bytes.
|
|
228
|
-
*/
|
|
229
|
-
class BytesOutputParser extends BaseTransformOutputParser {
|
|
230
|
-
constructor() {
|
|
231
|
-
super(...arguments);
|
|
232
|
-
Object.defineProperty(this, "lc_namespace", {
|
|
233
|
-
enumerable: true,
|
|
234
|
-
configurable: true,
|
|
235
|
-
writable: true,
|
|
236
|
-
value: ["langchain", "schema", "output_parser"]
|
|
237
|
-
});
|
|
238
|
-
Object.defineProperty(this, "lc_serializable", {
|
|
239
|
-
enumerable: true,
|
|
240
|
-
configurable: true,
|
|
241
|
-
writable: true,
|
|
242
|
-
value: true
|
|
243
|
-
});
|
|
244
|
-
Object.defineProperty(this, "textEncoder", {
|
|
245
|
-
enumerable: true,
|
|
246
|
-
configurable: true,
|
|
247
|
-
writable: true,
|
|
248
|
-
value: new TextEncoder()
|
|
249
|
-
});
|
|
250
|
-
}
|
|
251
|
-
static lc_name() {
|
|
252
|
-
return "BytesOutputParser";
|
|
253
|
-
}
|
|
254
|
-
parse(text) {
|
|
255
|
-
return Promise.resolve(this.textEncoder.encode(text));
|
|
256
|
-
}
|
|
257
|
-
getFormatInstructions() {
|
|
258
|
-
return "";
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
exports.BytesOutputParser = BytesOutputParser;
|
|
262
|
-
/**
|
|
263
|
-
* Exception that output parsers should raise to signify a parsing error.
|
|
264
|
-
*
|
|
265
|
-
* This exists to differentiate parsing errors from other code or execution errors
|
|
266
|
-
* that also may arise inside the output parser. OutputParserExceptions will be
|
|
267
|
-
* available to catch and handle in ways to fix the parsing error, while other
|
|
268
|
-
* errors will be raised.
|
|
269
|
-
*
|
|
270
|
-
* @param message - The error that's being re-raised or an error message.
|
|
271
|
-
* @param llmOutput - String model output which is error-ing.
|
|
272
|
-
* @param observation - String explanation of error which can be passed to a
|
|
273
|
-
* model to try and remediate the issue.
|
|
274
|
-
* @param sendToLLM - Whether to send the observation and llm_output back to an Agent
|
|
275
|
-
* after an OutputParserException has been raised. This gives the underlying
|
|
276
|
-
* model driving the agent the context that the previous output was improperly
|
|
277
|
-
* structured, in the hopes that it will update the output to the correct
|
|
278
|
-
* format.
|
|
279
|
-
*/
|
|
280
|
-
class OutputParserException extends Error {
|
|
281
|
-
constructor(message, llmOutput, observation, sendToLLM = false) {
|
|
282
|
-
super(message);
|
|
283
|
-
Object.defineProperty(this, "llmOutput", {
|
|
284
|
-
enumerable: true,
|
|
285
|
-
configurable: true,
|
|
286
|
-
writable: true,
|
|
287
|
-
value: void 0
|
|
288
|
-
});
|
|
289
|
-
Object.defineProperty(this, "observation", {
|
|
290
|
-
enumerable: true,
|
|
291
|
-
configurable: true,
|
|
292
|
-
writable: true,
|
|
293
|
-
value: void 0
|
|
294
|
-
});
|
|
295
|
-
Object.defineProperty(this, "sendToLLM", {
|
|
296
|
-
enumerable: true,
|
|
297
|
-
configurable: true,
|
|
298
|
-
writable: true,
|
|
299
|
-
value: void 0
|
|
300
|
-
});
|
|
301
|
-
this.llmOutput = llmOutput;
|
|
302
|
-
this.observation = observation;
|
|
303
|
-
this.sendToLLM = sendToLLM;
|
|
304
|
-
if (sendToLLM) {
|
|
305
|
-
if (observation === undefined || llmOutput === undefined) {
|
|
306
|
-
throw new Error("Arguments 'observation' & 'llmOutput' are required if 'sendToLlm' is true");
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
exports.OutputParserException = OutputParserException;
|
|
17
|
+
__exportStar(require("langchain-core/schema/output_parser"), exports);
|
|
@@ -1,173 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { BasePromptValue, Generation, ChatGeneration, BaseMessage } from "./index.js";
|
|
3
|
-
import { Runnable } from "./runnable/index.js";
|
|
4
|
-
import { RunnableConfig } from "./runnable/config.js";
|
|
5
|
-
/**
|
|
6
|
-
* Options for formatting instructions.
|
|
7
|
-
*/
|
|
8
|
-
export interface FormatInstructionsOptions {
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Abstract base class for parsing the output of a Large Language Model
|
|
12
|
-
* (LLM) call. It provides methods for parsing the result of an LLM call
|
|
13
|
-
* and invoking the parser with a given input.
|
|
14
|
-
*/
|
|
15
|
-
export declare abstract class BaseLLMOutputParser<T = unknown> extends Runnable<string | BaseMessage, T> {
|
|
16
|
-
/**
|
|
17
|
-
* Parses the result of an LLM call. This method is meant to be
|
|
18
|
-
* implemented by subclasses to define how the output from the LLM should
|
|
19
|
-
* be parsed.
|
|
20
|
-
* @param generations The generations from an LLM call.
|
|
21
|
-
* @param callbacks Optional callbacks.
|
|
22
|
-
* @returns A promise of the parsed output.
|
|
23
|
-
*/
|
|
24
|
-
abstract parseResult(generations: Generation[] | ChatGeneration[], callbacks?: Callbacks): Promise<T>;
|
|
25
|
-
/**
|
|
26
|
-
* Parses the result of an LLM call with a given prompt. By default, it
|
|
27
|
-
* simply calls `parseResult`.
|
|
28
|
-
* @param generations The generations from an LLM call.
|
|
29
|
-
* @param _prompt The prompt used in the LLM call.
|
|
30
|
-
* @param callbacks Optional callbacks.
|
|
31
|
-
* @returns A promise of the parsed output.
|
|
32
|
-
*/
|
|
33
|
-
parseResultWithPrompt(generations: Generation[] | ChatGeneration[], _prompt: BasePromptValue, callbacks?: Callbacks): Promise<T>;
|
|
34
|
-
/**
|
|
35
|
-
* Calls the parser with a given input and optional configuration options.
|
|
36
|
-
* If the input is a string, it creates a generation with the input as
|
|
37
|
-
* text and calls `parseResult`. If the input is a `BaseMessage`, it
|
|
38
|
-
* creates a generation with the input as a message and the content of the
|
|
39
|
-
* input as text, and then calls `parseResult`.
|
|
40
|
-
* @param input The input to the parser, which can be a string or a `BaseMessage`.
|
|
41
|
-
* @param options Optional configuration options.
|
|
42
|
-
* @returns A promise of the parsed output.
|
|
43
|
-
*/
|
|
44
|
-
invoke(input: string | BaseMessage, options?: RunnableConfig): Promise<T>;
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Class to parse the output of an LLM call.
|
|
48
|
-
*/
|
|
49
|
-
export declare abstract class BaseOutputParser<T = unknown> extends BaseLLMOutputParser<T> {
|
|
50
|
-
parseResult(generations: Generation[] | ChatGeneration[], callbacks?: Callbacks): Promise<T>;
|
|
51
|
-
/**
|
|
52
|
-
* Parse the output of an LLM call.
|
|
53
|
-
*
|
|
54
|
-
* @param text - LLM output to parse.
|
|
55
|
-
* @returns Parsed output.
|
|
56
|
-
*/
|
|
57
|
-
abstract parse(text: string, callbacks?: Callbacks): Promise<T>;
|
|
58
|
-
parseWithPrompt(text: string, _prompt: BasePromptValue, callbacks?: Callbacks): Promise<T>;
|
|
59
|
-
/**
|
|
60
|
-
* Return a string describing the format of the output.
|
|
61
|
-
* @returns Format instructions.
|
|
62
|
-
* @param options - Options for formatting instructions.
|
|
63
|
-
* @example
|
|
64
|
-
* ```json
|
|
65
|
-
* {
|
|
66
|
-
* "foo": "bar"
|
|
67
|
-
* }
|
|
68
|
-
* ```
|
|
69
|
-
*/
|
|
70
|
-
abstract getFormatInstructions(options?: FormatInstructionsOptions): string;
|
|
71
|
-
/**
|
|
72
|
-
* Return the string type key uniquely identifying this class of parser
|
|
73
|
-
*/
|
|
74
|
-
_type(): string;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Class to parse the output of an LLM call that also allows streaming inputs.
|
|
78
|
-
*/
|
|
79
|
-
export declare abstract class BaseTransformOutputParser<T = unknown> extends BaseOutputParser<T> {
|
|
80
|
-
_transform(inputGenerator: AsyncGenerator<string | BaseMessage>): AsyncGenerator<T>;
|
|
81
|
-
/**
|
|
82
|
-
* Transforms an asynchronous generator of input into an asynchronous
|
|
83
|
-
* generator of parsed output.
|
|
84
|
-
* @param inputGenerator An asynchronous generator of input.
|
|
85
|
-
* @param options A configuration object.
|
|
86
|
-
* @returns An asynchronous generator of parsed output.
|
|
87
|
-
*/
|
|
88
|
-
transform(inputGenerator: AsyncGenerator<string | BaseMessage>, options: BaseCallbackConfig): AsyncGenerator<T>;
|
|
89
|
-
}
|
|
90
|
-
export type BaseCumulativeTransformOutputParserInput = {
|
|
91
|
-
diff?: boolean;
|
|
92
|
-
};
|
|
93
|
-
/**
|
|
94
|
-
* A base class for output parsers that can handle streaming input. It
|
|
95
|
-
* extends the `BaseTransformOutputParser` class and provides a method for
|
|
96
|
-
* converting parsed outputs into a diff format.
|
|
97
|
-
*/
|
|
98
|
-
export declare abstract class BaseCumulativeTransformOutputParser<T = unknown> extends BaseTransformOutputParser<T> {
|
|
99
|
-
protected diff: boolean;
|
|
100
|
-
constructor(fields?: BaseCumulativeTransformOutputParserInput);
|
|
101
|
-
protected abstract _diff(prev: any | undefined, next: any): any;
|
|
102
|
-
abstract parsePartialResult(generations: Generation[] | ChatGeneration[]): Promise<T | undefined>;
|
|
103
|
-
_transform(inputGenerator: AsyncGenerator<string | BaseMessage>): AsyncGenerator<T>;
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* OutputParser that parses LLMResult into the top likely string.
|
|
107
|
-
* @example
|
|
108
|
-
* ```typescript
|
|
109
|
-
* const promptTemplate = PromptTemplate.fromTemplate(
|
|
110
|
-
* "Tell me a joke about {topic}",
|
|
111
|
-
* );
|
|
112
|
-
*
|
|
113
|
-
* const chain = RunnableSequence.from([
|
|
114
|
-
* promptTemplate,
|
|
115
|
-
* new ChatOpenAI({}),
|
|
116
|
-
* new StringOutputParser(),
|
|
117
|
-
* ]);
|
|
118
|
-
*
|
|
119
|
-
* const result = await chain.invoke({ topic: "bears" });
|
|
120
|
-
* console.log("What do you call a bear with no teeth? A gummy bear!");
|
|
121
|
-
* ```
|
|
122
|
-
*/
|
|
123
|
-
export declare class StringOutputParser extends BaseTransformOutputParser<string> {
|
|
124
|
-
static lc_name(): string;
|
|
125
|
-
lc_namespace: string[];
|
|
126
|
-
lc_serializable: boolean;
|
|
127
|
-
/**
|
|
128
|
-
* Parses a string output from an LLM call. This method is meant to be
|
|
129
|
-
* implemented by subclasses to define how a string output from an LLM
|
|
130
|
-
* should be parsed.
|
|
131
|
-
* @param text The string output from an LLM call.
|
|
132
|
-
* @param callbacks Optional callbacks.
|
|
133
|
-
* @returns A promise of the parsed output.
|
|
134
|
-
*/
|
|
135
|
-
parse(text: string): Promise<string>;
|
|
136
|
-
getFormatInstructions(): string;
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* OutputParser that parses LLMResult into the top likely string and
|
|
140
|
-
* encodes it into bytes.
|
|
141
|
-
*/
|
|
142
|
-
export declare class BytesOutputParser extends BaseTransformOutputParser<Uint8Array> {
|
|
143
|
-
static lc_name(): string;
|
|
144
|
-
lc_namespace: string[];
|
|
145
|
-
lc_serializable: boolean;
|
|
146
|
-
protected textEncoder: TextEncoder;
|
|
147
|
-
parse(text: string): Promise<Uint8Array>;
|
|
148
|
-
getFormatInstructions(): string;
|
|
149
|
-
}
|
|
150
|
-
/**
|
|
151
|
-
* Exception that output parsers should raise to signify a parsing error.
|
|
152
|
-
*
|
|
153
|
-
* This exists to differentiate parsing errors from other code or execution errors
|
|
154
|
-
* that also may arise inside the output parser. OutputParserExceptions will be
|
|
155
|
-
* available to catch and handle in ways to fix the parsing error, while other
|
|
156
|
-
* errors will be raised.
|
|
157
|
-
*
|
|
158
|
-
* @param message - The error that's being re-raised or an error message.
|
|
159
|
-
* @param llmOutput - String model output which is error-ing.
|
|
160
|
-
* @param observation - String explanation of error which can be passed to a
|
|
161
|
-
* model to try and remediate the issue.
|
|
162
|
-
* @param sendToLLM - Whether to send the observation and llm_output back to an Agent
|
|
163
|
-
* after an OutputParserException has been raised. This gives the underlying
|
|
164
|
-
* model driving the agent the context that the previous output was improperly
|
|
165
|
-
* structured, in the hopes that it will update the output to the correct
|
|
166
|
-
* format.
|
|
167
|
-
*/
|
|
168
|
-
export declare class OutputParserException extends Error {
|
|
169
|
-
llmOutput?: string;
|
|
170
|
-
observation?: string;
|
|
171
|
-
sendToLLM: boolean;
|
|
172
|
-
constructor(message: string, llmOutput?: string, observation?: string, sendToLLM?: boolean);
|
|
173
|
-
}
|
|
1
|
+
export * from "langchain-core/schema/output_parser";
|