langchain 0.0.148 → 0.0.150
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/chains/question_answering/load.cjs +12 -4
- package/dist/chains/question_answering/load.d.ts +2 -0
- package/dist/chains/question_answering/load.js +12 -4
- package/dist/chains/summarization/load.cjs +8 -4
- package/dist/chains/summarization/load.d.ts +2 -0
- package/dist/chains/summarization/load.js +8 -4
- package/dist/llms/bedrock.cjs +9 -1
- package/dist/llms/bedrock.d.ts +3 -0
- package/dist/llms/bedrock.js +9 -1
- package/dist/llms/replicate.cjs +28 -2
- package/dist/llms/replicate.d.ts +3 -0
- package/dist/llms/replicate.js +28 -2
- package/dist/prompts/prompt.cjs +2 -0
- package/dist/prompts/prompt.d.ts +1 -1
- package/dist/prompts/prompt.js +2 -0
- package/dist/retrievers/self_query/base.cjs +1 -1
- package/dist/retrievers/self_query/base.js +2 -2
- package/dist/retrievers/self_query/functional.cjs +1 -1
- package/dist/retrievers/self_query/functional.js +2 -2
- package/dist/retrievers/self_query/utils.cjs +46 -6
- package/dist/retrievers/self_query/utils.d.ts +7 -0
- package/dist/retrievers/self_query/utils.js +44 -5
- package/dist/schema/runnable/base.cjs +911 -0
- package/dist/schema/runnable/base.d.ts +300 -0
- package/dist/schema/runnable/base.js +897 -0
- package/dist/schema/runnable/index.cjs +19 -926
- package/dist/schema/runnable/index.d.ts +4 -298
- package/dist/schema/runnable/index.js +3 -914
- package/dist/schema/runnable/passthrough.cjs +31 -0
- package/dist/schema/runnable/passthrough.d.ts +11 -0
- package/dist/schema/runnable/passthrough.js +27 -0
- package/dist/schema/runnable/router.cjs +74 -0
- package/dist/schema/runnable/router.d.ts +29 -0
- package/dist/schema/runnable/router.js +70 -0
- package/dist/vectorstores/opensearch.cjs +4 -2
- package/dist/vectorstores/opensearch.d.ts +4 -1
- package/dist/vectorstores/opensearch.js +4 -2
- package/package.json +3 -3
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunnablePassthrough = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* A runnable that passes through the input.
|
|
7
|
+
*/
|
|
8
|
+
class RunnablePassthrough extends base_js_1.Runnable {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ["langchain", "schema", "runnable"]
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static lc_name() {
|
|
25
|
+
return "RunnablePassthrough";
|
|
26
|
+
}
|
|
27
|
+
async invoke(input, options) {
|
|
28
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.RunnablePassthrough = RunnablePassthrough;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
import type { RunnableConfig } from "./config.js";
|
|
3
|
+
/**
|
|
4
|
+
* A runnable that passes through the input.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, RunInput> {
|
|
7
|
+
static lc_name(): string;
|
|
8
|
+
lc_namespace: string[];
|
|
9
|
+
lc_serializable: boolean;
|
|
10
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A runnable that passes through the input.
|
|
4
|
+
*/
|
|
5
|
+
export class RunnablePassthrough extends Runnable {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: ["langchain", "schema", "runnable"]
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static lc_name() {
|
|
22
|
+
return "RunnablePassthrough";
|
|
23
|
+
}
|
|
24
|
+
async invoke(input, options) {
|
|
25
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterRunnable = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
7
|
+
* Returns the output of the selected runnable.
|
|
8
|
+
*/
|
|
9
|
+
class RouterRunnable extends base_js_1.Runnable {
|
|
10
|
+
static lc_name() {
|
|
11
|
+
return "RouterRunnable";
|
|
12
|
+
}
|
|
13
|
+
constructor(fields) {
|
|
14
|
+
super(fields);
|
|
15
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: ["langchain", "schema", "runnable"]
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: true
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "runnables", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
this.runnables = fields.runnables;
|
|
34
|
+
}
|
|
35
|
+
async invoke(input, options) {
|
|
36
|
+
const { key, input: actualInput } = input;
|
|
37
|
+
const runnable = this.runnables[key];
|
|
38
|
+
if (runnable === undefined) {
|
|
39
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
40
|
+
}
|
|
41
|
+
return runnable.invoke(actualInput, options);
|
|
42
|
+
}
|
|
43
|
+
async batch(inputs, options, batchOptions) {
|
|
44
|
+
const keys = inputs.map((input) => input.key);
|
|
45
|
+
const actualInputs = inputs.map((input) => input.input);
|
|
46
|
+
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
47
|
+
if (missingKey !== undefined) {
|
|
48
|
+
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
49
|
+
}
|
|
50
|
+
const runnables = keys.map((key) => this.runnables[key]);
|
|
51
|
+
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
52
|
+
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
53
|
+
? batchOptions?.maxConcurrency
|
|
54
|
+
: inputs.length;
|
|
55
|
+
const batchResults = [];
|
|
56
|
+
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
57
|
+
const batchPromises = actualInputs
|
|
58
|
+
.slice(i, i + batchSize)
|
|
59
|
+
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
60
|
+
const batchResult = await Promise.all(batchPromises);
|
|
61
|
+
batchResults.push(batchResult);
|
|
62
|
+
}
|
|
63
|
+
return batchResults.flat();
|
|
64
|
+
}
|
|
65
|
+
async stream(input, options) {
|
|
66
|
+
const { key, input: actualInput } = input;
|
|
67
|
+
const runnable = this.runnables[key];
|
|
68
|
+
if (runnable === undefined) {
|
|
69
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
70
|
+
}
|
|
71
|
+
return runnable.stream(actualInput, options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.RouterRunnable = RouterRunnable;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Runnable, type RunnableBatchOptions } from "./base.js";
|
|
2
|
+
import { IterableReadableStream } from "../../util/stream.js";
|
|
3
|
+
import type { RunnableConfig } from "./config.js";
|
|
4
|
+
export type RouterInput = {
|
|
5
|
+
key: string;
|
|
6
|
+
input: any;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
10
|
+
* Returns the output of the selected runnable.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RouterRunnable<RunInput extends RouterInput, RunnableInput, RunOutput> extends Runnable<RunInput, RunOutput> {
|
|
13
|
+
static lc_name(): string;
|
|
14
|
+
lc_namespace: string[];
|
|
15
|
+
lc_serializable: boolean;
|
|
16
|
+
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
17
|
+
constructor(fields: {
|
|
18
|
+
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
19
|
+
});
|
|
20
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
21
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
22
|
+
returnExceptions?: false;
|
|
23
|
+
}): Promise<RunOutput[]>;
|
|
24
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
25
|
+
returnExceptions: true;
|
|
26
|
+
}): Promise<(RunOutput | Error)[]>;
|
|
27
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
28
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
4
|
+
* Returns the output of the selected runnable.
|
|
5
|
+
*/
|
|
6
|
+
export class RouterRunnable extends Runnable {
|
|
7
|
+
static lc_name() {
|
|
8
|
+
return "RouterRunnable";
|
|
9
|
+
}
|
|
10
|
+
constructor(fields) {
|
|
11
|
+
super(fields);
|
|
12
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ["langchain", "schema", "runnable"]
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "runnables", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
this.runnables = fields.runnables;
|
|
31
|
+
}
|
|
32
|
+
async invoke(input, options) {
|
|
33
|
+
const { key, input: actualInput } = input;
|
|
34
|
+
const runnable = this.runnables[key];
|
|
35
|
+
if (runnable === undefined) {
|
|
36
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
37
|
+
}
|
|
38
|
+
return runnable.invoke(actualInput, options);
|
|
39
|
+
}
|
|
40
|
+
async batch(inputs, options, batchOptions) {
|
|
41
|
+
const keys = inputs.map((input) => input.key);
|
|
42
|
+
const actualInputs = inputs.map((input) => input.input);
|
|
43
|
+
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
44
|
+
if (missingKey !== undefined) {
|
|
45
|
+
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
46
|
+
}
|
|
47
|
+
const runnables = keys.map((key) => this.runnables[key]);
|
|
48
|
+
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
49
|
+
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
50
|
+
? batchOptions?.maxConcurrency
|
|
51
|
+
: inputs.length;
|
|
52
|
+
const batchResults = [];
|
|
53
|
+
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
54
|
+
const batchPromises = actualInputs
|
|
55
|
+
.slice(i, i + batchSize)
|
|
56
|
+
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
57
|
+
const batchResult = await Promise.all(batchPromises);
|
|
58
|
+
batchResults.push(batchResult);
|
|
59
|
+
}
|
|
60
|
+
return batchResults.flat();
|
|
61
|
+
}
|
|
62
|
+
async stream(input, options) {
|
|
63
|
+
const { key, input: actualInput } = input;
|
|
64
|
+
const runnable = this.runnables[key];
|
|
65
|
+
if (runnable === undefined) {
|
|
66
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
67
|
+
}
|
|
68
|
+
return runnable.stream(actualInput, options);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -106,15 +106,17 @@ class OpenSearchVectorStore extends base_js_1.VectorStore {
|
|
|
106
106
|
* exists, then adds the vectors and associated documents to the index.
|
|
107
107
|
* @param vectors The vectors to be added to the OpenSearch index.
|
|
108
108
|
* @param documents The documents associated with the vectors.
|
|
109
|
+
* @param options Optional parameter that can contain the IDs for the documents.
|
|
109
110
|
* @returns Promise resolving to void.
|
|
110
111
|
*/
|
|
111
|
-
async addVectors(vectors, documents) {
|
|
112
|
+
async addVectors(vectors, documents, options) {
|
|
112
113
|
await this.ensureIndexExists(vectors[0].length, this.engine, this.spaceType, this.efSearch, this.efConstruction, this.m);
|
|
114
|
+
const documentIds = options?.ids ?? Array.from({ length: vectors.length }, () => uuid.v4());
|
|
113
115
|
const operations = vectors.flatMap((embedding, idx) => [
|
|
114
116
|
{
|
|
115
117
|
index: {
|
|
116
118
|
_index: this.indexName,
|
|
117
|
-
_id:
|
|
119
|
+
_id: documentIds[idx],
|
|
118
120
|
},
|
|
119
121
|
},
|
|
120
122
|
{
|
|
@@ -61,9 +61,12 @@ export declare class OpenSearchVectorStore extends VectorStore {
|
|
|
61
61
|
* exists, then adds the vectors and associated documents to the index.
|
|
62
62
|
* @param vectors The vectors to be added to the OpenSearch index.
|
|
63
63
|
* @param documents The documents associated with the vectors.
|
|
64
|
+
* @param options Optional parameter that can contain the IDs for the documents.
|
|
64
65
|
* @returns Promise resolving to void.
|
|
65
66
|
*/
|
|
66
|
-
addVectors(vectors: number[][], documents: Document[]
|
|
67
|
+
addVectors(vectors: number[][], documents: Document[], options?: {
|
|
68
|
+
ids?: string[];
|
|
69
|
+
}): Promise<void>;
|
|
67
70
|
/**
|
|
68
71
|
* Method to perform a similarity search on the OpenSearch index using a
|
|
69
72
|
* query vector. It returns the k most similar documents and their scores.
|
|
@@ -80,15 +80,17 @@ export class OpenSearchVectorStore extends VectorStore {
|
|
|
80
80
|
* exists, then adds the vectors and associated documents to the index.
|
|
81
81
|
* @param vectors The vectors to be added to the OpenSearch index.
|
|
82
82
|
* @param documents The documents associated with the vectors.
|
|
83
|
+
* @param options Optional parameter that can contain the IDs for the documents.
|
|
83
84
|
* @returns Promise resolving to void.
|
|
84
85
|
*/
|
|
85
|
-
async addVectors(vectors, documents) {
|
|
86
|
+
async addVectors(vectors, documents, options) {
|
|
86
87
|
await this.ensureIndexExists(vectors[0].length, this.engine, this.spaceType, this.efSearch, this.efConstruction, this.m);
|
|
88
|
+
const documentIds = options?.ids ?? Array.from({ length: vectors.length }, () => uuid.v4());
|
|
87
89
|
const operations = vectors.flatMap((embedding, idx) => [
|
|
88
90
|
{
|
|
89
91
|
index: {
|
|
90
92
|
_index: this.indexName,
|
|
91
|
-
_id:
|
|
93
|
+
_id: documentIds[idx],
|
|
92
94
|
},
|
|
93
95
|
},
|
|
94
96
|
{
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langchain",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.150",
|
|
4
4
|
"description": "Typescript bindings for langchain",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -728,7 +728,7 @@
|
|
|
728
728
|
"puppeteer": "^19.7.2",
|
|
729
729
|
"redis": "^4.6.6",
|
|
730
730
|
"release-it": "^15.10.1",
|
|
731
|
-
"replicate": "^0.
|
|
731
|
+
"replicate": "^0.18.0",
|
|
732
732
|
"rimraf": "^5.0.1",
|
|
733
733
|
"rollup": "^3.19.1",
|
|
734
734
|
"sonix-speech-recognition": "^2.1.1",
|
|
@@ -815,7 +815,7 @@
|
|
|
815
815
|
"playwright": "^1.32.1",
|
|
816
816
|
"puppeteer": "^19.7.2",
|
|
817
817
|
"redis": "^4.6.4",
|
|
818
|
-
"replicate": "^0.
|
|
818
|
+
"replicate": "^0.18.0",
|
|
819
819
|
"sonix-speech-recognition": "^2.1.1",
|
|
820
820
|
"srt-parser-2": "^1.2.2",
|
|
821
821
|
"typeorm": "^0.3.12",
|