@langchain/core 0.2.0 → 0.2.1
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/callbacks/tests/callbacks.test.d.ts +1 -0
- package/dist/callbacks/tests/callbacks.test.js +492 -0
- package/dist/callbacks/tests/manager.int.test.d.ts +1 -0
- package/dist/callbacks/tests/manager.int.test.js +29 -0
- package/dist/callbacks/tests/run_collector.test.d.ts +1 -0
- package/dist/callbacks/tests/run_collector.test.js +58 -0
- package/dist/chat_history.cjs +13 -0
- package/dist/chat_history.d.ts +9 -0
- package/dist/chat_history.js +13 -0
- package/dist/language_models/chat_models.d.ts +2 -2
- package/dist/language_models/tests/chat_models.test.d.ts +1 -0
- package/dist/language_models/tests/chat_models.test.js +154 -0
- package/dist/language_models/tests/count_tokens.test.d.ts +1 -0
- package/dist/language_models/tests/count_tokens.test.js +19 -0
- package/dist/language_models/tests/llms.test.d.ts +1 -0
- package/dist/language_models/tests/llms.test.js +39 -0
- package/dist/messages/tests/base_message.test.d.ts +1 -0
- package/dist/messages/tests/base_message.test.js +97 -0
- package/dist/output_parsers/openai_tools/tests/json_output_tools_parser.test.d.ts +1 -0
- package/dist/output_parsers/openai_tools/tests/json_output_tools_parser.test.js +81 -0
- package/dist/output_parsers/tests/json.test.d.ts +1 -0
- package/dist/output_parsers/tests/json.test.js +427 -0
- package/dist/output_parsers/tests/output_parser.test.d.ts +1 -0
- package/dist/output_parsers/tests/output_parser.test.js +78 -0
- package/dist/output_parsers/tests/string.test.d.ts +1 -0
- package/dist/output_parsers/tests/string.test.js +68 -0
- package/dist/output_parsers/tests/structured.test.d.ts +1 -0
- package/dist/output_parsers/tests/structured.test.js +166 -0
- package/dist/output_parsers/tests/xml.test.d.ts +1 -0
- package/dist/output_parsers/tests/xml.test.js +81 -0
- package/dist/prompts/tests/chat.mustache.test.d.ts +1 -0
- package/dist/prompts/tests/chat.mustache.test.js +61 -0
- package/dist/prompts/tests/chat.test.d.ts +1 -0
- package/dist/prompts/tests/chat.test.js +507 -0
- package/dist/prompts/tests/few_shot.test.d.ts +1 -0
- package/dist/prompts/tests/few_shot.test.js +224 -0
- package/dist/prompts/tests/pipeline.test.d.ts +1 -0
- package/dist/prompts/tests/pipeline.test.js +101 -0
- package/dist/prompts/tests/prompt.mustache.test.d.ts +1 -0
- package/dist/prompts/tests/prompt.mustache.test.js +85 -0
- package/dist/prompts/tests/prompt.test.d.ts +1 -0
- package/dist/prompts/tests/prompt.test.js +78 -0
- package/dist/prompts/tests/structured.test.d.ts +1 -0
- package/dist/prompts/tests/structured.test.js +37 -0
- package/dist/prompts/tests/template.test.d.ts +1 -0
- package/dist/prompts/tests/template.test.js +24 -0
- package/dist/runnables/base.cjs +87 -6
- package/dist/runnables/base.d.ts +45 -26
- package/dist/runnables/base.js +87 -6
- package/dist/runnables/history.cjs +87 -32
- package/dist/runnables/history.d.ts +1 -1
- package/dist/runnables/history.js +87 -32
- package/dist/runnables/remote.cjs +2 -2
- package/dist/runnables/remote.d.ts +3 -3
- package/dist/runnables/remote.js +2 -2
- package/dist/runnables/tests/runnable.test.d.ts +1 -0
- package/dist/runnables/tests/runnable.test.js +491 -0
- package/dist/runnables/tests/runnable_binding.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_binding.test.js +46 -0
- package/dist/runnables/tests/runnable_branch.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_branch.test.js +116 -0
- package/dist/runnables/tests/runnable_graph.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_graph.test.js +84 -0
- package/dist/runnables/tests/runnable_history.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_history.test.js +177 -0
- package/dist/runnables/tests/runnable_interface.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_interface.test.js +209 -0
- package/dist/runnables/tests/runnable_map.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_map.test.js +238 -0
- package/dist/runnables/tests/runnable_passthrough.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_passthrough.test.js +96 -0
- package/dist/runnables/tests/runnable_remote.int.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_remote.int.test.js +138 -0
- package/dist/runnables/tests/runnable_remote.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_remote.test.js +200 -0
- package/dist/runnables/tests/runnable_retry.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_retry.test.js +125 -0
- package/dist/runnables/tests/runnable_stream_events.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_stream_events.test.js +1013 -0
- package/dist/runnables/tests/runnable_stream_events_v2.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_stream_events_v2.test.js +973 -0
- package/dist/runnables/tests/runnable_stream_log.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_stream_log.test.js +282 -0
- package/dist/runnables/tests/runnable_tracing.int.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_tracing.int.test.js +37 -0
- package/dist/runnables/tests/runnable_with_fallbacks.test.d.ts +1 -0
- package/dist/runnables/tests/runnable_with_fallbacks.test.js +36 -0
- package/dist/runnables/utils.d.ts +1 -1
- package/dist/singletons/tests/async_local_storage.test.d.ts +1 -0
- package/dist/singletons/tests/async_local_storage.test.js +120 -0
- package/dist/structured_query/tests/utils.test.d.ts +1 -0
- package/dist/structured_query/tests/utils.test.js +47 -0
- package/dist/tracers/event_stream.cjs +493 -0
- package/dist/tracers/event_stream.d.ts +137 -0
- package/dist/tracers/event_stream.js +489 -0
- package/dist/tracers/log_stream.d.ts +2 -77
- package/dist/tracers/tests/langchain_tracer.int.test.d.ts +1 -0
- package/dist/tracers/tests/langchain_tracer.int.test.js +74 -0
- package/dist/tracers/tests/tracer.test.d.ts +1 -0
- package/dist/tracers/tests/tracer.test.js +378 -0
- package/dist/utils/testing/tests/chatfake.test.d.ts +1 -0
- package/dist/utils/testing/tests/chatfake.test.js +112 -0
- package/dist/utils/tests/async_caller.test.d.ts +1 -0
- package/dist/utils/tests/async_caller.test.js +27 -0
- package/dist/utils/tests/enviroment.test.d.ts +1 -0
- package/dist/utils/tests/enviroment.test.js +6 -0
- package/dist/utils/tests/function_calling.test.d.ts +1 -0
- package/dist/utils/tests/function_calling.test.js +107 -0
- package/dist/utils/tests/math_utils.test.d.ts +1 -0
- package/dist/utils/tests/math_utils.test.js +139 -0
- package/dist/utils/tests/polyfill_stream.test.d.ts +1 -0
- package/dist/utils/tests/polyfill_stream.test.js +15 -0
- package/package.json +6 -6
|
@@ -123,68 +123,123 @@ export class RunnableWithMessageHistory extends RunnableBinding {
|
|
|
123
123
|
this.outputMessagesKey = fields.outputMessagesKey;
|
|
124
124
|
this.historyMessagesKey = fields.historyMessagesKey;
|
|
125
125
|
}
|
|
126
|
-
_getInputMessages(
|
|
127
|
-
|
|
128
|
-
|
|
126
|
+
_getInputMessages(
|
|
127
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
128
|
+
inputValue) {
|
|
129
|
+
let parsedInputValue;
|
|
130
|
+
if (typeof inputValue === "object" &&
|
|
131
|
+
!Array.isArray(inputValue) &&
|
|
132
|
+
!isBaseMessage(inputValue)) {
|
|
133
|
+
let key;
|
|
134
|
+
if (this.inputMessagesKey) {
|
|
135
|
+
key = this.inputMessagesKey;
|
|
136
|
+
}
|
|
137
|
+
else if (Object.keys(inputValue).length === 1) {
|
|
138
|
+
key = Object.keys(inputValue)[0];
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
key = "input";
|
|
142
|
+
}
|
|
143
|
+
if (Array.isArray(inputValue[key]) && Array.isArray(inputValue[key][0])) {
|
|
144
|
+
parsedInputValue = inputValue[key][0];
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
parsedInputValue = inputValue[key];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
parsedInputValue = inputValue;
|
|
152
|
+
}
|
|
153
|
+
if (typeof parsedInputValue === "string") {
|
|
154
|
+
return [new HumanMessage(parsedInputValue)];
|
|
129
155
|
}
|
|
130
|
-
else if (Array.isArray(
|
|
131
|
-
return
|
|
156
|
+
else if (Array.isArray(parsedInputValue)) {
|
|
157
|
+
return parsedInputValue;
|
|
158
|
+
}
|
|
159
|
+
else if (isBaseMessage(parsedInputValue)) {
|
|
160
|
+
return [parsedInputValue];
|
|
132
161
|
}
|
|
133
162
|
else {
|
|
134
|
-
|
|
163
|
+
throw new Error(`Expected a string, BaseMessage, or array of BaseMessages.\nGot ${JSON.stringify(parsedInputValue, null, 2)}`);
|
|
135
164
|
}
|
|
136
165
|
}
|
|
137
166
|
_getOutputMessages(
|
|
138
167
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
139
168
|
outputValue) {
|
|
140
|
-
let
|
|
169
|
+
let parsedOutputValue;
|
|
141
170
|
if (!Array.isArray(outputValue) &&
|
|
142
171
|
!isBaseMessage(outputValue) &&
|
|
143
172
|
typeof outputValue !== "string") {
|
|
144
|
-
|
|
173
|
+
let key;
|
|
174
|
+
if (this.outputMessagesKey !== undefined) {
|
|
175
|
+
key = this.outputMessagesKey;
|
|
176
|
+
}
|
|
177
|
+
else if (Object.keys(outputValue).length === 1) {
|
|
178
|
+
key = Object.keys(outputValue)[0];
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
key = "output";
|
|
182
|
+
}
|
|
183
|
+
// If you are wrapping a chat model directly
|
|
184
|
+
// The output is actually this weird generations object
|
|
185
|
+
if (outputValue.generations !== undefined) {
|
|
186
|
+
parsedOutputValue = outputValue.generations[0][0].message;
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
parsedOutputValue = outputValue[key];
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
parsedOutputValue = outputValue;
|
|
145
194
|
}
|
|
146
|
-
if (typeof
|
|
147
|
-
return [new AIMessage(
|
|
195
|
+
if (typeof parsedOutputValue === "string") {
|
|
196
|
+
return [new AIMessage(parsedOutputValue)];
|
|
148
197
|
}
|
|
149
|
-
else if (Array.isArray(
|
|
150
|
-
return
|
|
198
|
+
else if (Array.isArray(parsedOutputValue)) {
|
|
199
|
+
return parsedOutputValue;
|
|
151
200
|
}
|
|
152
|
-
else if (isBaseMessage(
|
|
153
|
-
return [
|
|
201
|
+
else if (isBaseMessage(parsedOutputValue)) {
|
|
202
|
+
return [parsedOutputValue];
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
throw new Error(`Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(parsedOutputValue, null, 2)}`);
|
|
154
206
|
}
|
|
155
|
-
throw new Error(`Expected a string, BaseMessage, or array of BaseMessages. Received: ${JSON.stringify(newOutputValue, null, 2)}`);
|
|
156
207
|
}
|
|
157
208
|
async _enterHistory(
|
|
158
209
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
159
210
|
input, kwargs) {
|
|
160
211
|
const history = kwargs?.config?.configurable?.messageHistory;
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
const historyMessages = history ? await history.getMessages() : [];
|
|
167
|
-
const returnType = [
|
|
168
|
-
...historyMessages,
|
|
169
|
-
...this._getInputMessages(inputVal),
|
|
170
|
-
];
|
|
171
|
-
return returnType;
|
|
212
|
+
const messages = await history.getMessages();
|
|
213
|
+
if (this.historyMessagesKey === undefined) {
|
|
214
|
+
return messages.concat(this._getInputMessages(input));
|
|
215
|
+
}
|
|
216
|
+
return messages;
|
|
172
217
|
}
|
|
173
218
|
async _exitHistory(run, config) {
|
|
174
219
|
const history = config.configurable?.messageHistory;
|
|
175
220
|
// Get input messages
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
221
|
+
let inputs;
|
|
222
|
+
// Chat model inputs are nested arrays
|
|
223
|
+
if (Array.isArray(run.inputs) && Array.isArray(run.inputs[0])) {
|
|
224
|
+
inputs = run.inputs[0];
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
inputs = run.inputs;
|
|
228
|
+
}
|
|
229
|
+
let inputMessages = this._getInputMessages(inputs);
|
|
230
|
+
// If historic messages were prepended to the input messages, remove them to
|
|
231
|
+
// avoid adding duplicate messages to history.
|
|
232
|
+
if (this.historyMessagesKey === undefined) {
|
|
233
|
+
const existingMessages = await history.getMessages();
|
|
234
|
+
inputMessages = inputMessages.slice(existingMessages.length);
|
|
235
|
+
}
|
|
179
236
|
// Get output messages
|
|
180
237
|
const outputValue = run.outputs;
|
|
181
238
|
if (!outputValue) {
|
|
182
239
|
throw new Error(`Output values from 'Run' undefined. Run: ${JSON.stringify(run, null, 2)}`);
|
|
183
240
|
}
|
|
184
241
|
const outputMessages = this._getOutputMessages(outputValue);
|
|
185
|
-
|
|
186
|
-
await history.addMessage(message);
|
|
187
|
-
}
|
|
242
|
+
await history.addMessages([...inputMessages, ...outputMessages]);
|
|
188
243
|
}
|
|
189
244
|
async _mergeConfig(...configs) {
|
|
190
245
|
const config = await super._mergeConfig(...configs);
|
|
@@ -461,8 +461,8 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
461
461
|
return generator();
|
|
462
462
|
}
|
|
463
463
|
streamEvents(input, options, streamOptions) {
|
|
464
|
-
if (options
|
|
465
|
-
throw new Error(`Only
|
|
464
|
+
if (options.version !== "v1" && options.version !== "v2") {
|
|
465
|
+
throw new Error(`Only versions "v1" and "v2" of the events schema is currently supported.`);
|
|
466
466
|
}
|
|
467
467
|
if (options.encoding !== undefined) {
|
|
468
468
|
throw new Error("Special encodings are not supported for this runnable.");
|
|
@@ -29,13 +29,13 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
|
|
|
29
29
|
_streamIterator(input: RunInput, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
30
30
|
streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
|
|
31
31
|
_streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
32
|
-
version: "v1";
|
|
32
|
+
version: "v1" | "v2";
|
|
33
33
|
}, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose"> | undefined): AsyncGenerator<StreamEvent>;
|
|
34
34
|
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
35
|
-
version: "v1";
|
|
35
|
+
version: "v1" | "v2";
|
|
36
36
|
}, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<StreamEvent>;
|
|
37
37
|
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
38
|
-
version: "v1";
|
|
38
|
+
version: "v1" | "v2";
|
|
39
39
|
encoding: "text/event-stream";
|
|
40
40
|
}, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): IterableReadableStream<Uint8Array>;
|
|
41
41
|
}
|
package/dist/runnables/remote.js
CHANGED
|
@@ -458,8 +458,8 @@ export class RemoteRunnable extends Runnable {
|
|
|
458
458
|
return generator();
|
|
459
459
|
}
|
|
460
460
|
streamEvents(input, options, streamOptions) {
|
|
461
|
-
if (options
|
|
462
|
-
throw new Error(`Only
|
|
461
|
+
if (options.version !== "v1" && options.version !== "v2") {
|
|
462
|
+
throw new Error(`Only versions "v1" and "v2" of the events schema is currently supported.`);
|
|
463
463
|
}
|
|
464
464
|
if (options.encoding !== undefined) {
|
|
465
465
|
throw new Error("Special encodings are not supported for this runnable.");
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|