@langchain/core 0.3.56 → 0.3.57
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/prompts/structured.cjs +7 -9
- package/dist/prompts/structured.js +7 -9
- package/dist/runnables/base.cjs +24 -7
- package/dist/runnables/base.d.ts +24 -4
- package/dist/runnables/base.js +24 -7
- package/dist/runnables/passthrough.cjs +1 -1
- package/dist/runnables/passthrough.d.ts +1 -1
- package/dist/runnables/passthrough.js +1 -1
- package/dist/tools/index.cjs +1 -1
- package/dist/tools/index.js +1 -1
- package/dist/utils/testing/index.cjs +1 -1
- package/dist/utils/testing/index.js +1 -1
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.StructuredPrompt = void 0;
|
|
4
|
+
const base_js_1 = require("../runnables/base.cjs");
|
|
4
5
|
const chat_js_1 = require("./chat.cjs");
|
|
5
6
|
function isWithStructuredOutput(x
|
|
6
7
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -54,15 +55,12 @@ class StructuredPrompt extends chat_js_1.ChatPromptTemplate {
|
|
|
54
55
|
}
|
|
55
56
|
if (isRunnableBinding(coerceable) &&
|
|
56
57
|
isWithStructuredOutput(coerceable.bound)) {
|
|
57
|
-
return super.pipe(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
.withStructuredOutput(this.schema)
|
|
64
|
-
.bind(coerceable.kwargs ?? {})
|
|
65
|
-
.withConfig(coerceable.config));
|
|
58
|
+
return super.pipe(new base_js_1.RunnableBinding({
|
|
59
|
+
bound: coerceable.bound.withStructuredOutput(this.schema, ...(this.method ? [{ method: this.method }] : [])),
|
|
60
|
+
kwargs: coerceable.kwargs ?? {},
|
|
61
|
+
config: coerceable.config,
|
|
62
|
+
configFactories: coerceable.configFactories,
|
|
63
|
+
}));
|
|
66
64
|
}
|
|
67
65
|
throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
|
|
68
66
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RunnableBinding } from "../runnables/base.js";
|
|
1
2
|
import { ChatPromptTemplate, } from "./chat.js";
|
|
2
3
|
function isWithStructuredOutput(x
|
|
3
4
|
// eslint-disable-next-line @typescript-eslint/ban-types
|
|
@@ -51,15 +52,12 @@ export class StructuredPrompt extends ChatPromptTemplate {
|
|
|
51
52
|
}
|
|
52
53
|
if (isRunnableBinding(coerceable) &&
|
|
53
54
|
isWithStructuredOutput(coerceable.bound)) {
|
|
54
|
-
return super.pipe(
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
.withStructuredOutput(this.schema)
|
|
61
|
-
.bind(coerceable.kwargs ?? {})
|
|
62
|
-
.withConfig(coerceable.config));
|
|
55
|
+
return super.pipe(new RunnableBinding({
|
|
56
|
+
bound: coerceable.bound.withStructuredOutput(this.schema, ...(this.method ? [{ method: this.method }] : [])),
|
|
57
|
+
kwargs: coerceable.kwargs ?? {},
|
|
58
|
+
config: coerceable.config,
|
|
59
|
+
configFactories: coerceable.configFactories,
|
|
60
|
+
}));
|
|
63
61
|
}
|
|
64
62
|
throw new Error(`Structured prompts need to be piped to a language model that supports the "withStructuredOutput()" method.`);
|
|
65
63
|
}
|
package/dist/runnables/base.cjs
CHANGED
|
@@ -63,6 +63,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
63
63
|
* Bind arguments to a Runnable, returning a new Runnable.
|
|
64
64
|
* @param kwargs
|
|
65
65
|
* @returns A new RunnableBinding that, when invoked, will apply the bound args.
|
|
66
|
+
*
|
|
67
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
66
68
|
*/
|
|
67
69
|
bind(kwargs) {
|
|
68
70
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -71,6 +73,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
71
73
|
/**
|
|
72
74
|
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
73
75
|
* by calling invoke() with each input.
|
|
76
|
+
*
|
|
77
|
+
* @deprecated This will be removed in the next breaking release.
|
|
74
78
|
*/
|
|
75
79
|
map() {
|
|
76
80
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -78,7 +82,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
78
82
|
}
|
|
79
83
|
/**
|
|
80
84
|
* Add retry logic to an existing runnable.
|
|
81
|
-
* @param
|
|
85
|
+
* @param fields.stopAfterAttempt The number of attempts to retry.
|
|
86
|
+
* @param fields.onFailedAttempt A function that is called when a retry fails.
|
|
82
87
|
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
83
88
|
*/
|
|
84
89
|
withRetry(fields) {
|
|
@@ -774,7 +779,8 @@ class Runnable extends serializable_js_1.Serializable {
|
|
|
774
779
|
}
|
|
775
780
|
exports.Runnable = Runnable;
|
|
776
781
|
/**
|
|
777
|
-
*
|
|
782
|
+
* Wraps a runnable and applies partial config upon invocation.
|
|
783
|
+
*
|
|
778
784
|
* @example
|
|
779
785
|
* ```typescript
|
|
780
786
|
* import {
|
|
@@ -869,8 +875,14 @@ class RunnableBinding extends Runnable {
|
|
|
869
875
|
? await Promise.all(this.configFactories.map(async (configFactory) => await configFactory(config)))
|
|
870
876
|
: []));
|
|
871
877
|
}
|
|
878
|
+
/**
|
|
879
|
+
* Binds the runnable with the specified arguments.
|
|
880
|
+
* @param kwargs The arguments to bind the runnable with.
|
|
881
|
+
* @returns A new instance of the `RunnableBinding` class that is bound with the specified arguments.
|
|
882
|
+
*
|
|
883
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
884
|
+
*/
|
|
872
885
|
bind(kwargs) {
|
|
873
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
874
886
|
return new this.constructor({
|
|
875
887
|
bound: this.bound,
|
|
876
888
|
kwargs: { ...this.kwargs, ...kwargs },
|
|
@@ -878,7 +890,6 @@ class RunnableBinding extends Runnable {
|
|
|
878
890
|
});
|
|
879
891
|
}
|
|
880
892
|
withConfig(config) {
|
|
881
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
882
893
|
return new this.constructor({
|
|
883
894
|
bound: this.bound,
|
|
884
895
|
kwargs: this.kwargs,
|
|
@@ -886,11 +897,13 @@ class RunnableBinding extends Runnable {
|
|
|
886
897
|
});
|
|
887
898
|
}
|
|
888
899
|
withRetry(fields) {
|
|
889
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
890
|
-
return new
|
|
891
|
-
bound: this.bound
|
|
900
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
901
|
+
return new RunnableRetry({
|
|
902
|
+
bound: this.bound,
|
|
892
903
|
kwargs: this.kwargs,
|
|
893
904
|
config: this.config,
|
|
905
|
+
maxAttemptNumber: fields?.stopAfterAttempt,
|
|
906
|
+
...fields,
|
|
894
907
|
});
|
|
895
908
|
}
|
|
896
909
|
async invoke(input, options) {
|
|
@@ -982,6 +995,8 @@ exports.RunnableBinding = RunnableBinding;
|
|
|
982
995
|
*
|
|
983
996
|
* // ["Hello, ALICE!", "Hello, BOB!", "Hello, CAROL!"]
|
|
984
997
|
* ```
|
|
998
|
+
*
|
|
999
|
+
* @deprecated This will be removed in the next breaking release.
|
|
985
1000
|
*/
|
|
986
1001
|
class RunnableEach extends Runnable {
|
|
987
1002
|
static lc_name() {
|
|
@@ -1013,6 +1028,8 @@ class RunnableEach extends Runnable {
|
|
|
1013
1028
|
* Binds the runnable with the specified arguments.
|
|
1014
1029
|
* @param kwargs The arguments to bind the runnable with.
|
|
1015
1030
|
* @returns A new instance of the `RunnableEach` class that is bound with the specified arguments.
|
|
1031
|
+
*
|
|
1032
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
1016
1033
|
*/
|
|
1017
1034
|
bind(kwargs) {
|
|
1018
1035
|
return new RunnableEach({
|
package/dist/runnables/base.d.ts
CHANGED
|
@@ -30,16 +30,21 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
30
30
|
* Bind arguments to a Runnable, returning a new Runnable.
|
|
31
31
|
* @param kwargs
|
|
32
32
|
* @returns A new RunnableBinding that, when invoked, will apply the bound args.
|
|
33
|
+
*
|
|
34
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
33
35
|
*/
|
|
34
36
|
bind(kwargs: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
|
|
35
37
|
/**
|
|
36
38
|
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
37
39
|
* by calling invoke() with each input.
|
|
40
|
+
*
|
|
41
|
+
* @deprecated This will be removed in the next breaking release.
|
|
38
42
|
*/
|
|
39
43
|
map(): Runnable<RunInput[], RunOutput[], CallOptions>;
|
|
40
44
|
/**
|
|
41
45
|
* Add retry logic to an existing runnable.
|
|
42
|
-
* @param
|
|
46
|
+
* @param fields.stopAfterAttempt The number of attempts to retry.
|
|
47
|
+
* @param fields.onFailedAttempt A function that is called when a retry fails.
|
|
43
48
|
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
44
49
|
*/
|
|
45
50
|
withRetry(fields?: {
|
|
@@ -310,12 +315,16 @@ export declare abstract class Runnable<RunInput = any, RunOutput = any, CallOpti
|
|
|
310
315
|
}
|
|
311
316
|
export type RunnableBindingArgs<RunInput, RunOutput, CallOptions extends RunnableConfig = RunnableConfig> = {
|
|
312
317
|
bound: Runnable<RunInput, RunOutput, CallOptions>;
|
|
318
|
+
/**
|
|
319
|
+
* @deprecated use {@link config} instead
|
|
320
|
+
*/
|
|
313
321
|
kwargs?: Partial<CallOptions>;
|
|
314
322
|
config: RunnableConfig;
|
|
315
|
-
configFactories?: Array<(config: RunnableConfig) => RunnableConfig
|
|
323
|
+
configFactories?: Array<(config: RunnableConfig) => RunnableConfig | Promise<RunnableConfig>>;
|
|
316
324
|
};
|
|
317
325
|
/**
|
|
318
|
-
*
|
|
326
|
+
* Wraps a runnable and applies partial config upon invocation.
|
|
327
|
+
*
|
|
319
328
|
* @example
|
|
320
329
|
* ```typescript
|
|
321
330
|
* import {
|
|
@@ -365,8 +374,15 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
|
|
|
365
374
|
constructor(fields: RunnableBindingArgs<RunInput, RunOutput, CallOptions>);
|
|
366
375
|
getName(suffix?: string | undefined): string;
|
|
367
376
|
_mergeConfig(...options: (Partial<CallOptions> | RunnableConfig | undefined)[]): Promise<Partial<CallOptions>>;
|
|
377
|
+
/**
|
|
378
|
+
* Binds the runnable with the specified arguments.
|
|
379
|
+
* @param kwargs The arguments to bind the runnable with.
|
|
380
|
+
* @returns A new instance of the `RunnableBinding` class that is bound with the specified arguments.
|
|
381
|
+
*
|
|
382
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
383
|
+
*/
|
|
368
384
|
bind(kwargs: Partial<CallOptions>): RunnableBinding<RunInput, RunOutput, CallOptions>;
|
|
369
|
-
withConfig(config:
|
|
385
|
+
withConfig(config: Partial<CallOptions>): Runnable<RunInput, RunOutput, CallOptions>;
|
|
370
386
|
withRetry(fields?: {
|
|
371
387
|
stopAfterAttempt?: number;
|
|
372
388
|
onFailedAttempt?: RunnableRetryFailedAttemptHandler;
|
|
@@ -428,6 +444,8 @@ export declare class RunnableBinding<RunInput, RunOutput, CallOptions extends Ru
|
|
|
428
444
|
*
|
|
429
445
|
* // ["Hello, ALICE!", "Hello, BOB!", "Hello, CAROL!"]
|
|
430
446
|
* ```
|
|
447
|
+
*
|
|
448
|
+
* @deprecated This will be removed in the next breaking release.
|
|
431
449
|
*/
|
|
432
450
|
export declare class RunnableEach<RunInputItem, RunOutputItem, CallOptions extends RunnableConfig> extends Runnable<RunInputItem[], RunOutputItem[], CallOptions> {
|
|
433
451
|
static lc_name(): string;
|
|
@@ -441,6 +459,8 @@ export declare class RunnableEach<RunInputItem, RunOutputItem, CallOptions exten
|
|
|
441
459
|
* Binds the runnable with the specified arguments.
|
|
442
460
|
* @param kwargs The arguments to bind the runnable with.
|
|
443
461
|
* @returns A new instance of the `RunnableEach` class that is bound with the specified arguments.
|
|
462
|
+
*
|
|
463
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
444
464
|
*/
|
|
445
465
|
bind(kwargs: Partial<CallOptions>): RunnableEach<RunInputItem, RunOutputItem, CallOptions>;
|
|
446
466
|
/**
|
package/dist/runnables/base.js
CHANGED
|
@@ -56,6 +56,8 @@ export class Runnable extends Serializable {
|
|
|
56
56
|
* Bind arguments to a Runnable, returning a new Runnable.
|
|
57
57
|
* @param kwargs
|
|
58
58
|
* @returns A new RunnableBinding that, when invoked, will apply the bound args.
|
|
59
|
+
*
|
|
60
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
59
61
|
*/
|
|
60
62
|
bind(kwargs) {
|
|
61
63
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -64,6 +66,8 @@ export class Runnable extends Serializable {
|
|
|
64
66
|
/**
|
|
65
67
|
* Return a new Runnable that maps a list of inputs to a list of outputs,
|
|
66
68
|
* by calling invoke() with each input.
|
|
69
|
+
*
|
|
70
|
+
* @deprecated This will be removed in the next breaking release.
|
|
67
71
|
*/
|
|
68
72
|
map() {
|
|
69
73
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
@@ -71,7 +75,8 @@ export class Runnable extends Serializable {
|
|
|
71
75
|
}
|
|
72
76
|
/**
|
|
73
77
|
* Add retry logic to an existing runnable.
|
|
74
|
-
* @param
|
|
78
|
+
* @param fields.stopAfterAttempt The number of attempts to retry.
|
|
79
|
+
* @param fields.onFailedAttempt A function that is called when a retry fails.
|
|
75
80
|
* @returns A new RunnableRetry that, when invoked, will retry according to the parameters.
|
|
76
81
|
*/
|
|
77
82
|
withRetry(fields) {
|
|
@@ -766,7 +771,8 @@ export class Runnable extends Serializable {
|
|
|
766
771
|
}
|
|
767
772
|
}
|
|
768
773
|
/**
|
|
769
|
-
*
|
|
774
|
+
* Wraps a runnable and applies partial config upon invocation.
|
|
775
|
+
*
|
|
770
776
|
* @example
|
|
771
777
|
* ```typescript
|
|
772
778
|
* import {
|
|
@@ -861,8 +867,14 @@ export class RunnableBinding extends Runnable {
|
|
|
861
867
|
? await Promise.all(this.configFactories.map(async (configFactory) => await configFactory(config)))
|
|
862
868
|
: []));
|
|
863
869
|
}
|
|
870
|
+
/**
|
|
871
|
+
* Binds the runnable with the specified arguments.
|
|
872
|
+
* @param kwargs The arguments to bind the runnable with.
|
|
873
|
+
* @returns A new instance of the `RunnableBinding` class that is bound with the specified arguments.
|
|
874
|
+
*
|
|
875
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
876
|
+
*/
|
|
864
877
|
bind(kwargs) {
|
|
865
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
866
878
|
return new this.constructor({
|
|
867
879
|
bound: this.bound,
|
|
868
880
|
kwargs: { ...this.kwargs, ...kwargs },
|
|
@@ -870,7 +882,6 @@ export class RunnableBinding extends Runnable {
|
|
|
870
882
|
});
|
|
871
883
|
}
|
|
872
884
|
withConfig(config) {
|
|
873
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
874
885
|
return new this.constructor({
|
|
875
886
|
bound: this.bound,
|
|
876
887
|
kwargs: this.kwargs,
|
|
@@ -878,11 +889,13 @@ export class RunnableBinding extends Runnable {
|
|
|
878
889
|
});
|
|
879
890
|
}
|
|
880
891
|
withRetry(fields) {
|
|
881
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
882
|
-
return new
|
|
883
|
-
bound: this.bound
|
|
892
|
+
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
893
|
+
return new RunnableRetry({
|
|
894
|
+
bound: this.bound,
|
|
884
895
|
kwargs: this.kwargs,
|
|
885
896
|
config: this.config,
|
|
897
|
+
maxAttemptNumber: fields?.stopAfterAttempt,
|
|
898
|
+
...fields,
|
|
886
899
|
});
|
|
887
900
|
}
|
|
888
901
|
async invoke(input, options) {
|
|
@@ -973,6 +986,8 @@ export class RunnableBinding extends Runnable {
|
|
|
973
986
|
*
|
|
974
987
|
* // ["Hello, ALICE!", "Hello, BOB!", "Hello, CAROL!"]
|
|
975
988
|
* ```
|
|
989
|
+
*
|
|
990
|
+
* @deprecated This will be removed in the next breaking release.
|
|
976
991
|
*/
|
|
977
992
|
export class RunnableEach extends Runnable {
|
|
978
993
|
static lc_name() {
|
|
@@ -1004,6 +1019,8 @@ export class RunnableEach extends Runnable {
|
|
|
1004
1019
|
* Binds the runnable with the specified arguments.
|
|
1005
1020
|
* @param kwargs The arguments to bind the runnable with.
|
|
1006
1021
|
* @returns A new instance of the `RunnableEach` class that is bound with the specified arguments.
|
|
1022
|
+
*
|
|
1023
|
+
* @deprecated Use {@link withConfig} instead. This will be removed in the next breaking release.
|
|
1007
1024
|
*/
|
|
1008
1025
|
bind(kwargs) {
|
|
1009
1026
|
return new RunnableEach({
|
|
@@ -112,7 +112,7 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
112
112
|
* schema: async () => db.getTableInfo(),
|
|
113
113
|
* }),
|
|
114
114
|
* prompt,
|
|
115
|
-
* new ChatOpenAI({}).
|
|
115
|
+
* new ChatOpenAI({}).withConfig({ stop: ["\nSQLResult:"] }),
|
|
116
116
|
* new StringOutputParser(),
|
|
117
117
|
* ]);
|
|
118
118
|
* const result = await sqlQueryGeneratorChain.invoke({
|
|
@@ -57,7 +57,7 @@ export declare class RunnablePassthrough<RunInput = any> extends Runnable<RunInp
|
|
|
57
57
|
* schema: async () => db.getTableInfo(),
|
|
58
58
|
* }),
|
|
59
59
|
* prompt,
|
|
60
|
-
* new ChatOpenAI({}).
|
|
60
|
+
* new ChatOpenAI({}).withConfig({ stop: ["\nSQLResult:"] }),
|
|
61
61
|
* new StringOutputParser(),
|
|
62
62
|
* ]);
|
|
63
63
|
* const result = await sqlQueryGeneratorChain.invoke({
|
|
@@ -109,7 +109,7 @@ export class RunnablePassthrough extends Runnable {
|
|
|
109
109
|
* schema: async () => db.getTableInfo(),
|
|
110
110
|
* }),
|
|
111
111
|
* prompt,
|
|
112
|
-
* new ChatOpenAI({}).
|
|
112
|
+
* new ChatOpenAI({}).withConfig({ stop: ["\nSQLResult:"] }),
|
|
113
113
|
* new StringOutputParser(),
|
|
114
114
|
* ]);
|
|
115
115
|
* const result = await sqlQueryGeneratorChain.invoke({
|
package/dist/tools/index.cjs
CHANGED
package/dist/tools/index.js
CHANGED
|
@@ -283,7 +283,7 @@ class FakeStreamingChatModel extends chat_models_js_1.BaseChatModel {
|
|
|
283
283
|
thrownErrorString: this.thrownErrorString,
|
|
284
284
|
});
|
|
285
285
|
next.tools = merged;
|
|
286
|
-
return next.
|
|
286
|
+
return next.withConfig({ tools: wrapped });
|
|
287
287
|
}
|
|
288
288
|
async _generate(messages, _options, _runManager) {
|
|
289
289
|
if (this.thrownErrorString) {
|
|
@@ -275,7 +275,7 @@ export class FakeStreamingChatModel extends BaseChatModel {
|
|
|
275
275
|
thrownErrorString: this.thrownErrorString,
|
|
276
276
|
});
|
|
277
277
|
next.tools = merged;
|
|
278
|
-
return next.
|
|
278
|
+
return next.withConfig({ tools: wrapped });
|
|
279
279
|
}
|
|
280
280
|
async _generate(messages, _options, _runManager) {
|
|
281
281
|
if (this.thrownErrorString) {
|