langchain 0.0.188 → 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.
- package/dist/embeddings/cohere.cjs +9 -18
- package/dist/embeddings/cohere.d.ts +1 -13
- package/dist/embeddings/cohere.js +9 -18
- package/dist/llms/cohere.cjs +7 -9
- package/dist/llms/cohere.d.ts +1 -1
- package/dist/llms/cohere.js +7 -9
- package/dist/schema/runnable/passthrough.cjs +52 -1
- package/dist/schema/runnable/passthrough.d.ts +52 -1
- package/dist/schema/runnable/passthrough.js +52 -1
- package/package.json +3 -3
|
@@ -27,12 +27,6 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
27
27
|
writable: true,
|
|
28
28
|
value: 48
|
|
29
29
|
});
|
|
30
|
-
Object.defineProperty(this, "inputType", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
configurable: true,
|
|
33
|
-
writable: true,
|
|
34
|
-
value: void 0
|
|
35
|
-
});
|
|
36
30
|
Object.defineProperty(this, "apiKey", {
|
|
37
31
|
enumerable: true,
|
|
38
32
|
configurable: true,
|
|
@@ -51,7 +45,6 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
51
45
|
}
|
|
52
46
|
this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
|
|
53
47
|
this.batchSize = fieldsWithDefaults?.batchSize ?? this.batchSize;
|
|
54
|
-
this.inputType = fieldsWithDefaults?.inputType;
|
|
55
48
|
this.apiKey = apiKey;
|
|
56
49
|
}
|
|
57
50
|
/**
|
|
@@ -65,15 +58,14 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
65
58
|
const batchRequests = batches.map((batch) => this.embeddingWithRetry({
|
|
66
59
|
model: this.modelName,
|
|
67
60
|
texts: batch,
|
|
68
|
-
inputType: this.inputType,
|
|
69
61
|
}));
|
|
70
62
|
const batchResponses = await Promise.all(batchRequests);
|
|
71
63
|
const embeddings = [];
|
|
72
64
|
for (let i = 0; i < batchResponses.length; i += 1) {
|
|
73
65
|
const batch = batches[i];
|
|
74
|
-
const {
|
|
66
|
+
const { body: batchResponse } = batchResponses[i];
|
|
75
67
|
for (let j = 0; j < batch.length; j += 1) {
|
|
76
|
-
embeddings.push(batchResponse[j]);
|
|
68
|
+
embeddings.push(batchResponse.embeddings[j]);
|
|
77
69
|
}
|
|
78
70
|
}
|
|
79
71
|
return embeddings;
|
|
@@ -85,11 +77,11 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
85
77
|
*/
|
|
86
78
|
async embedQuery(text) {
|
|
87
79
|
await this.maybeInitClient();
|
|
88
|
-
const {
|
|
80
|
+
const { body } = await this.embeddingWithRetry({
|
|
89
81
|
model: this.modelName,
|
|
90
82
|
texts: [text],
|
|
91
83
|
});
|
|
92
|
-
return embeddings[0];
|
|
84
|
+
return body.embeddings[0];
|
|
93
85
|
}
|
|
94
86
|
/**
|
|
95
87
|
* Generates embeddings with retry capabilities.
|
|
@@ -105,17 +97,16 @@ class CohereEmbeddings extends base_js_1.Embeddings {
|
|
|
105
97
|
*/
|
|
106
98
|
async maybeInitClient() {
|
|
107
99
|
if (!this.client) {
|
|
108
|
-
const {
|
|
109
|
-
this.client =
|
|
110
|
-
|
|
111
|
-
});
|
|
100
|
+
const { cohere } = await CohereEmbeddings.imports();
|
|
101
|
+
this.client = cohere;
|
|
102
|
+
this.client.init(this.apiKey);
|
|
112
103
|
}
|
|
113
104
|
}
|
|
114
105
|
/** @ignore */
|
|
115
106
|
static async imports() {
|
|
116
107
|
try {
|
|
117
|
-
const {
|
|
118
|
-
return {
|
|
108
|
+
const { default: cohere } = await import("cohere-ai");
|
|
109
|
+
return { cohere };
|
|
119
110
|
}
|
|
120
111
|
catch (e) {
|
|
121
112
|
throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
|
|
@@ -10,17 +10,6 @@ export interface CohereEmbeddingsParams extends EmbeddingsParams {
|
|
|
10
10
|
* limited by the Cohere API to a maximum of 96.
|
|
11
11
|
*/
|
|
12
12
|
batchSize?: number;
|
|
13
|
-
/**
|
|
14
|
-
* Specifies the type of input you're giving to the model.
|
|
15
|
-
* Not required for older versions of the embedding models (i.e. anything lower than v3),
|
|
16
|
-
* but is required for more recent versions (i.e. anything bigger than v2).
|
|
17
|
-
*
|
|
18
|
-
* * `search_document` - Use this when you encode documents for embeddings that you store in a vector database for search use-cases.
|
|
19
|
-
* * `search_query` - Use this when you query your vector DB to find relevant documents.
|
|
20
|
-
* * `classification` - Use this when you use the embeddings as an input to a text classifier.
|
|
21
|
-
* * `clustering` - Use this when you want to cluster the embeddings.
|
|
22
|
-
*/
|
|
23
|
-
inputType?: string;
|
|
24
13
|
}
|
|
25
14
|
/**
|
|
26
15
|
* A class for generating embeddings using the Cohere API.
|
|
@@ -28,7 +17,6 @@ export interface CohereEmbeddingsParams extends EmbeddingsParams {
|
|
|
28
17
|
export declare class CohereEmbeddings extends Embeddings implements CohereEmbeddingsParams {
|
|
29
18
|
modelName: string;
|
|
30
19
|
batchSize: number;
|
|
31
|
-
inputType: string | undefined;
|
|
32
20
|
private apiKey;
|
|
33
21
|
private client;
|
|
34
22
|
/**
|
|
@@ -63,6 +51,6 @@ export declare class CohereEmbeddings extends Embeddings implements CohereEmbedd
|
|
|
63
51
|
private maybeInitClient;
|
|
64
52
|
/** @ignore */
|
|
65
53
|
static imports(): Promise<{
|
|
66
|
-
|
|
54
|
+
cohere: typeof import("cohere-ai");
|
|
67
55
|
}>;
|
|
68
56
|
}
|
|
@@ -24,12 +24,6 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
24
24
|
writable: true,
|
|
25
25
|
value: 48
|
|
26
26
|
});
|
|
27
|
-
Object.defineProperty(this, "inputType", {
|
|
28
|
-
enumerable: true,
|
|
29
|
-
configurable: true,
|
|
30
|
-
writable: true,
|
|
31
|
-
value: void 0
|
|
32
|
-
});
|
|
33
27
|
Object.defineProperty(this, "apiKey", {
|
|
34
28
|
enumerable: true,
|
|
35
29
|
configurable: true,
|
|
@@ -48,7 +42,6 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
48
42
|
}
|
|
49
43
|
this.modelName = fieldsWithDefaults?.modelName ?? this.modelName;
|
|
50
44
|
this.batchSize = fieldsWithDefaults?.batchSize ?? this.batchSize;
|
|
51
|
-
this.inputType = fieldsWithDefaults?.inputType;
|
|
52
45
|
this.apiKey = apiKey;
|
|
53
46
|
}
|
|
54
47
|
/**
|
|
@@ -62,15 +55,14 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
62
55
|
const batchRequests = batches.map((batch) => this.embeddingWithRetry({
|
|
63
56
|
model: this.modelName,
|
|
64
57
|
texts: batch,
|
|
65
|
-
inputType: this.inputType,
|
|
66
58
|
}));
|
|
67
59
|
const batchResponses = await Promise.all(batchRequests);
|
|
68
60
|
const embeddings = [];
|
|
69
61
|
for (let i = 0; i < batchResponses.length; i += 1) {
|
|
70
62
|
const batch = batches[i];
|
|
71
|
-
const {
|
|
63
|
+
const { body: batchResponse } = batchResponses[i];
|
|
72
64
|
for (let j = 0; j < batch.length; j += 1) {
|
|
73
|
-
embeddings.push(batchResponse[j]);
|
|
65
|
+
embeddings.push(batchResponse.embeddings[j]);
|
|
74
66
|
}
|
|
75
67
|
}
|
|
76
68
|
return embeddings;
|
|
@@ -82,11 +74,11 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
82
74
|
*/
|
|
83
75
|
async embedQuery(text) {
|
|
84
76
|
await this.maybeInitClient();
|
|
85
|
-
const {
|
|
77
|
+
const { body } = await this.embeddingWithRetry({
|
|
86
78
|
model: this.modelName,
|
|
87
79
|
texts: [text],
|
|
88
80
|
});
|
|
89
|
-
return embeddings[0];
|
|
81
|
+
return body.embeddings[0];
|
|
90
82
|
}
|
|
91
83
|
/**
|
|
92
84
|
* Generates embeddings with retry capabilities.
|
|
@@ -102,17 +94,16 @@ export class CohereEmbeddings extends Embeddings {
|
|
|
102
94
|
*/
|
|
103
95
|
async maybeInitClient() {
|
|
104
96
|
if (!this.client) {
|
|
105
|
-
const {
|
|
106
|
-
this.client =
|
|
107
|
-
|
|
108
|
-
});
|
|
97
|
+
const { cohere } = await CohereEmbeddings.imports();
|
|
98
|
+
this.client = cohere;
|
|
99
|
+
this.client.init(this.apiKey);
|
|
109
100
|
}
|
|
110
101
|
}
|
|
111
102
|
/** @ignore */
|
|
112
103
|
static async imports() {
|
|
113
104
|
try {
|
|
114
|
-
const {
|
|
115
|
-
return {
|
|
105
|
+
const { default: cohere } = await import("cohere-ai");
|
|
106
|
+
return { cohere };
|
|
116
107
|
}
|
|
117
108
|
catch (e) {
|
|
118
109
|
throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
|
package/dist/llms/cohere.cjs
CHANGED
|
@@ -67,20 +67,18 @@ class Cohere extends base_js_1.LLM {
|
|
|
67
67
|
}
|
|
68
68
|
/** @ignore */
|
|
69
69
|
async _call(prompt, options) {
|
|
70
|
-
const {
|
|
71
|
-
|
|
72
|
-
token: this.apiKey,
|
|
73
|
-
});
|
|
70
|
+
const { cohere } = await Cohere.imports();
|
|
71
|
+
cohere.init(this.apiKey);
|
|
74
72
|
// Hit the `generate` endpoint on the `large` model
|
|
75
73
|
const generateResponse = await this.caller.callWithOptions({ signal: options.signal }, cohere.generate.bind(cohere), {
|
|
76
74
|
prompt,
|
|
77
75
|
model: this.model,
|
|
78
|
-
|
|
76
|
+
max_tokens: this.maxTokens,
|
|
79
77
|
temperature: this.temperature,
|
|
80
|
-
|
|
78
|
+
end_sequences: options.stop,
|
|
81
79
|
});
|
|
82
80
|
try {
|
|
83
|
-
return generateResponse.generations[0].text;
|
|
81
|
+
return generateResponse.body.generations[0].text;
|
|
84
82
|
}
|
|
85
83
|
catch {
|
|
86
84
|
console.log(generateResponse);
|
|
@@ -90,8 +88,8 @@ class Cohere extends base_js_1.LLM {
|
|
|
90
88
|
/** @ignore */
|
|
91
89
|
static async imports() {
|
|
92
90
|
try {
|
|
93
|
-
const {
|
|
94
|
-
return {
|
|
91
|
+
const { default: cohere } = await import("cohere-ai");
|
|
92
|
+
return { cohere };
|
|
95
93
|
}
|
|
96
94
|
catch (e) {
|
|
97
95
|
throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
|
package/dist/llms/cohere.d.ts
CHANGED
|
@@ -36,6 +36,6 @@ export declare class Cohere extends LLM implements CohereInput {
|
|
|
36
36
|
_call(prompt: string, options: this["ParsedCallOptions"]): Promise<string>;
|
|
37
37
|
/** @ignore */
|
|
38
38
|
static imports(): Promise<{
|
|
39
|
-
|
|
39
|
+
cohere: typeof import("cohere-ai");
|
|
40
40
|
}>;
|
|
41
41
|
}
|
package/dist/llms/cohere.js
CHANGED
|
@@ -64,20 +64,18 @@ export class Cohere extends LLM {
|
|
|
64
64
|
}
|
|
65
65
|
/** @ignore */
|
|
66
66
|
async _call(prompt, options) {
|
|
67
|
-
const {
|
|
68
|
-
|
|
69
|
-
token: this.apiKey,
|
|
70
|
-
});
|
|
67
|
+
const { cohere } = await Cohere.imports();
|
|
68
|
+
cohere.init(this.apiKey);
|
|
71
69
|
// Hit the `generate` endpoint on the `large` model
|
|
72
70
|
const generateResponse = await this.caller.callWithOptions({ signal: options.signal }, cohere.generate.bind(cohere), {
|
|
73
71
|
prompt,
|
|
74
72
|
model: this.model,
|
|
75
|
-
|
|
73
|
+
max_tokens: this.maxTokens,
|
|
76
74
|
temperature: this.temperature,
|
|
77
|
-
|
|
75
|
+
end_sequences: options.stop,
|
|
78
76
|
});
|
|
79
77
|
try {
|
|
80
|
-
return generateResponse.generations[0].text;
|
|
78
|
+
return generateResponse.body.generations[0].text;
|
|
81
79
|
}
|
|
82
80
|
catch {
|
|
83
81
|
console.log(generateResponse);
|
|
@@ -87,8 +85,8 @@ export class Cohere extends LLM {
|
|
|
87
85
|
/** @ignore */
|
|
88
86
|
static async imports() {
|
|
89
87
|
try {
|
|
90
|
-
const {
|
|
91
|
-
return {
|
|
88
|
+
const { default: cohere } = await import("cohere-ai");
|
|
89
|
+
return { cohere };
|
|
92
90
|
}
|
|
93
91
|
catch (e) {
|
|
94
92
|
throw new Error("Please install cohere-ai as a dependency with, e.g. `yarn add cohere-ai`");
|
|
@@ -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) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.190",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -902,7 +902,7 @@
|
|
|
902
902
|
"closevector-common": "0.1.0-alpha.1",
|
|
903
903
|
"closevector-node": "0.1.0-alpha.10",
|
|
904
904
|
"closevector-web": "0.1.0-alpha.15",
|
|
905
|
-
"cohere-ai": "
|
|
905
|
+
"cohere-ai": ">=6.0.0",
|
|
906
906
|
"convex": "^1.3.1",
|
|
907
907
|
"d3-dsv": "^2.0.0",
|
|
908
908
|
"dotenv": "^16.0.3",
|
|
@@ -1020,7 +1020,7 @@
|
|
|
1020
1020
|
"closevector-common": "0.1.0-alpha.1",
|
|
1021
1021
|
"closevector-node": "0.1.0-alpha.10",
|
|
1022
1022
|
"closevector-web": "0.1.0-alpha.16",
|
|
1023
|
-
"cohere-ai": "
|
|
1023
|
+
"cohere-ai": ">=6.0.0",
|
|
1024
1024
|
"convex": "^1.3.1",
|
|
1025
1025
|
"d3-dsv": "^2.0.0",
|
|
1026
1026
|
"epub2": "^3.0.1",
|