langchain 0.0.189 → 0.0.190
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.
|
@@ -32,7 +32,30 @@ class RunnableAssign extends base_js_1.Runnable {
|
|
|
32
32
|
}
|
|
33
33
|
exports.RunnableAssign = RunnableAssign;
|
|
34
34
|
/**
|
|
35
|
-
* A runnable
|
|
35
|
+
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
36
|
+
*
|
|
37
|
+
* This runnable behaves almost like the identity function, except that it
|
|
38
|
+
* can be configured to add additional keys to the output, if the input is
|
|
39
|
+
* an object.
|
|
40
|
+
*
|
|
41
|
+
* The example below demonstrates how to use `RunnablePassthrough to
|
|
42
|
+
* passthrough the input from the `.invoke()`
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```typescript
|
|
46
|
+
* const chain = RunnableSequence.from([
|
|
47
|
+
* {
|
|
48
|
+
* question: new RunnablePassthrough(),
|
|
49
|
+
* context: async () => loadContextFromStore(),
|
|
50
|
+
* },
|
|
51
|
+
* prompt,
|
|
52
|
+
* llm,
|
|
53
|
+
* outputParser,
|
|
54
|
+
* ]);
|
|
55
|
+
* const response = await chain.invoke(
|
|
56
|
+
* "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
|
|
57
|
+
* );
|
|
58
|
+
* ```
|
|
36
59
|
*/
|
|
37
60
|
class RunnablePassthrough extends base_js_1.Runnable {
|
|
38
61
|
constructor() {
|
|
@@ -56,6 +79,34 @@ class RunnablePassthrough extends base_js_1.Runnable {
|
|
|
56
79
|
async invoke(input, options) {
|
|
57
80
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
58
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* A runnable that assigns key-value pairs to the input.
|
|
84
|
+
*
|
|
85
|
+
* The example below shows how you could use it with an inline function.
|
|
86
|
+
*
|
|
87
|
+
* @example
|
|
88
|
+
* ```typescript
|
|
89
|
+
* const prompt =
|
|
90
|
+
* PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
|
|
91
|
+
* Question: {question}
|
|
92
|
+
* SQL Query:`);
|
|
93
|
+
*
|
|
94
|
+
* // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
|
|
95
|
+
* // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
|
|
96
|
+
* // In this case, we're passing the schema.
|
|
97
|
+
* const sqlQueryGeneratorChain = RunnableSequence.from([
|
|
98
|
+
* RunnablePassthrough.assign({
|
|
99
|
+
* schema: async () => db.getTableInfo(),
|
|
100
|
+
* }),
|
|
101
|
+
* prompt,
|
|
102
|
+
* new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
|
|
103
|
+
* new StringOutputParser(),
|
|
104
|
+
* ]);
|
|
105
|
+
* const result = await sqlQueryGeneratorChain.invoke({
|
|
106
|
+
* question: "How many employees are there?",
|
|
107
|
+
* });
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
59
110
|
static assign(
|
|
60
111
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
61
112
|
mapping) {
|
|
@@ -10,12 +10,63 @@ export declare class RunnableAssign<RunInput extends Record<string, any> = any,
|
|
|
10
10
|
invoke(input: RunInput, options?: Partial<CallOptions>): Promise<RunOutput>;
|
|
11
11
|
}
|
|
12
12
|
/**
|
|
13
|
-
* A runnable
|
|
13
|
+
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
14
|
+
*
|
|
15
|
+
* This runnable behaves almost like the identity function, except that it
|
|
16
|
+
* can be configured to add additional keys to the output, if the input is
|
|
17
|
+
* an object.
|
|
18
|
+
*
|
|
19
|
+
* The example below demonstrates how to use `RunnablePassthrough to
|
|
20
|
+
* passthrough the input from the `.invoke()`
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const chain = RunnableSequence.from([
|
|
25
|
+
* {
|
|
26
|
+
* question: new RunnablePassthrough(),
|
|
27
|
+
* context: async () => loadContextFromStore(),
|
|
28
|
+
* },
|
|
29
|
+
* prompt,
|
|
30
|
+
* llm,
|
|
31
|
+
* outputParser,
|
|
32
|
+
* ]);
|
|
33
|
+
* const response = await chain.invoke(
|
|
34
|
+
* "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
|
|
35
|
+
* );
|
|
36
|
+
* ```
|
|
14
37
|
*/
|
|
15
38
|
export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, RunInput> {
|
|
16
39
|
static lc_name(): string;
|
|
17
40
|
lc_namespace: string[];
|
|
18
41
|
lc_serializable: boolean;
|
|
19
42
|
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
|
|
43
|
+
/**
|
|
44
|
+
* A runnable that assigns key-value pairs to the input.
|
|
45
|
+
*
|
|
46
|
+
* The example below shows how you could use it with an inline function.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const prompt =
|
|
51
|
+
* PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
|
|
52
|
+
* Question: {question}
|
|
53
|
+
* SQL Query:`);
|
|
54
|
+
*
|
|
55
|
+
* // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
|
|
56
|
+
* // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
|
|
57
|
+
* // In this case, we're passing the schema.
|
|
58
|
+
* const sqlQueryGeneratorChain = RunnableSequence.from([
|
|
59
|
+
* RunnablePassthrough.assign({
|
|
60
|
+
* schema: async () => db.getTableInfo(),
|
|
61
|
+
* }),
|
|
62
|
+
* prompt,
|
|
63
|
+
* new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
|
|
64
|
+
* new StringOutputParser(),
|
|
65
|
+
* ]);
|
|
66
|
+
* const result = await sqlQueryGeneratorChain.invoke({
|
|
67
|
+
* question: "How many employees are there?",
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
20
71
|
static assign(mapping: Record<string, RunnableLike<Record<string, unknown>, any>>): RunnableAssign<Record<string, unknown>, Record<string, unknown>>;
|
|
21
72
|
}
|
|
@@ -28,7 +28,30 @@ export class RunnableAssign extends Runnable {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
/**
|
|
31
|
-
* A runnable
|
|
31
|
+
* A runnable to passthrough inputs unchanged or with additional keys.
|
|
32
|
+
*
|
|
33
|
+
* This runnable behaves almost like the identity function, except that it
|
|
34
|
+
* can be configured to add additional keys to the output, if the input is
|
|
35
|
+
* an object.
|
|
36
|
+
*
|
|
37
|
+
* The example below demonstrates how to use `RunnablePassthrough to
|
|
38
|
+
* passthrough the input from the `.invoke()`
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* const chain = RunnableSequence.from([
|
|
43
|
+
* {
|
|
44
|
+
* question: new RunnablePassthrough(),
|
|
45
|
+
* context: async () => loadContextFromStore(),
|
|
46
|
+
* },
|
|
47
|
+
* prompt,
|
|
48
|
+
* llm,
|
|
49
|
+
* outputParser,
|
|
50
|
+
* ]);
|
|
51
|
+
* const response = await chain.invoke(
|
|
52
|
+
* "I can pass a single string instead of an object since I'm using `RunnablePassthrough`."
|
|
53
|
+
* );
|
|
54
|
+
* ```
|
|
32
55
|
*/
|
|
33
56
|
export class RunnablePassthrough extends Runnable {
|
|
34
57
|
constructor() {
|
|
@@ -52,6 +75,34 @@ export class RunnablePassthrough extends Runnable {
|
|
|
52
75
|
async invoke(input, options) {
|
|
53
76
|
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
54
77
|
}
|
|
78
|
+
/**
|
|
79
|
+
* A runnable that assigns key-value pairs to the input.
|
|
80
|
+
*
|
|
81
|
+
* The example below shows how you could use it with an inline function.
|
|
82
|
+
*
|
|
83
|
+
* @example
|
|
84
|
+
* ```typescript
|
|
85
|
+
* const prompt =
|
|
86
|
+
* PromptTemplate.fromTemplate(`Write a SQL query to answer the question using the following schema: {schema}
|
|
87
|
+
* Question: {question}
|
|
88
|
+
* SQL Query:`);
|
|
89
|
+
*
|
|
90
|
+
* // The `RunnablePassthrough.assign()` is used here to passthrough the input from the `.invoke()`
|
|
91
|
+
* // call (in this example it's the question), along with any inputs passed to the `.assign()` method.
|
|
92
|
+
* // In this case, we're passing the schema.
|
|
93
|
+
* const sqlQueryGeneratorChain = RunnableSequence.from([
|
|
94
|
+
* RunnablePassthrough.assign({
|
|
95
|
+
* schema: async () => db.getTableInfo(),
|
|
96
|
+
* }),
|
|
97
|
+
* prompt,
|
|
98
|
+
* new ChatOpenAI({}).bind({ stop: ["\nSQLResult:"] }),
|
|
99
|
+
* new StringOutputParser(),
|
|
100
|
+
* ]);
|
|
101
|
+
* const result = await sqlQueryGeneratorChain.invoke({
|
|
102
|
+
* question: "How many employees are there?",
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
55
106
|
static assign(
|
|
56
107
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
108
|
mapping) {
|