@langchain/core 0.1.52 → 0.1.54
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/base.d.ts +1 -1
- package/dist/callbacks/manager.cjs +13 -11
- package/dist/callbacks/manager.d.ts +8 -3
- package/dist/callbacks/manager.js +13 -11
- package/dist/example_selectors/conditional.d.ts +1 -1
- package/dist/language_models/chat_models.cjs +3 -3
- package/dist/language_models/chat_models.js +3 -3
- package/dist/language_models/llms.cjs +5 -4
- package/dist/language_models/llms.d.ts +2 -1
- package/dist/language_models/llms.js +5 -4
- package/dist/load/import_map.cjs +2 -2
- package/dist/load/import_map.d.ts +2 -2
- package/dist/load/import_map.js +2 -2
- package/dist/messages/index.d.ts +10 -3
- package/dist/output_parsers/string.cjs +12 -5
- package/dist/output_parsers/string.js +12 -5
- package/dist/prompts/base.d.ts +1 -1
- package/dist/prompts/chat.cjs +32 -3
- package/dist/prompts/chat.d.ts +1 -1
- package/dist/prompts/chat.js +32 -3
- package/dist/prompts/few_shot.d.ts +1 -1
- package/dist/prompts/image.d.ts +1 -1
- package/dist/prompts/pipeline.d.ts +1 -1
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/string.d.ts +1 -1
- package/dist/prompts/structured.d.ts +1 -1
- package/dist/prompts/template.d.ts +1 -1
- package/dist/retrievers/document_compressors/base.cjs +13 -0
- package/dist/retrievers/document_compressors/base.d.ts +18 -0
- package/dist/retrievers/document_compressors/base.js +9 -0
- package/dist/{retrievers.cjs → retrievers/index.cjs} +4 -4
- package/dist/{retrievers.d.ts → retrievers/index.d.ts} +4 -4
- package/dist/{retrievers.js → retrievers/index.js} +4 -4
- package/dist/runnables/base.cjs +36 -11
- package/dist/runnables/base.js +36 -11
- package/dist/runnables/branch.cjs +1 -1
- package/dist/runnables/branch.js +1 -1
- package/dist/runnables/config.cjs +5 -1
- package/dist/runnables/config.d.ts +1 -1
- package/dist/runnables/config.js +5 -1
- package/dist/runnables/remote.cjs +120 -79
- package/dist/runnables/remote.d.ts +3 -3
- package/dist/runnables/remote.js +123 -82
- package/dist/tools.cjs +2 -1
- package/dist/tools.js +2 -1
- package/dist/tracers/base.d.ts +1 -1
- package/dist/tracers/tracer_langchain_v1.d.ts +1 -1
- package/dist/utils/testing/index.cjs +37 -3
- package/dist/utils/testing/index.d.ts +10 -1
- package/dist/utils/testing/index.js +34 -1
- package/dist/utils/types/index.cjs +17 -0
- package/dist/utils/{types.d.ts → types/index.d.ts} +1 -0
- package/dist/utils/types/index.js +1 -0
- package/dist/utils/types/is_zod_schema.cjs +16 -0
- package/dist/utils/types/is_zod_schema.d.ts +8 -0
- package/dist/utils/types/is_zod_schema.js +12 -0
- package/dist/vectorstores.cjs +2 -2
- package/dist/vectorstores.d.ts +1 -1
- package/dist/vectorstores.js +1 -1
- package/package.json +27 -14
- package/retrievers/document_compressors.cjs +1 -0
- package/retrievers/document_compressors.d.cts +1 -0
- package/retrievers/document_compressors.d.ts +1 -0
- package/retrievers/document_compressors.js +1 -0
- package/retrievers.cjs +1 -1
- package/retrievers.d.cts +1 -1
- package/retrievers.d.ts +1 -1
- package/retrievers.js +1 -1
- package/utils/types.cjs +1 -1
- package/utils/types.d.cts +1 -1
- package/utils/types.d.ts +1 -1
- package/utils/types.js +1 -1
- package/dist/utils/types.cjs +0 -5
- package/dist/utils/types.js +0 -4
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.RemoteRunnable = void 0;
|
|
4
4
|
const base_js_1 = require("./base.cjs");
|
|
5
|
+
const config_js_1 = require("./config.cjs");
|
|
5
6
|
const index_js_1 = require("../documents/index.cjs");
|
|
6
7
|
const prompt_values_js_1 = require("../prompt_values.cjs");
|
|
7
8
|
const log_stream_js_1 = require("../tracers/log_stream.cjs");
|
|
@@ -261,7 +262,7 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
261
262
|
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
262
263
|
});
|
|
263
264
|
}
|
|
264
|
-
async
|
|
265
|
+
async _invoke(input, options, _) {
|
|
265
266
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
266
267
|
const response = await this.post("/invoke", {
|
|
267
268
|
input,
|
|
@@ -273,6 +274,9 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
273
274
|
}
|
|
274
275
|
return revive((await response.json()).output);
|
|
275
276
|
}
|
|
277
|
+
async invoke(input, options) {
|
|
278
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
279
|
+
}
|
|
276
280
|
async _batch(inputs, options, _, batchOptions) {
|
|
277
281
|
if (batchOptions?.returnExceptions) {
|
|
278
282
|
throw new Error("returnExceptions is not supported for remote clients");
|
|
@@ -303,50 +307,60 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
303
307
|
}
|
|
304
308
|
return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
|
|
305
309
|
}
|
|
306
|
-
async
|
|
310
|
+
async *_streamIterator(input, options) {
|
|
307
311
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
312
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
313
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
314
|
+
let finalOutput;
|
|
315
|
+
let finalOutputSupported = true;
|
|
316
|
+
try {
|
|
317
|
+
const response = await this.post("/stream", {
|
|
318
|
+
input,
|
|
319
|
+
config: removeCallbacks(config),
|
|
320
|
+
kwargs,
|
|
321
|
+
});
|
|
322
|
+
if (!response.ok) {
|
|
323
|
+
const json = await response.json();
|
|
324
|
+
const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
|
|
325
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
326
|
+
error.response = response;
|
|
327
|
+
throw error;
|
|
328
|
+
}
|
|
329
|
+
const { body } = response;
|
|
330
|
+
if (!body) {
|
|
331
|
+
throw new Error("Could not begin remote stream. Please check the given URL and try again.");
|
|
332
|
+
}
|
|
333
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
326
334
|
for await (const chunk of runnableStream) {
|
|
327
|
-
|
|
335
|
+
const deserializedChunk = deserialize(chunk);
|
|
336
|
+
yield deserializedChunk;
|
|
337
|
+
if (finalOutputSupported) {
|
|
338
|
+
if (finalOutput === undefined) {
|
|
339
|
+
finalOutput = deserializedChunk;
|
|
340
|
+
}
|
|
341
|
+
else {
|
|
342
|
+
try {
|
|
343
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
344
|
+
finalOutput = (0, stream_js_1.concat)(finalOutput, deserializedChunk);
|
|
345
|
+
}
|
|
346
|
+
catch {
|
|
347
|
+
finalOutput = undefined;
|
|
348
|
+
finalOutputSupported = false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
328
352
|
}
|
|
329
353
|
}
|
|
330
|
-
|
|
354
|
+
catch (err) {
|
|
355
|
+
await runManager?.handleChainError(err);
|
|
356
|
+
throw err;
|
|
357
|
+
}
|
|
358
|
+
await runManager?.handleChainEnd(finalOutput ?? {});
|
|
331
359
|
}
|
|
332
360
|
async *streamLog(input, options, streamOptions) {
|
|
333
361
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
autoClose: false,
|
|
337
|
-
});
|
|
338
|
-
const { callbacks } = config;
|
|
339
|
-
if (callbacks === undefined) {
|
|
340
|
-
config.callbacks = [stream];
|
|
341
|
-
}
|
|
342
|
-
else if (Array.isArray(callbacks)) {
|
|
343
|
-
config.callbacks = callbacks.concat([stream]);
|
|
344
|
-
}
|
|
345
|
-
else {
|
|
346
|
-
const copiedCallbacks = callbacks.copy();
|
|
347
|
-
copiedCallbacks.inheritableHandlers.push(stream);
|
|
348
|
-
config.callbacks = copiedCallbacks;
|
|
349
|
-
}
|
|
362
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
363
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
350
364
|
// The type is in camelCase but the API only accepts snake_case.
|
|
351
365
|
const camelCaseStreamOptions = {
|
|
352
366
|
include_names: streamOptions?.includeNames,
|
|
@@ -356,31 +370,48 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
356
370
|
exclude_types: streamOptions?.excludeTypes,
|
|
357
371
|
exclude_tags: streamOptions?.excludeTags,
|
|
358
372
|
};
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
373
|
+
let runLog;
|
|
374
|
+
try {
|
|
375
|
+
const response = await this.post("/stream_log", {
|
|
376
|
+
input,
|
|
377
|
+
config: removeCallbacks(config),
|
|
378
|
+
kwargs,
|
|
379
|
+
...camelCaseStreamOptions,
|
|
380
|
+
diff: false,
|
|
381
|
+
});
|
|
382
|
+
const { body, ok } = response;
|
|
383
|
+
if (!ok) {
|
|
384
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
385
|
+
}
|
|
386
|
+
if (!body) {
|
|
387
|
+
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
388
|
+
}
|
|
389
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
390
|
+
for await (const log of runnableStream) {
|
|
391
|
+
const chunk = revive(JSON.parse(log));
|
|
392
|
+
const logPatch = new log_stream_js_1.RunLogPatch({ ops: chunk.ops });
|
|
393
|
+
yield logPatch;
|
|
394
|
+
if (runLog === undefined) {
|
|
395
|
+
runLog = log_stream_js_1.RunLog.fromRunLogPatch(logPatch);
|
|
396
|
+
}
|
|
397
|
+
else {
|
|
398
|
+
runLog = runLog.concat(logPatch);
|
|
399
|
+
}
|
|
400
|
+
}
|
|
372
401
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
yield new log_stream_js_1.RunLogPatch({ ops: chunk.ops });
|
|
402
|
+
catch (err) {
|
|
403
|
+
await runManager?.handleChainError(err);
|
|
404
|
+
throw err;
|
|
377
405
|
}
|
|
406
|
+
await runManager?.handleChainEnd(runLog?.state.final_output);
|
|
378
407
|
}
|
|
379
408
|
async *streamEvents(input, options, streamOptions) {
|
|
380
409
|
if (options?.version !== "v1") {
|
|
381
410
|
throw new Error(`Only version "v1" of the events schema is currently supported.`);
|
|
382
411
|
}
|
|
383
412
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
413
|
+
const callbackManager_ = await (0, config_js_1.getCallbackManagerForConfig)(options);
|
|
414
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), (0, base_js_1._coerceToDict)(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
384
415
|
// The type is in camelCase but the API only accepts snake_case.
|
|
385
416
|
const camelCaseStreamOptions = {
|
|
386
417
|
include_names: streamOptions?.includeNames,
|
|
@@ -390,32 +421,42 @@ class RemoteRunnable extends base_js_1.Runnable {
|
|
|
390
421
|
exclude_types: streamOptions?.excludeTypes,
|
|
391
422
|
exclude_tags: streamOptions?.excludeTags,
|
|
392
423
|
};
|
|
393
|
-
const
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
424
|
+
const events = [];
|
|
425
|
+
try {
|
|
426
|
+
const response = await this.post("/stream_events", {
|
|
427
|
+
input,
|
|
428
|
+
config: removeCallbacks(config),
|
|
429
|
+
kwargs,
|
|
430
|
+
...camelCaseStreamOptions,
|
|
431
|
+
diff: false,
|
|
432
|
+
});
|
|
433
|
+
const { body, ok } = response;
|
|
434
|
+
if (!ok) {
|
|
435
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
436
|
+
}
|
|
437
|
+
if (!body) {
|
|
438
|
+
throw new Error("Could not begin remote stream events. Please check the given URL and try again.");
|
|
439
|
+
}
|
|
440
|
+
const runnableStream = (0, event_source_parse_js_1.convertEventStreamToIterableReadableDataStream)(body);
|
|
441
|
+
for await (const log of runnableStream) {
|
|
442
|
+
const chunk = revive(JSON.parse(log));
|
|
443
|
+
const event = {
|
|
444
|
+
event: chunk.event,
|
|
445
|
+
name: chunk.name,
|
|
446
|
+
run_id: chunk.run_id,
|
|
447
|
+
tags: chunk.tags,
|
|
448
|
+
metadata: chunk.metadata,
|
|
449
|
+
data: chunk.data,
|
|
450
|
+
};
|
|
451
|
+
yield event;
|
|
452
|
+
events.push(event);
|
|
453
|
+
}
|
|
406
454
|
}
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
yield {
|
|
411
|
-
event: chunk.event,
|
|
412
|
-
name: chunk.name,
|
|
413
|
-
run_id: chunk.run_id,
|
|
414
|
-
tags: chunk.tags,
|
|
415
|
-
metadata: chunk.metadata,
|
|
416
|
-
data: chunk.data,
|
|
417
|
-
};
|
|
455
|
+
catch (err) {
|
|
456
|
+
await runManager?.handleChainError(err);
|
|
457
|
+
throw err;
|
|
418
458
|
}
|
|
459
|
+
await runManager?.handleChainEnd(events);
|
|
419
460
|
}
|
|
420
461
|
}
|
|
421
462
|
exports.RemoteRunnable = RemoteRunnable;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Runnable, RunnableBatchOptions } from "./base.js";
|
|
2
|
-
import type
|
|
2
|
+
import { type RunnableConfig } from "./config.js";
|
|
3
3
|
import { CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
4
4
|
import { RunLogPatch, type LogStreamCallbackHandlerInput, type StreamEvent } from "../tracers/log_stream.js";
|
|
5
|
-
import { IterableReadableStream } from "../utils/stream.js";
|
|
6
5
|
type RemoteRunnableOptions = {
|
|
7
6
|
timeout?: number;
|
|
8
7
|
headers?: Record<string, unknown>;
|
|
@@ -16,6 +15,7 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
|
|
|
16
15
|
options?: RemoteRunnableOptions;
|
|
17
16
|
});
|
|
18
17
|
private post;
|
|
18
|
+
_invoke(input: RunInput, options?: Partial<CallOptions>, _?: CallbackManagerForChainRun): Promise<RunOutput>;
|
|
19
19
|
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
20
20
|
_batch(inputs: RunInput[], options?: Partial<CallOptions>[], _?: (CallbackManagerForChainRun | undefined)[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
21
21
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions & {
|
|
@@ -25,7 +25,7 @@ export declare class RemoteRunnable<RunInput, RunOutput, CallOptions extends Run
|
|
|
25
25
|
returnExceptions: true;
|
|
26
26
|
}): Promise<(RunOutput | Error)[]>;
|
|
27
27
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
28
|
-
|
|
28
|
+
_streamIterator(input: RunInput, options?: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
29
29
|
streamLog(input: RunInput, options?: Partial<CallOptions>, streamOptions?: Omit<LogStreamCallbackHandlerInput, "autoClose">): AsyncGenerator<RunLogPatch>;
|
|
30
30
|
streamEvents(input: RunInput, options: Partial<CallOptions> & {
|
|
31
31
|
version: "v1";
|
package/dist/runnables/remote.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { Runnable } from "./base.js";
|
|
1
|
+
import { Runnable, _coerceToDict } from "./base.js";
|
|
2
|
+
import { getCallbackManagerForConfig } from "./config.js";
|
|
2
3
|
import { Document } from "../documents/index.js";
|
|
3
4
|
import { ChatPromptValue, StringPromptValue } from "../prompt_values.js";
|
|
4
|
-
import {
|
|
5
|
+
import { RunLogPatch, RunLog, } from "../tracers/log_stream.js";
|
|
5
6
|
import { AIMessage, AIMessageChunk, ChatMessage, ChatMessageChunk, FunctionMessage, FunctionMessageChunk, HumanMessage, HumanMessageChunk, SystemMessage, SystemMessageChunk, ToolMessage, ToolMessageChunk, isBaseMessage, } from "../messages/index.js";
|
|
6
7
|
import { GenerationChunk, ChatGenerationChunk, RUN_KEY } from "../outputs.js";
|
|
7
8
|
import { convertEventStreamToIterableReadableDataStream } from "../utils/event_source_parse.js";
|
|
8
|
-
import {
|
|
9
|
+
import { concat } from "../utils/stream.js";
|
|
9
10
|
function isSuperset(set, subset) {
|
|
10
11
|
for (const elem of subset) {
|
|
11
12
|
if (!set.has(elem)) {
|
|
@@ -258,7 +259,7 @@ export class RemoteRunnable extends Runnable {
|
|
|
258
259
|
signal: AbortSignal.timeout(this.options?.timeout ?? 60000),
|
|
259
260
|
});
|
|
260
261
|
}
|
|
261
|
-
async
|
|
262
|
+
async _invoke(input, options, _) {
|
|
262
263
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
263
264
|
const response = await this.post("/invoke", {
|
|
264
265
|
input,
|
|
@@ -270,6 +271,9 @@ export class RemoteRunnable extends Runnable {
|
|
|
270
271
|
}
|
|
271
272
|
return revive((await response.json()).output);
|
|
272
273
|
}
|
|
274
|
+
async invoke(input, options) {
|
|
275
|
+
return this._callWithConfig(this._invoke, input, options);
|
|
276
|
+
}
|
|
273
277
|
async _batch(inputs, options, _, batchOptions) {
|
|
274
278
|
if (batchOptions?.returnExceptions) {
|
|
275
279
|
throw new Error("returnExceptions is not supported for remote clients");
|
|
@@ -300,50 +304,60 @@ export class RemoteRunnable extends Runnable {
|
|
|
300
304
|
}
|
|
301
305
|
return this._batchWithConfig(this._batch.bind(this), inputs, options, batchOptions);
|
|
302
306
|
}
|
|
303
|
-
async
|
|
307
|
+
async *_streamIterator(input, options) {
|
|
304
308
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
305
|
-
const
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
309
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
310
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
311
|
+
let finalOutput;
|
|
312
|
+
let finalOutputSupported = true;
|
|
313
|
+
try {
|
|
314
|
+
const response = await this.post("/stream", {
|
|
315
|
+
input,
|
|
316
|
+
config: removeCallbacks(config),
|
|
317
|
+
kwargs,
|
|
318
|
+
});
|
|
319
|
+
if (!response.ok) {
|
|
320
|
+
const json = await response.json();
|
|
321
|
+
const error = new Error(`RemoteRunnable call failed with status code ${response.status}: ${json.message}`);
|
|
322
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
|
+
error.response = response;
|
|
324
|
+
throw error;
|
|
325
|
+
}
|
|
326
|
+
const { body } = response;
|
|
327
|
+
if (!body) {
|
|
328
|
+
throw new Error("Could not begin remote stream. Please check the given URL and try again.");
|
|
329
|
+
}
|
|
330
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
323
331
|
for await (const chunk of runnableStream) {
|
|
324
|
-
|
|
332
|
+
const deserializedChunk = deserialize(chunk);
|
|
333
|
+
yield deserializedChunk;
|
|
334
|
+
if (finalOutputSupported) {
|
|
335
|
+
if (finalOutput === undefined) {
|
|
336
|
+
finalOutput = deserializedChunk;
|
|
337
|
+
}
|
|
338
|
+
else {
|
|
339
|
+
try {
|
|
340
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
341
|
+
finalOutput = concat(finalOutput, deserializedChunk);
|
|
342
|
+
}
|
|
343
|
+
catch {
|
|
344
|
+
finalOutput = undefined;
|
|
345
|
+
finalOutputSupported = false;
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
325
349
|
}
|
|
326
350
|
}
|
|
327
|
-
|
|
351
|
+
catch (err) {
|
|
352
|
+
await runManager?.handleChainError(err);
|
|
353
|
+
throw err;
|
|
354
|
+
}
|
|
355
|
+
await runManager?.handleChainEnd(finalOutput ?? {});
|
|
328
356
|
}
|
|
329
357
|
async *streamLog(input, options, streamOptions) {
|
|
330
358
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
331
|
-
const
|
|
332
|
-
|
|
333
|
-
autoClose: false,
|
|
334
|
-
});
|
|
335
|
-
const { callbacks } = config;
|
|
336
|
-
if (callbacks === undefined) {
|
|
337
|
-
config.callbacks = [stream];
|
|
338
|
-
}
|
|
339
|
-
else if (Array.isArray(callbacks)) {
|
|
340
|
-
config.callbacks = callbacks.concat([stream]);
|
|
341
|
-
}
|
|
342
|
-
else {
|
|
343
|
-
const copiedCallbacks = callbacks.copy();
|
|
344
|
-
copiedCallbacks.inheritableHandlers.push(stream);
|
|
345
|
-
config.callbacks = copiedCallbacks;
|
|
346
|
-
}
|
|
359
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
360
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
347
361
|
// The type is in camelCase but the API only accepts snake_case.
|
|
348
362
|
const camelCaseStreamOptions = {
|
|
349
363
|
include_names: streamOptions?.includeNames,
|
|
@@ -353,31 +367,48 @@ export class RemoteRunnable extends Runnable {
|
|
|
353
367
|
exclude_types: streamOptions?.excludeTypes,
|
|
354
368
|
exclude_tags: streamOptions?.excludeTags,
|
|
355
369
|
};
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
370
|
+
let runLog;
|
|
371
|
+
try {
|
|
372
|
+
const response = await this.post("/stream_log", {
|
|
373
|
+
input,
|
|
374
|
+
config: removeCallbacks(config),
|
|
375
|
+
kwargs,
|
|
376
|
+
...camelCaseStreamOptions,
|
|
377
|
+
diff: false,
|
|
378
|
+
});
|
|
379
|
+
const { body, ok } = response;
|
|
380
|
+
if (!ok) {
|
|
381
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
382
|
+
}
|
|
383
|
+
if (!body) {
|
|
384
|
+
throw new Error("Could not begin remote stream log. Please check the given URL and try again.");
|
|
385
|
+
}
|
|
386
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
387
|
+
for await (const log of runnableStream) {
|
|
388
|
+
const chunk = revive(JSON.parse(log));
|
|
389
|
+
const logPatch = new RunLogPatch({ ops: chunk.ops });
|
|
390
|
+
yield logPatch;
|
|
391
|
+
if (runLog === undefined) {
|
|
392
|
+
runLog = RunLog.fromRunLogPatch(logPatch);
|
|
393
|
+
}
|
|
394
|
+
else {
|
|
395
|
+
runLog = runLog.concat(logPatch);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
369
398
|
}
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
yield new RunLogPatch({ ops: chunk.ops });
|
|
399
|
+
catch (err) {
|
|
400
|
+
await runManager?.handleChainError(err);
|
|
401
|
+
throw err;
|
|
374
402
|
}
|
|
403
|
+
await runManager?.handleChainEnd(runLog?.state.final_output);
|
|
375
404
|
}
|
|
376
405
|
async *streamEvents(input, options, streamOptions) {
|
|
377
406
|
if (options?.version !== "v1") {
|
|
378
407
|
throw new Error(`Only version "v1" of the events schema is currently supported.`);
|
|
379
408
|
}
|
|
380
409
|
const [config, kwargs] = this._separateRunnableConfigFromCallOptions(options);
|
|
410
|
+
const callbackManager_ = await getCallbackManagerForConfig(options);
|
|
411
|
+
const runManager = await callbackManager_?.handleChainStart(this.toJSON(), _coerceToDict(input, "input"), undefined, undefined, undefined, undefined, options?.runName);
|
|
381
412
|
// The type is in camelCase but the API only accepts snake_case.
|
|
382
413
|
const camelCaseStreamOptions = {
|
|
383
414
|
include_names: streamOptions?.includeNames,
|
|
@@ -387,31 +418,41 @@ export class RemoteRunnable extends Runnable {
|
|
|
387
418
|
exclude_types: streamOptions?.excludeTypes,
|
|
388
419
|
exclude_tags: streamOptions?.excludeTags,
|
|
389
420
|
};
|
|
390
|
-
const
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
421
|
+
const events = [];
|
|
422
|
+
try {
|
|
423
|
+
const response = await this.post("/stream_events", {
|
|
424
|
+
input,
|
|
425
|
+
config: removeCallbacks(config),
|
|
426
|
+
kwargs,
|
|
427
|
+
...camelCaseStreamOptions,
|
|
428
|
+
diff: false,
|
|
429
|
+
});
|
|
430
|
+
const { body, ok } = response;
|
|
431
|
+
if (!ok) {
|
|
432
|
+
throw new Error(`${response.status} Error: ${await response.text()}`);
|
|
433
|
+
}
|
|
434
|
+
if (!body) {
|
|
435
|
+
throw new Error("Could not begin remote stream events. Please check the given URL and try again.");
|
|
436
|
+
}
|
|
437
|
+
const runnableStream = convertEventStreamToIterableReadableDataStream(body);
|
|
438
|
+
for await (const log of runnableStream) {
|
|
439
|
+
const chunk = revive(JSON.parse(log));
|
|
440
|
+
const event = {
|
|
441
|
+
event: chunk.event,
|
|
442
|
+
name: chunk.name,
|
|
443
|
+
run_id: chunk.run_id,
|
|
444
|
+
tags: chunk.tags,
|
|
445
|
+
metadata: chunk.metadata,
|
|
446
|
+
data: chunk.data,
|
|
447
|
+
};
|
|
448
|
+
yield event;
|
|
449
|
+
events.push(event);
|
|
450
|
+
}
|
|
403
451
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
yield {
|
|
408
|
-
event: chunk.event,
|
|
409
|
-
name: chunk.name,
|
|
410
|
-
run_id: chunk.run_id,
|
|
411
|
-
tags: chunk.tags,
|
|
412
|
-
metadata: chunk.metadata,
|
|
413
|
-
data: chunk.data,
|
|
414
|
-
};
|
|
452
|
+
catch (err) {
|
|
453
|
+
await runManager?.handleChainError(err);
|
|
454
|
+
throw err;
|
|
415
455
|
}
|
|
456
|
+
await runManager?.handleChainEnd(events);
|
|
416
457
|
}
|
|
417
458
|
}
|
package/dist/tools.cjs
CHANGED
|
@@ -69,7 +69,8 @@ class StructuredTool extends base_js_1.BaseLangChain {
|
|
|
69
69
|
}
|
|
70
70
|
const config = (0, manager_js_1.parseCallbackConfigArg)(configArg);
|
|
71
71
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
|
72
|
-
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed),
|
|
72
|
+
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed), config.runId, undefined, undefined, undefined, config.runName);
|
|
73
|
+
delete config.runId;
|
|
73
74
|
let result;
|
|
74
75
|
try {
|
|
75
76
|
result = await this._call(parsed, runManager, config);
|
package/dist/tools.js
CHANGED
|
@@ -65,7 +65,8 @@ export class StructuredTool extends BaseLangChain {
|
|
|
65
65
|
}
|
|
66
66
|
const config = parseCallbackConfigArg(configArg);
|
|
67
67
|
const callbackManager_ = await CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
|
68
|
-
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed),
|
|
68
|
+
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed), config.runId, undefined, undefined, undefined, config.runName);
|
|
69
|
+
delete config.runId;
|
|
69
70
|
let result;
|
|
70
71
|
try {
|
|
71
72
|
result = await this._call(parsed, runManager, config);
|
package/dist/tracers/base.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { KVMap, BaseRun } from "langsmith/schemas";
|
|
2
|
-
import type { ChainValues } from "../utils/types.js";
|
|
2
|
+
import type { ChainValues } from "../utils/types/index.js";
|
|
3
3
|
import type { AgentAction, AgentFinish } from "../agents.js";
|
|
4
4
|
import type { LLMResult } from "../outputs.js";
|
|
5
5
|
import type { BaseMessage } from "../messages/index.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.SyntheticEmbeddings = exports.FakeEmbeddings = exports.FakeTool = exports.FakeTracer = exports.FakeListChatMessageHistory = exports.FakeChatMessageHistory = exports.FakeListChatModel = exports.FakeRetriever = exports.FakeChatModel = exports.FakeStreamingLLM = exports.FakeLLM = exports.FakeRunnable = exports.FakeSplitIntoListParser = void 0;
|
|
3
|
+
exports.SingleRunExtractor = exports.SyntheticEmbeddings = exports.FakeEmbeddings = exports.FakeTool = exports.FakeTracer = exports.FakeListChatMessageHistory = exports.FakeChatMessageHistory = exports.FakeListChatModel = exports.FakeRetriever = exports.FakeChatModel = exports.FakeStreamingLLM = exports.FakeLLM = exports.FakeRunnable = exports.FakeSplitIntoListParser = void 0;
|
|
4
4
|
const chat_history_js_1 = require("../../chat_history.cjs");
|
|
5
5
|
const document_js_1 = require("../../documents/document.cjs");
|
|
6
6
|
const chat_models_js_1 = require("../../language_models/chat_models.cjs");
|
|
@@ -8,7 +8,7 @@ const llms_js_1 = require("../../language_models/llms.cjs");
|
|
|
8
8
|
const index_js_1 = require("../../messages/index.cjs");
|
|
9
9
|
const base_js_1 = require("../../output_parsers/base.cjs");
|
|
10
10
|
const outputs_js_1 = require("../../outputs.cjs");
|
|
11
|
-
const
|
|
11
|
+
const index_js_2 = require("../../retrievers/index.cjs");
|
|
12
12
|
const base_js_2 = require("../../runnables/base.cjs");
|
|
13
13
|
const tools_js_1 = require("../../tools.cjs");
|
|
14
14
|
const base_js_3 = require("../../tracers/base.cjs");
|
|
@@ -172,7 +172,7 @@ class FakeChatModel extends chat_models_js_1.BaseChatModel {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
exports.FakeChatModel = FakeChatModel;
|
|
175
|
-
class FakeRetriever extends
|
|
175
|
+
class FakeRetriever extends index_js_2.BaseRetriever {
|
|
176
176
|
constructor(fields) {
|
|
177
177
|
super();
|
|
178
178
|
Object.defineProperty(this, "lc_namespace", {
|
|
@@ -518,3 +518,37 @@ class SyntheticEmbeddings extends embeddings_js_1.Embeddings {
|
|
|
518
518
|
}
|
|
519
519
|
}
|
|
520
520
|
exports.SyntheticEmbeddings = SyntheticEmbeddings;
|
|
521
|
+
class SingleRunExtractor extends base_js_3.BaseTracer {
|
|
522
|
+
constructor() {
|
|
523
|
+
super();
|
|
524
|
+
Object.defineProperty(this, "runPromiseResolver", {
|
|
525
|
+
enumerable: true,
|
|
526
|
+
configurable: true,
|
|
527
|
+
writable: true,
|
|
528
|
+
value: void 0
|
|
529
|
+
});
|
|
530
|
+
Object.defineProperty(this, "runPromise", {
|
|
531
|
+
enumerable: true,
|
|
532
|
+
configurable: true,
|
|
533
|
+
writable: true,
|
|
534
|
+
value: void 0
|
|
535
|
+
});
|
|
536
|
+
/** The name of the callback handler. */
|
|
537
|
+
Object.defineProperty(this, "name", {
|
|
538
|
+
enumerable: true,
|
|
539
|
+
configurable: true,
|
|
540
|
+
writable: true,
|
|
541
|
+
value: "single_run_extractor"
|
|
542
|
+
});
|
|
543
|
+
this.runPromise = new Promise((extract) => {
|
|
544
|
+
this.runPromiseResolver = extract;
|
|
545
|
+
});
|
|
546
|
+
}
|
|
547
|
+
async persistRun(run) {
|
|
548
|
+
this.runPromiseResolver(run);
|
|
549
|
+
}
|
|
550
|
+
async extract() {
|
|
551
|
+
return this.runPromise;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
exports.SingleRunExtractor = SingleRunExtractor;
|