langchain 0.0.132 → 0.0.133
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/agents/chat/outputParser.cjs +2 -1
- package/dist/agents/chat/outputParser.js +2 -1
- package/dist/agents/executor.cjs +106 -7
- package/dist/agents/executor.d.ts +23 -0
- package/dist/agents/executor.js +104 -6
- package/dist/agents/mrkl/outputParser.cjs +2 -1
- package/dist/agents/mrkl/outputParser.js +2 -1
- package/dist/chat_models/googlevertexai.cjs +1 -1
- package/dist/chat_models/googlevertexai.d.ts +2 -2
- package/dist/chat_models/googlevertexai.js +2 -2
- package/dist/chat_models/ollama.cjs +8 -8
- package/dist/chat_models/ollama.js +8 -8
- package/dist/document_loaders/web/notionapi.cjs +153 -74
- package/dist/document_loaders/web/notionapi.d.ts +19 -10
- package/dist/document_loaders/web/notionapi.js +154 -75
- package/dist/embeddings/googlevertexai.cjs +1 -1
- package/dist/embeddings/googlevertexai.d.ts +2 -2
- package/dist/embeddings/googlevertexai.js +2 -2
- package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +1 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -2
- package/dist/experimental/multimodal_embeddings/googlevertexai.js +2 -2
- package/dist/llms/googlevertexai.cjs +1 -1
- package/dist/llms/googlevertexai.js +2 -2
- package/dist/load/import_constants.cjs +1 -0
- package/dist/load/import_constants.js +1 -0
- package/dist/schema/output_parser.cjs +2 -2
- package/dist/schema/output_parser.js +2 -2
- package/dist/tools/base.cjs +26 -2
- package/dist/tools/base.d.ts +9 -0
- package/dist/tools/base.js +24 -1
- package/dist/types/googlevertexai-types.d.ts +8 -3
- package/dist/util/googlevertexai-connection.cjs +49 -15
- package/dist/util/googlevertexai-connection.d.ts +12 -4
- package/dist/util/googlevertexai-connection.js +46 -13
- package/dist/vectorstores/googlevertexai.cjs +550 -0
- package/dist/vectorstores/googlevertexai.d.ts +180 -0
- package/dist/vectorstores/googlevertexai.js +519 -0
- package/dist/vectorstores/vectara.cjs +11 -2
- package/dist/vectorstores/vectara.d.ts +10 -1
- package/dist/vectorstores/vectara.js +11 -2
- package/package.json +10 -2
- package/vectorstores/googlevertexai.cjs +1 -0
- package/vectorstores/googlevertexai.d.ts +1 -0
- package/vectorstores/googlevertexai.js +1 -0
|
@@ -1,8 +1,22 @@
|
|
|
1
|
-
import { Client, isFullBlock, isFullPage, iteratePaginatedAPI, } from "@notionhq/client";
|
|
1
|
+
import { Client, isFullBlock, isFullPage, iteratePaginatedAPI, APIErrorCode, isNotionClientError, isFullDatabase, } from "@notionhq/client";
|
|
2
2
|
import { NotionToMarkdown } from "notion-to-md";
|
|
3
3
|
import { getBlockChildren } from "notion-to-md/build/utils/notion.js";
|
|
4
|
-
import { BaseDocumentLoader } from "../base.js";
|
|
5
4
|
import { Document } from "../../document.js";
|
|
5
|
+
import { BaseDocumentLoader } from "../base.js";
|
|
6
|
+
import { AsyncCaller } from "../../util/async_caller.js";
|
|
7
|
+
const isPageResponse = (res) => !isNotionClientError(res) && res.object === "page";
|
|
8
|
+
const isDatabaseResponse = (res) => !isNotionClientError(res) && res.object === "database";
|
|
9
|
+
const isErrorResponse = (res) => isNotionClientError(res);
|
|
10
|
+
const isPage = (res) => isPageResponse(res) && isFullPage(res);
|
|
11
|
+
const isDatabase = (res) => isDatabaseResponse(res) && isFullDatabase(res);
|
|
12
|
+
const getTitle = (obj) => {
|
|
13
|
+
if (isPage(obj) && obj.properties.title.type === "title") {
|
|
14
|
+
return obj.properties.title.title[0]?.plain_text;
|
|
15
|
+
}
|
|
16
|
+
if (isDatabase(obj))
|
|
17
|
+
return obj.title[0]?.plain_text;
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
6
20
|
/**
|
|
7
21
|
* A class that extends the BaseDocumentLoader class. It represents a
|
|
8
22
|
* document loader for loading documents from Notion using the Notion API.
|
|
@@ -10,6 +24,12 @@ import { Document } from "../../document.js";
|
|
|
10
24
|
export class NotionAPILoader extends BaseDocumentLoader {
|
|
11
25
|
constructor(options) {
|
|
12
26
|
super();
|
|
27
|
+
Object.defineProperty(this, "caller", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
13
33
|
Object.defineProperty(this, "notionClient", {
|
|
14
34
|
enumerable: true,
|
|
15
35
|
configurable: true,
|
|
@@ -28,19 +48,66 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
28
48
|
writable: true,
|
|
29
49
|
value: void 0
|
|
30
50
|
});
|
|
31
|
-
Object.defineProperty(this, "
|
|
51
|
+
Object.defineProperty(this, "pageQueue", {
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true,
|
|
54
|
+
writable: true,
|
|
55
|
+
value: void 0
|
|
56
|
+
});
|
|
57
|
+
Object.defineProperty(this, "pageCompleted", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true,
|
|
61
|
+
value: void 0
|
|
62
|
+
});
|
|
63
|
+
Object.defineProperty(this, "pageQueueTotal", {
|
|
64
|
+
enumerable: true,
|
|
65
|
+
configurable: true,
|
|
66
|
+
writable: true,
|
|
67
|
+
value: void 0
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(this, "documents", {
|
|
32
70
|
enumerable: true,
|
|
33
71
|
configurable: true,
|
|
34
72
|
writable: true,
|
|
35
73
|
value: void 0
|
|
36
74
|
});
|
|
37
|
-
this
|
|
75
|
+
Object.defineProperty(this, "rootTitle", {
|
|
76
|
+
enumerable: true,
|
|
77
|
+
configurable: true,
|
|
78
|
+
writable: true,
|
|
79
|
+
value: void 0
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(this, "onDocumentLoaded", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
configurable: true,
|
|
84
|
+
writable: true,
|
|
85
|
+
value: void 0
|
|
86
|
+
});
|
|
87
|
+
this.caller = new AsyncCaller({
|
|
88
|
+
maxConcurrency: 64,
|
|
89
|
+
...options.callerOptions,
|
|
90
|
+
});
|
|
91
|
+
this.notionClient = new Client({
|
|
92
|
+
logger: () => { },
|
|
93
|
+
...options.clientOptions,
|
|
94
|
+
});
|
|
38
95
|
this.n2mClient = new NotionToMarkdown({
|
|
39
96
|
notionClient: this.notionClient,
|
|
40
97
|
config: { parseChildPages: false, convertImagesToBase64: false },
|
|
41
98
|
});
|
|
42
99
|
this.id = options.id;
|
|
43
|
-
this.
|
|
100
|
+
this.pageQueue = [];
|
|
101
|
+
this.pageCompleted = [];
|
|
102
|
+
this.pageQueueTotal = 0;
|
|
103
|
+
this.documents = [];
|
|
104
|
+
this.rootTitle = "";
|
|
105
|
+
this.onDocumentLoaded = options.onDocumentLoaded ?? ((_ti, _cu) => { });
|
|
106
|
+
}
|
|
107
|
+
addToQueue(...items) {
|
|
108
|
+
const deDuped = items.filter((item) => !this.pageCompleted.concat(this.pageQueue).includes(item));
|
|
109
|
+
this.pageQueue.push(...deDuped);
|
|
110
|
+
this.pageQueueTotal += deDuped.length;
|
|
44
111
|
}
|
|
45
112
|
/**
|
|
46
113
|
* Parses the properties of a Notion page and returns them as key-value
|
|
@@ -123,123 +190,135 @@ export class NotionAPILoader extends BaseDocumentLoader {
|
|
|
123
190
|
* @returns A Promise that resolves to an MdBlock object.
|
|
124
191
|
*/
|
|
125
192
|
async loadBlock(block) {
|
|
126
|
-
|
|
193
|
+
const mdBlock = {
|
|
127
194
|
type: block.type,
|
|
128
195
|
blockId: block.id,
|
|
129
|
-
parent: await this.n2mClient.blockToMarkdown(block),
|
|
196
|
+
parent: await this.caller.call(() => this.n2mClient.blockToMarkdown(block)),
|
|
130
197
|
children: [],
|
|
131
198
|
};
|
|
199
|
+
if (block.has_children) {
|
|
200
|
+
const block_id = block.type === "synced_block" &&
|
|
201
|
+
block.synced_block?.synced_from?.block_id
|
|
202
|
+
? block.synced_block.synced_from.block_id
|
|
203
|
+
: block.id;
|
|
204
|
+
const childBlocks = await this.loadBlocks(await this.caller.call(() => getBlockChildren(this.notionClient, block_id, null)));
|
|
205
|
+
mdBlock.children = childBlocks;
|
|
206
|
+
}
|
|
207
|
+
return mdBlock;
|
|
132
208
|
}
|
|
133
209
|
/**
|
|
134
|
-
* Loads Notion blocks and their
|
|
210
|
+
* Loads Notion blocks and their children recursively.
|
|
135
211
|
* @param blocksResponse The response from the Notion API containing the blocks to load.
|
|
136
|
-
* @returns A Promise that resolves to an
|
|
212
|
+
* @returns A Promise that resolves to an array containing the loaded MdBlocks.
|
|
137
213
|
*/
|
|
138
|
-
async
|
|
214
|
+
async loadBlocks(blocksResponse) {
|
|
139
215
|
const blocks = blocksResponse.filter(isFullBlock);
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
const childBlocksDocs = await this.loadBlocksAndDocs(await getBlockChildren(this.notionClient, block_id, null));
|
|
158
|
-
mdBlock.children = childBlocksDocs.mdBlocks;
|
|
159
|
-
childDocuments = childBlocksDocs.childDocuments;
|
|
160
|
-
}
|
|
161
|
-
return {
|
|
162
|
-
mdBlocks: [mdBlock],
|
|
163
|
-
childDocuments,
|
|
164
|
-
};
|
|
165
|
-
})),
|
|
216
|
+
// Add child pages to queue
|
|
217
|
+
const childPages = blocks
|
|
218
|
+
.filter((block) => block.type.includes("child_page"))
|
|
219
|
+
.map((block) => block.id);
|
|
220
|
+
if (childPages.length > 0)
|
|
221
|
+
this.addToQueue(...childPages);
|
|
222
|
+
// Add child database pages to queue
|
|
223
|
+
const childDatabases = blocks
|
|
224
|
+
.filter((block) => block.type.includes("child_database"))
|
|
225
|
+
.map((block) => this.caller.call(() => this.loadDatabase(block.id)));
|
|
226
|
+
// Load this block and child blocks
|
|
227
|
+
const loadingMdBlocks = blocks
|
|
228
|
+
.filter((block) => !["child_page", "child_database"].includes(block.type))
|
|
229
|
+
.map((block) => this.loadBlock(block));
|
|
230
|
+
const [mdBlocks] = await Promise.all([
|
|
231
|
+
Promise.all(loadingMdBlocks),
|
|
232
|
+
Promise.all(childDatabases),
|
|
166
233
|
]);
|
|
167
|
-
|
|
168
|
-
.flat()
|
|
169
|
-
.map((blockDoc) => blockDoc.mdBlocks);
|
|
170
|
-
const childDocuments = blocksDocsArray
|
|
171
|
-
.flat()
|
|
172
|
-
.map((blockDoc) => blockDoc.childDocuments);
|
|
173
|
-
return {
|
|
174
|
-
mdBlocks: [...allMdBlocks.flat()],
|
|
175
|
-
childDocuments: [
|
|
176
|
-
...childPageDocuments.flat(),
|
|
177
|
-
...childDatabaseDocuments.flat(),
|
|
178
|
-
...childDocuments.flat(),
|
|
179
|
-
],
|
|
180
|
-
};
|
|
234
|
+
return mdBlocks;
|
|
181
235
|
}
|
|
182
236
|
/**
|
|
183
|
-
* Loads a Notion page and its child documents.
|
|
237
|
+
* Loads a Notion page and its child documents, then adds it to the completed documents array.
|
|
184
238
|
* @param page The Notion page or page ID to load.
|
|
185
|
-
* @returns A Promise that resolves to an array of Documents.
|
|
186
239
|
*/
|
|
187
240
|
async loadPage(page) {
|
|
188
|
-
// Check page is a page ID or a
|
|
241
|
+
// Check page is a page ID or a PageObjectResponse
|
|
189
242
|
const [pageData, pageId] = typeof page === "string"
|
|
190
|
-
? [
|
|
243
|
+
? [
|
|
244
|
+
this.caller.call(() => this.notionClient.pages.retrieve({ page_id: page })),
|
|
245
|
+
page,
|
|
246
|
+
]
|
|
191
247
|
: [page, page.id];
|
|
192
248
|
const [pageDetails, pageBlocks] = await Promise.all([
|
|
193
249
|
pageData,
|
|
194
|
-
getBlockChildren(this.notionClient, pageId, null),
|
|
250
|
+
this.caller.call(() => getBlockChildren(this.notionClient, pageId, null)),
|
|
195
251
|
]);
|
|
196
252
|
if (!isFullPage(pageDetails))
|
|
197
|
-
return
|
|
198
|
-
const
|
|
253
|
+
return;
|
|
254
|
+
const mdBlocks = await this.loadBlocks(pageBlocks);
|
|
199
255
|
const mdStringObject = this.n2mClient.toMarkdownString(mdBlocks);
|
|
200
256
|
const pageDocument = new Document({
|
|
201
257
|
pageContent: mdStringObject.parent,
|
|
202
258
|
metadata: this.parsePageDetails(pageDetails),
|
|
203
259
|
});
|
|
204
|
-
|
|
260
|
+
this.documents.push(pageDocument);
|
|
261
|
+
this.pageCompleted.push(pageId);
|
|
262
|
+
this.onDocumentLoaded(this.documents.length, this.pageQueueTotal, pageDocument.metadata.properties.title, this.rootTitle);
|
|
205
263
|
}
|
|
206
264
|
/**
|
|
207
|
-
* Loads a Notion database and
|
|
265
|
+
* Loads a Notion database and adds it's pages to the queue.
|
|
208
266
|
* @param id The ID of the Notion database to load.
|
|
209
|
-
* @returns A Promise that resolves to an array of Documents.
|
|
210
267
|
*/
|
|
211
268
|
async loadDatabase(id) {
|
|
212
|
-
const documents = [];
|
|
213
269
|
try {
|
|
214
270
|
for await (const page of iteratePaginatedAPI(this.notionClient.databases.query, {
|
|
215
271
|
database_id: id,
|
|
272
|
+
page_size: 50,
|
|
216
273
|
})) {
|
|
217
|
-
|
|
218
|
-
continue;
|
|
219
|
-
documents.push(...(await this.loadPage(page)));
|
|
274
|
+
this.addToQueue(page.id);
|
|
220
275
|
}
|
|
221
276
|
}
|
|
222
277
|
catch (e) {
|
|
223
278
|
console.log(e);
|
|
224
279
|
// TODO: Catch and report api request errors
|
|
225
280
|
}
|
|
226
|
-
return documents;
|
|
227
281
|
}
|
|
228
282
|
/**
|
|
229
283
|
* Loads the documents from Notion based on the specified options.
|
|
230
284
|
* @returns A Promise that resolves to an array of Documents.
|
|
231
285
|
*/
|
|
232
286
|
async load() {
|
|
233
|
-
const
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
287
|
+
const resPagePromise = this.notionClient.pages
|
|
288
|
+
.retrieve({ page_id: this.id })
|
|
289
|
+
.then((res) => {
|
|
290
|
+
this.addToQueue(this.id);
|
|
291
|
+
return res;
|
|
292
|
+
})
|
|
293
|
+
.catch((error) => error);
|
|
294
|
+
const resDatabasePromise = this.notionClient.databases
|
|
295
|
+
.retrieve({ database_id: this.id })
|
|
296
|
+
.then(async (res) => {
|
|
297
|
+
await this.loadDatabase(this.id);
|
|
298
|
+
return res;
|
|
299
|
+
})
|
|
300
|
+
.catch((error) => error);
|
|
301
|
+
const [resPage, resDatabase] = await Promise.all([
|
|
302
|
+
resPagePromise,
|
|
303
|
+
resDatabasePromise,
|
|
304
|
+
]);
|
|
305
|
+
// Check if both resPage and resDatabase resulted in error responses
|
|
306
|
+
const errors = [resPage, resDatabase].filter(isErrorResponse);
|
|
307
|
+
if (errors.length === 2) {
|
|
308
|
+
if (errors.every((e) => e.code === APIErrorCode.ObjectNotFound)) {
|
|
309
|
+
throw new AggregateError([
|
|
310
|
+
Error(`Could not find object with ID: ${this.id}. Make sure the relevant pages and databases are shared with your integration.`),
|
|
311
|
+
...errors,
|
|
312
|
+
]);
|
|
313
|
+
}
|
|
314
|
+
throw new AggregateError(errors);
|
|
315
|
+
}
|
|
316
|
+
this.rootTitle = getTitle(resPage) || getTitle(resDatabase) || this.id;
|
|
317
|
+
let pageId = this.pageQueue.shift();
|
|
318
|
+
while (pageId) {
|
|
319
|
+
await this.loadPage(pageId);
|
|
320
|
+
pageId = this.pageQueue.shift();
|
|
242
321
|
}
|
|
243
|
-
return documents;
|
|
322
|
+
return this.documents;
|
|
244
323
|
}
|
|
245
324
|
}
|
|
@@ -34,7 +34,7 @@ class GoogleVertexAIEmbeddings extends base_js_1.Embeddings {
|
|
|
34
34
|
value: void 0
|
|
35
35
|
});
|
|
36
36
|
this.model = fields?.model ?? this.model;
|
|
37
|
-
this.connection = new googlevertexai_connection_js_1.
|
|
37
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
38
38
|
}
|
|
39
39
|
/**
|
|
40
40
|
* Takes an array of documents as input and returns a promise that
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Embeddings, EmbeddingsParams } from "./base.js";
|
|
2
|
-
import {
|
|
2
|
+
import { GoogleVertexAIBaseLLMInput } from "../types/googlevertexai-types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Defines the parameters required to initialize a
|
|
5
5
|
* GoogleVertexAIEmbeddings instance. It extends EmbeddingsParams and
|
|
6
6
|
* GoogleVertexAIConnectionParams.
|
|
7
7
|
*/
|
|
8
|
-
export interface GoogleVertexAIEmbeddingsParams extends EmbeddingsParams,
|
|
8
|
+
export interface GoogleVertexAIEmbeddingsParams extends EmbeddingsParams, GoogleVertexAIBaseLLMInput {
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Embeddings } from "./base.js";
|
|
2
|
-
import {
|
|
2
|
+
import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
|
|
3
3
|
import { chunkArray } from "../util/chunk.js";
|
|
4
4
|
/**
|
|
5
5
|
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
@@ -31,7 +31,7 @@ export class GoogleVertexAIEmbeddings extends Embeddings {
|
|
|
31
31
|
value: void 0
|
|
32
32
|
});
|
|
33
33
|
this.model = fields?.model ?? this.model;
|
|
34
|
-
this.connection = new
|
|
34
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
35
35
|
}
|
|
36
36
|
/**
|
|
37
37
|
* Takes an array of documents as input and returns a promise that
|
|
@@ -24,7 +24,7 @@ class GoogleVertexAIMultimodalEmbeddings extends base_js_1.Embeddings {
|
|
|
24
24
|
value: void 0
|
|
25
25
|
});
|
|
26
26
|
this.model = fields?.model ?? this.model;
|
|
27
|
-
this.connection = new googlevertexai_connection_js_1.
|
|
27
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
28
28
|
}
|
|
29
29
|
/**
|
|
30
30
|
* Converts media (text or image) to an instance that can be used for
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" resolution-mode="require"/>
|
|
2
2
|
import { Embeddings, EmbeddingsParams } from "../../embeddings/base.js";
|
|
3
|
-
import {
|
|
3
|
+
import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction, GoogleVertexAILLMResponse } from "../../types/googlevertexai-types.js";
|
|
4
4
|
/**
|
|
5
5
|
* Parameters for the GoogleVertexAIMultimodalEmbeddings class, extending
|
|
6
6
|
* both EmbeddingsParams and GoogleVertexAIConnectionParams.
|
|
7
7
|
*/
|
|
8
|
-
export interface GoogleVertexAIMultimodalEmbeddingsParams extends EmbeddingsParams,
|
|
8
|
+
export interface GoogleVertexAIMultimodalEmbeddingsParams extends EmbeddingsParams, GoogleVertexAIBaseLLMInput {
|
|
9
9
|
}
|
|
10
10
|
/**
|
|
11
11
|
* An instance of media (text or image) that can be used for generating
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Embeddings } from "../../embeddings/base.js";
|
|
2
|
-
import {
|
|
2
|
+
import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
|
|
3
3
|
/**
|
|
4
4
|
* Class for generating embeddings for text and images using Google's
|
|
5
5
|
* Vertex AI. It extends the Embeddings base class and implements the
|
|
@@ -21,7 +21,7 @@ export class GoogleVertexAIMultimodalEmbeddings extends Embeddings {
|
|
|
21
21
|
value: void 0
|
|
22
22
|
});
|
|
23
23
|
this.model = fields?.model ?? this.model;
|
|
24
|
-
this.connection = new
|
|
24
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Converts media (text or image) to an instance that can be used for
|
|
@@ -68,7 +68,7 @@ class GoogleVertexAI extends base_js_1.BaseLLM {
|
|
|
68
68
|
this.maxOutputTokens = fields?.maxOutputTokens ?? this.maxOutputTokens;
|
|
69
69
|
this.topP = fields?.topP ?? this.topP;
|
|
70
70
|
this.topK = fields?.topK ?? this.topK;
|
|
71
|
-
this.connection = new googlevertexai_connection_js_1.
|
|
71
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
72
72
|
}
|
|
73
73
|
_llmType() {
|
|
74
74
|
return "googlevertexai";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BaseLLM } from "./base.js";
|
|
2
|
-
import {
|
|
2
|
+
import { GoogleVertexAILLMConnection } from "../util/googlevertexai-connection.js";
|
|
3
3
|
/**
|
|
4
4
|
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
5
5
|
* Large Language Models.
|
|
@@ -65,7 +65,7 @@ export class GoogleVertexAI extends BaseLLM {
|
|
|
65
65
|
this.maxOutputTokens = fields?.maxOutputTokens ?? this.maxOutputTokens;
|
|
66
66
|
this.topP = fields?.topP ?? this.topP;
|
|
67
67
|
this.topK = fields?.topK ?? this.topK;
|
|
68
|
-
this.connection = new
|
|
68
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
69
69
|
}
|
|
70
70
|
_llmType() {
|
|
71
71
|
return "googlevertexai";
|
|
@@ -33,6 +33,7 @@ exports.optionalImportEntrypoints = [
|
|
|
33
33
|
"langchain/vectorstores/analyticdb",
|
|
34
34
|
"langchain/vectorstores/elasticsearch",
|
|
35
35
|
"langchain/vectorstores/chroma",
|
|
36
|
+
"langchain/vectorstores/googlevertexai",
|
|
36
37
|
"langchain/vectorstores/hnswlib",
|
|
37
38
|
"langchain/vectorstores/faiss",
|
|
38
39
|
"langchain/vectorstores/weaviate",
|
|
@@ -30,6 +30,7 @@ export const optionalImportEntrypoints = [
|
|
|
30
30
|
"langchain/vectorstores/analyticdb",
|
|
31
31
|
"langchain/vectorstores/elasticsearch",
|
|
32
32
|
"langchain/vectorstores/chroma",
|
|
33
|
+
"langchain/vectorstores/googlevertexai",
|
|
33
34
|
"langchain/vectorstores/hnswlib",
|
|
34
35
|
"langchain/vectorstores/faiss",
|
|
35
36
|
"langchain/vectorstores/weaviate",
|
|
@@ -96,7 +96,7 @@ class StringOutputParser extends BaseTransformOutputParser {
|
|
|
96
96
|
enumerable: true,
|
|
97
97
|
configurable: true,
|
|
98
98
|
writable: true,
|
|
99
|
-
value: ["schema", "output_parser"]
|
|
99
|
+
value: ["langchain", "schema", "output_parser"]
|
|
100
100
|
});
|
|
101
101
|
Object.defineProperty(this, "lc_serializable", {
|
|
102
102
|
enumerable: true,
|
|
@@ -135,7 +135,7 @@ class BytesOutputParser extends BaseTransformOutputParser {
|
|
|
135
135
|
enumerable: true,
|
|
136
136
|
configurable: true,
|
|
137
137
|
writable: true,
|
|
138
|
-
value: ["schema", "output_parser"]
|
|
138
|
+
value: ["langchain", "schema", "output_parser"]
|
|
139
139
|
});
|
|
140
140
|
Object.defineProperty(this, "lc_serializable", {
|
|
141
141
|
enumerable: true,
|
|
@@ -90,7 +90,7 @@ export class StringOutputParser extends BaseTransformOutputParser {
|
|
|
90
90
|
enumerable: true,
|
|
91
91
|
configurable: true,
|
|
92
92
|
writable: true,
|
|
93
|
-
value: ["schema", "output_parser"]
|
|
93
|
+
value: ["langchain", "schema", "output_parser"]
|
|
94
94
|
});
|
|
95
95
|
Object.defineProperty(this, "lc_serializable", {
|
|
96
96
|
enumerable: true,
|
|
@@ -128,7 +128,7 @@ export class BytesOutputParser extends BaseTransformOutputParser {
|
|
|
128
128
|
enumerable: true,
|
|
129
129
|
configurable: true,
|
|
130
130
|
writable: true,
|
|
131
|
-
value: ["schema", "output_parser"]
|
|
131
|
+
value: ["langchain", "schema", "output_parser"]
|
|
132
132
|
});
|
|
133
133
|
Object.defineProperty(this, "lc_serializable", {
|
|
134
134
|
enumerable: true,
|
package/dist/tools/base.cjs
CHANGED
|
@@ -1,9 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Tool = exports.StructuredTool = void 0;
|
|
3
|
+
exports.Tool = exports.StructuredTool = exports.ToolInputParsingException = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const manager_js_1 = require("../callbacks/manager.cjs");
|
|
6
6
|
const index_js_1 = require("../base_language/index.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
9
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
10
|
+
* property that can hold the output that caused the exception.
|
|
11
|
+
*/
|
|
12
|
+
class ToolInputParsingException extends Error {
|
|
13
|
+
constructor(message, output) {
|
|
14
|
+
super(message);
|
|
15
|
+
Object.defineProperty(this, "output", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: void 0
|
|
20
|
+
});
|
|
21
|
+
this.output = output;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
exports.ToolInputParsingException = ToolInputParsingException;
|
|
7
25
|
/**
|
|
8
26
|
* Base class for Tools that accept input of any shape defined by a Zod schema.
|
|
9
27
|
*/
|
|
@@ -41,7 +59,13 @@ class StructuredTool extends index_js_1.BaseLangChain {
|
|
|
41
59
|
async call(arg, configArg,
|
|
42
60
|
/** @deprecated */
|
|
43
61
|
tags) {
|
|
44
|
-
|
|
62
|
+
let parsed;
|
|
63
|
+
try {
|
|
64
|
+
parsed = await this.schema.parseAsync(arg);
|
|
65
|
+
}
|
|
66
|
+
catch (e) {
|
|
67
|
+
throw new ToolInputParsingException(`Received tool input did not match expected schema`, JSON.stringify(arg));
|
|
68
|
+
}
|
|
45
69
|
const config = (0, manager_js_1.parseCallbackConfigArg)(configArg);
|
|
46
70
|
const callbackManager_ = await manager_js_1.CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
|
47
71
|
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed));
|
package/dist/tools/base.d.ts
CHANGED
|
@@ -7,6 +7,15 @@ import { RunnableConfig } from "../schema/runnable.js";
|
|
|
7
7
|
*/
|
|
8
8
|
export interface ToolParams extends BaseLangChainParams {
|
|
9
9
|
}
|
|
10
|
+
/**
|
|
11
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
12
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
13
|
+
* property that can hold the output that caused the exception.
|
|
14
|
+
*/
|
|
15
|
+
export declare class ToolInputParsingException extends Error {
|
|
16
|
+
output?: string;
|
|
17
|
+
constructor(message: string, output?: string);
|
|
18
|
+
}
|
|
10
19
|
/**
|
|
11
20
|
* Base class for Tools that accept input of any shape defined by a Zod schema.
|
|
12
21
|
*/
|
package/dist/tools/base.js
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { CallbackManager, parseCallbackConfigArg, } from "../callbacks/manager.js";
|
|
3
3
|
import { BaseLangChain } from "../base_language/index.js";
|
|
4
|
+
/**
|
|
5
|
+
* Custom error class used to handle exceptions related to tool input parsing.
|
|
6
|
+
* It extends the built-in `Error` class and adds an optional `output`
|
|
7
|
+
* property that can hold the output that caused the exception.
|
|
8
|
+
*/
|
|
9
|
+
export class ToolInputParsingException extends Error {
|
|
10
|
+
constructor(message, output) {
|
|
11
|
+
super(message);
|
|
12
|
+
Object.defineProperty(this, "output", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: void 0
|
|
17
|
+
});
|
|
18
|
+
this.output = output;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
4
21
|
/**
|
|
5
22
|
* Base class for Tools that accept input of any shape defined by a Zod schema.
|
|
6
23
|
*/
|
|
@@ -38,7 +55,13 @@ export class StructuredTool extends BaseLangChain {
|
|
|
38
55
|
async call(arg, configArg,
|
|
39
56
|
/** @deprecated */
|
|
40
57
|
tags) {
|
|
41
|
-
|
|
58
|
+
let parsed;
|
|
59
|
+
try {
|
|
60
|
+
parsed = await this.schema.parseAsync(arg);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
throw new ToolInputParsingException(`Received tool input did not match expected schema`, JSON.stringify(arg));
|
|
64
|
+
}
|
|
42
65
|
const config = parseCallbackConfigArg(configArg);
|
|
43
66
|
const callbackManager_ = await CallbackManager.configure(config.callbacks, this.callbacks, config.tags || tags, this.tags, config.metadata, this.metadata, { verbose: this.verbose });
|
|
44
67
|
const runManager = await callbackManager_?.handleToolStart(this.toJSON(), typeof parsed === "string" ? parsed : JSON.stringify(parsed));
|
|
@@ -6,10 +6,12 @@ export interface GoogleVertexAIConnectionParams {
|
|
|
6
6
|
authOptions?: GoogleAuthOptions;
|
|
7
7
|
/** Region where the LLM is stored */
|
|
8
8
|
location?: string;
|
|
9
|
-
/**
|
|
10
|
-
|
|
9
|
+
/** The version of the API functions. Part of the path. */
|
|
10
|
+
apiVersion?: string;
|
|
11
11
|
}
|
|
12
12
|
export interface GoogleVertexAIModelParams {
|
|
13
|
+
/** Model to use */
|
|
14
|
+
model?: string;
|
|
13
15
|
/** Sampling temperature to use */
|
|
14
16
|
temperature?: number;
|
|
15
17
|
/**
|
|
@@ -39,7 +41,10 @@ export interface GoogleVertexAIModelParams {
|
|
|
39
41
|
}
|
|
40
42
|
export interface GoogleVertexAIBaseLLMInput extends BaseLLMParams, GoogleVertexAIConnectionParams, GoogleVertexAIModelParams {
|
|
41
43
|
}
|
|
42
|
-
export interface
|
|
44
|
+
export interface GoogleVertexAIResponse {
|
|
45
|
+
data: any;
|
|
46
|
+
}
|
|
47
|
+
export interface GoogleVertexAIBasePrediction extends GoogleVertexAIResponse {
|
|
43
48
|
safetyAttributes?: any;
|
|
44
49
|
}
|
|
45
50
|
export interface GoogleVertexAILLMResponse<PredictionType extends GoogleVertexAIBasePrediction> {
|