@langchain/core 0.1.4 → 0.1.6
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/README.md +1 -1
- package/dist/callbacks/manager.d.ts +0 -5
- package/dist/chat_history.d.ts +1 -0
- package/dist/language_models/base.d.ts +2 -0
- package/dist/output_parsers/index.cjs +1 -0
- package/dist/output_parsers/index.d.ts +1 -0
- package/dist/output_parsers/index.js +1 -0
- package/dist/output_parsers/json.cjs +137 -0
- package/dist/output_parsers/json.d.ts +17 -0
- package/dist/output_parsers/json.js +131 -0
- package/dist/output_parsers/list.cjs +121 -2
- package/dist/output_parsers/list.d.ts +21 -2
- package/dist/output_parsers/list.js +119 -2
- package/dist/prompt_values.cjs +3 -0
- package/dist/prompt_values.d.ts +1 -0
- package/dist/prompt_values.js +3 -0
- package/dist/prompts/chat.cjs +22 -2
- package/dist/prompts/chat.d.ts +4 -2
- package/dist/prompts/chat.js +22 -2
- package/dist/runnables/base.cjs +290 -31
- package/dist/runnables/base.d.ts +72 -20
- package/dist/runnables/base.js +289 -32
- package/dist/runnables/config.cjs +7 -3
- package/dist/runnables/config.d.ts +13 -2
- package/dist/runnables/config.js +5 -1
- package/dist/runnables/history.cjs +3 -3
- package/dist/runnables/history.d.ts +5 -6
- package/dist/runnables/history.js +3 -3
- package/dist/runnables/index.cjs +5 -2
- package/dist/runnables/index.d.ts +3 -3
- package/dist/runnables/index.js +3 -2
- package/dist/runnables/passthrough.cjs +5 -31
- package/dist/runnables/passthrough.d.ts +3 -11
- package/dist/runnables/passthrough.js +4 -29
- package/dist/utils/stream.cjs +113 -1
- package/dist/utils/stream.d.ts +13 -0
- package/dist/utils/stream.js +109 -0
- package/dist/utils/testing/index.cjs +14 -1
- package/dist/utils/testing/index.d.ts +5 -0
- package/dist/utils/testing/index.js +14 -1
- package/package.json +1 -1
package/dist/runnables/base.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CallbackManager, CallbackManagerForChainRun
|
|
1
|
+
import { CallbackManager, CallbackManagerForChainRun } from "../callbacks/manager.js";
|
|
2
2
|
import { LogStreamCallbackHandlerInput, RunLogPatch } from "../tracers/log_stream.js";
|
|
3
3
|
import { Serializable } from "../load/serializable.js";
|
|
4
4
|
import { IterableReadableStream, type IterableReadableStreamInterface } from "../utils/stream.js";
|
|
@@ -20,7 +20,6 @@ export interface RunnableInterface<RunInput = any, RunOutput = any, CallOptions
|
|
|
20
20
|
returnExceptions: true;
|
|
21
21
|
}): Promise<(RunOutput | Error)[]>;
|
|
22
22
|
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
23
|
-
batch(inputs: RunInput[], options?: Partial<CallOptions> | Partial<CallOptions>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
24
23
|
stream(input: RunInput, options?: Partial<CallOptions>): Promise<IterableReadableStreamInterface<RunOutput>>;
|
|
25
24
|
transform(generator: AsyncGenerator<RunInput>, options: Partial<CallOptions>): AsyncGenerator<RunOutput>;
|
|
26
25
|
}
|
|
@@ -44,6 +43,8 @@ export type RunnableRetryFailedAttemptHandler = (error: any) => any;
|
|
|
44
43
|
*/
|
|
45
44
|
export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOptions extends RunnableConfig = RunnableConfig> extends Serializable implements RunnableInterface<RunInput, RunOutput, CallOptions> {
|
|
46
45
|
protected lc_runnable: boolean;
|
|
46
|
+
name?: string;
|
|
47
|
+
getName(suffix?: string): string;
|
|
47
48
|
abstract invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
48
49
|
/**
|
|
49
50
|
* Bind arguments to a Runnable, returning a new Runnable.
|
|
@@ -136,10 +137,10 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
136
137
|
* Output values, with callbacks.
|
|
137
138
|
* Use this to implement `stream()` or `transform()` in Runnable subclasses.
|
|
138
139
|
*/
|
|
139
|
-
protected _transformStreamWithConfig<I extends RunInput, O extends RunOutput>(inputGenerator: AsyncGenerator<I>, transformer: (generator: AsyncGenerator<I>, runManager?: CallbackManagerForChainRun
|
|
140
|
+
protected _transformStreamWithConfig<I extends RunInput, O extends RunOutput>(inputGenerator: AsyncGenerator<I>, transformer: (generator: AsyncGenerator<I>, runManager?: Promise<CallbackManagerForChainRun | undefined>, options?: Partial<CallOptions>) => AsyncGenerator<O>, options?: CallOptions & {
|
|
140
141
|
runType?: string;
|
|
141
142
|
}): AsyncGenerator<O>;
|
|
142
|
-
_patchConfig(config?: Partial<CallOptions>, callbackManager?: CallbackManager | undefined): Partial<CallOptions>;
|
|
143
|
+
_patchConfig(config?: Partial<CallOptions>, callbackManager?: CallbackManager | undefined, recursionLimit?: number | undefined): Partial<CallOptions>;
|
|
143
144
|
/**
|
|
144
145
|
* Create a new runnable sequence that runs each individual runnable in series,
|
|
145
146
|
* piping the output of one runnable into another runnable or runnable-like.
|
|
@@ -147,6 +148,14 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
147
148
|
* @returns A new runnable sequence.
|
|
148
149
|
*/
|
|
149
150
|
pipe<NewRunOutput>(coerceable: RunnableLike<RunOutput, NewRunOutput>): RunnableSequence<RunInput, Exclude<NewRunOutput, Error>>;
|
|
151
|
+
/**
|
|
152
|
+
* Pick keys from the dict output of this runnable. Returns a new runnable.
|
|
153
|
+
*/
|
|
154
|
+
pick(keys: string | string[]): RunnableSequence;
|
|
155
|
+
/**
|
|
156
|
+
* Assigns new fields to the dict output of this runnable. Returns a new runnable.
|
|
157
|
+
*/
|
|
158
|
+
assign(mapping: RunnableMapLike<Record<string, unknown>, Record<string, unknown>>): RunnableSequence;
|
|
150
159
|
/**
|
|
151
160
|
* Default implementation of transform, which buffers input and then calls stream.
|
|
152
161
|
* Subclasses should override this method if they can start producing output while
|
|
@@ -185,7 +194,7 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
185
194
|
onError?: (run: Run, config?: RunnableConfig) => void | Promise<void>;
|
|
186
195
|
}): Runnable<RunInput, RunOutput, CallOptions>;
|
|
187
196
|
}
|
|
188
|
-
export type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig> = {
|
|
197
|
+
export type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = {
|
|
189
198
|
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
190
199
|
kwargs?: Partial<CallOptions>;
|
|
191
200
|
config: RunnableConfig;
|
|
@@ -194,7 +203,7 @@ export type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends Runnabl
|
|
|
194
203
|
/**
|
|
195
204
|
* A runnable that delegates calls to another runnable with a set of kwargs.
|
|
196
205
|
*/
|
|
197
|
-
export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
206
|
+
export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput, CallOptions> {
|
|
198
207
|
static lc_name(): string;
|
|
199
208
|
lc_namespace: string[];
|
|
200
209
|
lc_serializable: boolean;
|
|
@@ -203,6 +212,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
|
|
|
203
212
|
protected kwargs?: Partial<CallOptions>;
|
|
204
213
|
configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
|
|
205
214
|
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
|
|
215
|
+
getName(suffix?: string | undefined): string;
|
|
206
216
|
_mergeConfig(options?: Record<string, any>): Promise<Partial<CallOptions>>;
|
|
207
217
|
bind(kwargs: Partial<CallOptions>): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
208
218
|
withConfig(config: RunnableConfig): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
@@ -243,7 +253,7 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
|
|
|
243
253
|
* A runnable that delegates calls to another runnable
|
|
244
254
|
* with each element of the input sequence.
|
|
245
255
|
*/
|
|
246
|
-
export declare class RunnableEach<RunInputItem, RunOutputItem, CallOptions extends
|
|
256
|
+
export declare class RunnableEach<RunInputItem, RunOutputItem, CallOptions extends RunnableConfig> extends Runnable<RunInputItem[], RunOutputItem[], CallOptions> {
|
|
247
257
|
static lc_name(): string;
|
|
248
258
|
lc_serializable: boolean;
|
|
249
259
|
lc_namespace: string[];
|
|
@@ -345,8 +355,9 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
|
|
|
345
355
|
first: Runnable<RunInput>;
|
|
346
356
|
middle?: Runnable[];
|
|
347
357
|
last: Runnable<any, RunOutput>;
|
|
358
|
+
name?: string;
|
|
348
359
|
});
|
|
349
|
-
get steps(): Runnable<RunInput, any,
|
|
360
|
+
get steps(): Runnable<RunInput, any, RunnableConfig>[];
|
|
350
361
|
invoke(input: RunInput, options?: RunnableConfig): Promise<RunOutput>;
|
|
351
362
|
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
352
363
|
returnExceptions?: false;
|
|
@@ -362,7 +373,7 @@ export declare class RunnableSequence<RunInput = any, RunOutput = any> extends R
|
|
|
362
373
|
RunnableLike<RunInput>,
|
|
363
374
|
...RunnableLike[],
|
|
364
375
|
RunnableLike<any, RunOutput>
|
|
365
|
-
]): RunnableSequence<RunInput, Exclude<RunOutput, Error>>;
|
|
376
|
+
], name?: string): RunnableSequence<RunInput, Exclude<RunOutput, Error>>;
|
|
366
377
|
}
|
|
367
378
|
/**
|
|
368
379
|
* A runnable that runs a mapping of runnables in parallel,
|
|
@@ -390,7 +401,10 @@ export declare class RunnableMap<RunInput = any, RunOutput extends Record<string
|
|
|
390
401
|
steps: RunnableMapLike<RunInput, RunOutput>;
|
|
391
402
|
});
|
|
392
403
|
static from<RunInput, RunOutput extends Record<string, any> = Record<string, any>>(steps: RunnableMapLike<RunInput, RunOutput>): RunnableMap<RunInput, RunOutput>;
|
|
393
|
-
invoke(input: RunInput, options?: Partial<
|
|
404
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
405
|
+
_transform(generator: AsyncGenerator<RunInput>, runManagerPromise?: Promise<CallbackManagerForChainRun | undefined>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
406
|
+
transform(generator: AsyncGenerator<RunInput>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
407
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
394
408
|
}
|
|
395
409
|
/**
|
|
396
410
|
* A runnable that runs a callable.
|
|
@@ -398,13 +412,16 @@ export declare class RunnableMap<RunInput = any, RunOutput extends Record<string
|
|
|
398
412
|
export declare class RunnableLambda<RunInput, RunOutput> extends Runnable<RunInput, RunOutput> {
|
|
399
413
|
static lc_name(): string;
|
|
400
414
|
lc_namespace: string[];
|
|
401
|
-
protected func: RunnableFunc<RunInput, RunOutput
|
|
415
|
+
protected func: RunnableFunc<RunInput, RunOutput | Runnable<RunInput, RunOutput>>;
|
|
402
416
|
constructor(fields: {
|
|
403
|
-
func: RunnableFunc<RunInput, RunOutput
|
|
417
|
+
func: RunnableFunc<RunInput, RunOutput | Runnable<RunInput, RunOutput>>;
|
|
404
418
|
});
|
|
405
|
-
static from<RunInput, RunOutput>(func: RunnableFunc<RunInput, RunOutput
|
|
406
|
-
_invoke(input: RunInput, config?: Partial<
|
|
407
|
-
invoke(input: RunInput, options?: Partial<
|
|
419
|
+
static from<RunInput, RunOutput>(func: RunnableFunc<RunInput, RunOutput | Runnable<RunInput, RunOutput>>): RunnableLambda<RunInput, RunOutput>;
|
|
420
|
+
_invoke(input: RunInput, config?: Partial<RunnableConfig>, runManager?: CallbackManagerForChainRun): Promise<RunOutput>;
|
|
421
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
422
|
+
_transform(generator: AsyncGenerator<RunInput>, runManagerPromise?: Promise<CallbackManagerForChainRun | undefined>, config?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
423
|
+
transform(generator: AsyncGenerator<RunInput>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
424
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
408
425
|
}
|
|
409
426
|
export declare class RunnableParallel<RunInput> extends RunnableMap<RunInput> {
|
|
410
427
|
}
|
|
@@ -421,14 +438,49 @@ export declare class RunnableWithFallbacks<RunInput, RunOutput> extends Runnable
|
|
|
421
438
|
runnable: Runnable<RunInput, RunOutput>;
|
|
422
439
|
fallbacks: Runnable<RunInput, RunOutput>[];
|
|
423
440
|
});
|
|
424
|
-
runnables(): Generator<Runnable<RunInput, RunOutput,
|
|
425
|
-
invoke(input: RunInput, options?: Partial<
|
|
426
|
-
batch(inputs: RunInput[], options?: Partial<
|
|
441
|
+
runnables(): Generator<Runnable<RunInput, RunOutput, RunnableConfig>, void, unknown>;
|
|
442
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
443
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
427
444
|
returnExceptions?: false;
|
|
428
445
|
}): Promise<RunOutput[]>;
|
|
429
|
-
batch(inputs: RunInput[], options?: Partial<
|
|
446
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
430
447
|
returnExceptions: true;
|
|
431
448
|
}): Promise<(RunOutput | Error)[]>;
|
|
432
|
-
batch(inputs: RunInput[], options?: Partial<
|
|
449
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
433
450
|
}
|
|
434
451
|
export declare function _coerceToRunnable<RunInput, RunOutput>(coerceable: RunnableLike<RunInput, RunOutput>): Runnable<RunInput, Exclude<RunOutput, Error>>;
|
|
452
|
+
export interface RunnableAssignFields<RunInput> {
|
|
453
|
+
mapper: RunnableMap<RunInput>;
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
|
|
457
|
+
*/
|
|
458
|
+
export declare class RunnableAssign<RunInput extends Record<string, any> = Record<string, any>, RunOutput extends Record<string, any> = Record<string, any>, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput> implements RunnableAssignFields<RunInput> {
|
|
459
|
+
static lc_name(): string;
|
|
460
|
+
lc_namespace: string[];
|
|
461
|
+
lc_serializable: boolean;
|
|
462
|
+
mapper: RunnableMap<RunInput>;
|
|
463
|
+
constructor(fields: RunnableMap<RunInput> | RunnableAssignFields<RunInput>);
|
|
464
|
+
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
465
|
+
_transform(generator: AsyncGenerator<RunInput>, runManagerPromise?: Promise<CallbackManagerForChainRun | undefined>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
466
|
+
transform(generator: AsyncGenerator<RunInput>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
467
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
468
|
+
}
|
|
469
|
+
export interface RunnablePickFields {
|
|
470
|
+
keys: string | string[];
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* A runnable that assigns key-value pairs to inputs of type `Record<string, unknown>`.
|
|
474
|
+
*/
|
|
475
|
+
export declare class RunnablePick<RunInput extends Record<string, any> = Record<string, any>, RunOutput extends Record<string, any> | any = Record<string, any> | any, CallOptions extends RunnableConfig = RunnableConfig> extends Runnable<RunInput, RunOutput> implements RunnablePickFields {
|
|
476
|
+
static lc_name(): string;
|
|
477
|
+
lc_namespace: string[];
|
|
478
|
+
lc_serializable: boolean;
|
|
479
|
+
keys: string | string[];
|
|
480
|
+
constructor(fields: string | string[] | RunnablePickFields);
|
|
481
|
+
_pick(input: RunInput): Promise<RunOutput>;
|
|
482
|
+
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
483
|
+
_transform(generator: AsyncGenerator<RunInput>): AsyncGenerator<RunOutput>;
|
|
484
|
+
transform(generator: AsyncGenerator<RunInput>, options?: Partial<RunnableConfig>): AsyncGenerator<RunOutput>;
|
|
485
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
486
|
+
}
|