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