langchain 0.0.78 → 0.0.79
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/query_constructor/prompt.cjs +5 -5
- package/dist/chains/query_constructor/prompt.d.ts +2 -2
- package/dist/chains/query_constructor/prompt.js +5 -5
- package/dist/chains/sql_db/sql_db_chain.cjs +0 -3
- package/dist/chains/sql_db/sql_db_chain.js +0 -3
- package/dist/chains/vector_db_qa.cjs +1 -1
- package/dist/chains/vector_db_qa.js +1 -1
- package/dist/client/langchainplus.cjs +143 -52
- package/dist/client/langchainplus.d.ts +72 -15
- package/dist/client/langchainplus.js +144 -53
- package/dist/prompts/selectors/conditional.cjs +4 -0
- package/dist/prompts/selectors/conditional.d.ts +5 -0
- package/dist/prompts/selectors/conditional.js +4 -0
- package/dist/retrievers/metal.d.ts +2 -1
- package/dist/stores/message/redis.cjs +1 -10
- package/dist/stores/message/redis.js +1 -10
- package/dist/vectorstores/milvus.cjs +9 -30
- package/dist/vectorstores/milvus.d.ts +0 -3
- package/dist/vectorstores/milvus.js +9 -30
- package/package.json +4 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { LangChainTracer } from "../callbacks/handlers/tracer_langchain.js";
|
|
1
|
+
import { LangChainTracer, } from "../callbacks/handlers/tracer_langchain.js";
|
|
2
2
|
import { mapStoredMessagesToChatMessages } from "../stores/message/utils.js";
|
|
3
3
|
import { AsyncCaller } from "../util/async_caller.js";
|
|
4
4
|
// utility functions
|
|
@@ -7,7 +7,7 @@ const isLocalhost = (url) => {
|
|
|
7
7
|
const hostname = strippedUrl.split("/")[0].split(":")[0];
|
|
8
8
|
return (hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1");
|
|
9
9
|
};
|
|
10
|
-
const getSeededTenantId = async (apiUrl, apiKey, callerOptions
|
|
10
|
+
const getSeededTenantId = async (apiUrl, { apiKey, callerOptions, }) => {
|
|
11
11
|
// Get the tenant ID from the seeded tenant
|
|
12
12
|
const caller = new AsyncCaller(callerOptions ?? {});
|
|
13
13
|
const url = `${apiUrl}/tenants`;
|
|
@@ -15,7 +15,7 @@ const getSeededTenantId = async (apiUrl, apiKey, callerOptions = undefined) => {
|
|
|
15
15
|
try {
|
|
16
16
|
response = await caller.call(fetch, url, {
|
|
17
17
|
method: "GET",
|
|
18
|
-
headers: apiKey ? {
|
|
18
|
+
headers: apiKey ? { "x-api-key": apiKey } : undefined,
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
21
|
catch (err) {
|
|
@@ -76,18 +76,24 @@ async function getModelOrFactoryType(llm) {
|
|
|
76
76
|
throw new Error("Unknown model or factory type");
|
|
77
77
|
}
|
|
78
78
|
export class LangChainPlusClient {
|
|
79
|
-
constructor(
|
|
79
|
+
constructor(config) {
|
|
80
80
|
Object.defineProperty(this, "apiKey", {
|
|
81
81
|
enumerable: true,
|
|
82
82
|
configurable: true,
|
|
83
83
|
writable: true,
|
|
84
|
-
value:
|
|
84
|
+
value: typeof process !== "undefined"
|
|
85
|
+
? // eslint-disable-next-line no-process-env
|
|
86
|
+
process.env?.LANGCHAIN_API_KEY
|
|
87
|
+
: undefined
|
|
85
88
|
});
|
|
86
89
|
Object.defineProperty(this, "apiUrl", {
|
|
87
90
|
enumerable: true,
|
|
88
91
|
configurable: true,
|
|
89
92
|
writable: true,
|
|
90
|
-
value:
|
|
93
|
+
value: (typeof process !== "undefined"
|
|
94
|
+
? // eslint-disable-next-line no-process-env
|
|
95
|
+
process.env?.LANGCHAIN_ENDPOINT
|
|
96
|
+
: undefined) || "http://localhost:8000"
|
|
91
97
|
});
|
|
92
98
|
Object.defineProperty(this, "tenantId", {
|
|
93
99
|
enumerable: true,
|
|
@@ -101,15 +107,45 @@ export class LangChainPlusClient {
|
|
|
101
107
|
writable: true,
|
|
102
108
|
value: void 0
|
|
103
109
|
});
|
|
104
|
-
this.apiUrl = apiUrl;
|
|
105
|
-
this.apiKey = apiKey;
|
|
106
|
-
|
|
110
|
+
this.apiUrl = config.apiUrl ?? this.apiUrl;
|
|
111
|
+
this.apiKey = config.apiKey;
|
|
112
|
+
const tenantId = config.tenantId ??
|
|
113
|
+
(typeof process !== "undefined"
|
|
114
|
+
? // eslint-disable-next-line no-process-env
|
|
115
|
+
process.env?.LANGCHAIN_TENANT_ID
|
|
116
|
+
: undefined);
|
|
117
|
+
if (tenantId === undefined) {
|
|
118
|
+
throw new Error("No tenant ID provided and no LANGCHAIN_TENANT_ID env var");
|
|
119
|
+
}
|
|
120
|
+
else {
|
|
121
|
+
this.tenantId = tenantId;
|
|
122
|
+
}
|
|
107
123
|
this.validateApiKeyIfHosted();
|
|
108
|
-
this.caller = new AsyncCaller(callerOptions ?? {});
|
|
124
|
+
this.caller = new AsyncCaller(config.callerOptions ?? {});
|
|
109
125
|
}
|
|
110
|
-
static async create(
|
|
111
|
-
const
|
|
112
|
-
|
|
126
|
+
static async create(config = {}) {
|
|
127
|
+
const apiUrl_ = config.apiUrl ??
|
|
128
|
+
((typeof process !== "undefined"
|
|
129
|
+
? // eslint-disable-next-line no-process-env
|
|
130
|
+
process.env?.LANGCHAIN_ENDPOINT
|
|
131
|
+
: undefined) ||
|
|
132
|
+
"http://localhost:8000");
|
|
133
|
+
const apiKey_ = config.apiKey ??
|
|
134
|
+
(typeof process !== "undefined"
|
|
135
|
+
? // eslint-disable-next-line no-process-env
|
|
136
|
+
process.env?.LANGCHAIN_API_KEY
|
|
137
|
+
: undefined);
|
|
138
|
+
const tenantId_ = config.tenantId ??
|
|
139
|
+
((typeof process !== "undefined"
|
|
140
|
+
? // eslint-disable-next-line no-process-env
|
|
141
|
+
process.env?.LANGCHAIN_TENANT_ID
|
|
142
|
+
: undefined) ||
|
|
143
|
+
(await getSeededTenantId(apiUrl_, { apiKey: apiKey_ })));
|
|
144
|
+
return new LangChainPlusClient({
|
|
145
|
+
tenantId: tenantId_,
|
|
146
|
+
apiKey: apiKey_,
|
|
147
|
+
apiUrl: apiUrl_,
|
|
148
|
+
});
|
|
113
149
|
}
|
|
114
150
|
validateApiKeyIfHosted() {
|
|
115
151
|
const isLocal = isLocalhost(this.apiUrl);
|
|
@@ -120,24 +156,21 @@ export class LangChainPlusClient {
|
|
|
120
156
|
get headers() {
|
|
121
157
|
const headers = {};
|
|
122
158
|
if (this.apiKey) {
|
|
123
|
-
headers
|
|
159
|
+
headers["x-api-key"] = `${this.apiKey}`;
|
|
124
160
|
}
|
|
125
161
|
return headers;
|
|
126
162
|
}
|
|
127
163
|
get queryParams() {
|
|
128
|
-
return { tenant_id: this.tenantId };
|
|
129
|
-
}
|
|
130
|
-
async _get(path, queryParams
|
|
131
|
-
const params =
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
? `${queryString}&${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`
|
|
137
|
-
: `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`;
|
|
138
|
-
}
|
|
164
|
+
return new URLSearchParams({ tenant_id: this.tenantId });
|
|
165
|
+
}
|
|
166
|
+
async _get(path, queryParams) {
|
|
167
|
+
const params = this.queryParams;
|
|
168
|
+
if (queryParams) {
|
|
169
|
+
queryParams.forEach((value, key) => {
|
|
170
|
+
params.append(key, value);
|
|
171
|
+
});
|
|
139
172
|
}
|
|
140
|
-
const url = `${this.apiUrl}${path}
|
|
173
|
+
const url = `${this.apiUrl}${path}?${params.toString()}`;
|
|
141
174
|
const response = await this.caller.call(fetch, url, {
|
|
142
175
|
method: "GET",
|
|
143
176
|
headers: this.headers,
|
|
@@ -147,14 +180,73 @@ export class LangChainPlusClient {
|
|
|
147
180
|
}
|
|
148
181
|
return response.json();
|
|
149
182
|
}
|
|
150
|
-
async
|
|
183
|
+
async readRun(runId) {
|
|
184
|
+
return await this._get(`/runs/${runId}`);
|
|
185
|
+
}
|
|
186
|
+
async listRuns({ sessionId, sessionName, executionOrder = 1, runType, error, }) {
|
|
187
|
+
const queryParams = new URLSearchParams();
|
|
188
|
+
let sessionId_ = sessionId;
|
|
189
|
+
if (sessionName) {
|
|
190
|
+
if (sessionId) {
|
|
191
|
+
throw new Error("Only one of session_id or session_name may be given");
|
|
192
|
+
}
|
|
193
|
+
sessionId_ = (await this.readSession({ sessionName })).id;
|
|
194
|
+
}
|
|
195
|
+
if (sessionId_) {
|
|
196
|
+
queryParams.append("session", sessionId_);
|
|
197
|
+
}
|
|
198
|
+
if (executionOrder) {
|
|
199
|
+
queryParams.append("execution_order", executionOrder.toString());
|
|
200
|
+
}
|
|
201
|
+
if (runType) {
|
|
202
|
+
queryParams.append("run_type", runType);
|
|
203
|
+
}
|
|
204
|
+
if (error !== undefined) {
|
|
205
|
+
queryParams.append("error", error.toString());
|
|
206
|
+
}
|
|
207
|
+
return this._get("/runs", queryParams);
|
|
208
|
+
}
|
|
209
|
+
async readSession({ sessionId, sessionName, }) {
|
|
210
|
+
let path = "/sessions";
|
|
211
|
+
const params = new URLSearchParams();
|
|
212
|
+
if (sessionId !== undefined && sessionName !== undefined) {
|
|
213
|
+
throw new Error("Must provide either sessionName or sessionId, not both");
|
|
214
|
+
}
|
|
215
|
+
else if (sessionId !== undefined) {
|
|
216
|
+
path += `/${sessionId}`;
|
|
217
|
+
}
|
|
218
|
+
else if (sessionName !== undefined) {
|
|
219
|
+
params.append("name", sessionName);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
throw new Error("Must provide sessionName or sessionId");
|
|
223
|
+
}
|
|
224
|
+
const response = await this._get(path, params);
|
|
225
|
+
let result;
|
|
226
|
+
if (Array.isArray(response)) {
|
|
227
|
+
if (response.length === 0) {
|
|
228
|
+
throw new Error(`Session[id=${sessionId}, name=${sessionName}] not found`);
|
|
229
|
+
}
|
|
230
|
+
result = response[0];
|
|
231
|
+
}
|
|
232
|
+
else {
|
|
233
|
+
result = response;
|
|
234
|
+
}
|
|
235
|
+
return result;
|
|
236
|
+
}
|
|
237
|
+
async listSessions() {
|
|
238
|
+
return this._get("/sessions");
|
|
239
|
+
}
|
|
240
|
+
async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, }) {
|
|
151
241
|
const url = `${this.apiUrl}/datasets/upload`;
|
|
152
242
|
const formData = new FormData();
|
|
153
243
|
formData.append("file", csvFile, fileName);
|
|
154
244
|
formData.append("input_keys", inputKeys.join(","));
|
|
155
245
|
formData.append("output_keys", outputKeys.join(","));
|
|
156
|
-
formData.append("description", description);
|
|
157
246
|
formData.append("tenant_id", this.tenantId);
|
|
247
|
+
if (description) {
|
|
248
|
+
formData.append("description", description);
|
|
249
|
+
}
|
|
158
250
|
const response = await this.caller.call(fetch, url, {
|
|
159
251
|
method: "POST",
|
|
160
252
|
headers: this.headers,
|
|
@@ -170,7 +262,7 @@ export class LangChainPlusClient {
|
|
|
170
262
|
const result = await response.json();
|
|
171
263
|
return result;
|
|
172
264
|
}
|
|
173
|
-
async createDataset(name, description) {
|
|
265
|
+
async createDataset(name, { description }) {
|
|
174
266
|
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, {
|
|
175
267
|
method: "POST",
|
|
176
268
|
headers: { ...this.headers, "Content-Type": "application/json" },
|
|
@@ -190,10 +282,10 @@ export class LangChainPlusClient {
|
|
|
190
282
|
const result = await response.json();
|
|
191
283
|
return result;
|
|
192
284
|
}
|
|
193
|
-
async readDataset(datasetId, datasetName) {
|
|
285
|
+
async readDataset({ datasetId, datasetName, }) {
|
|
194
286
|
let path = "/datasets";
|
|
195
|
-
//
|
|
196
|
-
const params = { limit: 1 };
|
|
287
|
+
// limit to 1 result
|
|
288
|
+
const params = new URLSearchParams({ limit: "1" });
|
|
197
289
|
if (datasetId !== undefined && datasetName !== undefined) {
|
|
198
290
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
199
291
|
}
|
|
@@ -201,7 +293,7 @@ export class LangChainPlusClient {
|
|
|
201
293
|
path += `/${datasetId}`;
|
|
202
294
|
}
|
|
203
295
|
else if (datasetName !== undefined) {
|
|
204
|
-
params.name
|
|
296
|
+
params.append("name", datasetName);
|
|
205
297
|
}
|
|
206
298
|
else {
|
|
207
299
|
throw new Error("Must provide datasetName or datasetId");
|
|
@@ -219,24 +311,23 @@ export class LangChainPlusClient {
|
|
|
219
311
|
}
|
|
220
312
|
return result;
|
|
221
313
|
}
|
|
222
|
-
async listDatasets(limit = 100) {
|
|
314
|
+
async listDatasets({ limit = 100, } = {}) {
|
|
223
315
|
const path = "/datasets";
|
|
224
|
-
|
|
225
|
-
const params = { limit };
|
|
316
|
+
const params = new URLSearchParams({ limit: limit.toString() });
|
|
226
317
|
const response = await this._get(path, params);
|
|
227
318
|
if (!Array.isArray(response)) {
|
|
228
319
|
throw new Error(`Expected ${path} to return an array, but got ${response}`);
|
|
229
320
|
}
|
|
230
321
|
return response;
|
|
231
322
|
}
|
|
232
|
-
async deleteDataset(datasetId, datasetName) {
|
|
323
|
+
async deleteDataset({ datasetId, datasetName, }) {
|
|
233
324
|
let path = "/datasets";
|
|
234
325
|
let datasetId_ = datasetId;
|
|
235
326
|
if (datasetId !== undefined && datasetName !== undefined) {
|
|
236
327
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
237
328
|
}
|
|
238
329
|
else if (datasetName !== undefined) {
|
|
239
|
-
const dataset = await this.readDataset(
|
|
330
|
+
const dataset = await this.readDataset({ datasetName });
|
|
240
331
|
datasetId_ = dataset.id;
|
|
241
332
|
}
|
|
242
333
|
if (datasetId_ !== undefined) {
|
|
@@ -255,7 +346,7 @@ export class LangChainPlusClient {
|
|
|
255
346
|
const results = await response.json();
|
|
256
347
|
return results;
|
|
257
348
|
}
|
|
258
|
-
async createExample(inputs, outputs
|
|
349
|
+
async createExample(inputs, outputs, { datasetId, datasetName, createdAt, }) {
|
|
259
350
|
let datasetId_ = datasetId;
|
|
260
351
|
if (datasetId_ === undefined && datasetName === undefined) {
|
|
261
352
|
throw new Error("Must provide either datasetName or datasetId");
|
|
@@ -264,7 +355,7 @@ export class LangChainPlusClient {
|
|
|
264
355
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
265
356
|
}
|
|
266
357
|
else if (datasetId_ === undefined) {
|
|
267
|
-
const dataset = await this.readDataset(
|
|
358
|
+
const dataset = await this.readDataset({ datasetName });
|
|
268
359
|
datasetId_ = dataset.id;
|
|
269
360
|
}
|
|
270
361
|
const createdAt_ = createdAt || new Date();
|
|
@@ -289,7 +380,7 @@ export class LangChainPlusClient {
|
|
|
289
380
|
const path = `/examples/${exampleId}`;
|
|
290
381
|
return await this._get(path);
|
|
291
382
|
}
|
|
292
|
-
async listExamples(datasetId
|
|
383
|
+
async listExamples({ datasetId, datasetName, } = {}) {
|
|
293
384
|
let datasetId_;
|
|
294
385
|
if (datasetId !== undefined && datasetName !== undefined) {
|
|
295
386
|
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
@@ -298,15 +389,13 @@ export class LangChainPlusClient {
|
|
|
298
389
|
datasetId_ = datasetId;
|
|
299
390
|
}
|
|
300
391
|
else if (datasetName !== undefined) {
|
|
301
|
-
const dataset = await this.readDataset(
|
|
392
|
+
const dataset = await this.readDataset({ datasetName });
|
|
302
393
|
datasetId_ = dataset.id;
|
|
303
394
|
}
|
|
304
395
|
else {
|
|
305
396
|
throw new Error("Must provide a datasetName or datasetId");
|
|
306
397
|
}
|
|
307
|
-
const response = await this._get("/examples", {
|
|
308
|
-
dataset: datasetId_,
|
|
309
|
-
});
|
|
398
|
+
const response = await this._get("/examples", new URLSearchParams({ dataset: datasetId_ }));
|
|
310
399
|
if (!Array.isArray(response)) {
|
|
311
400
|
throw new Error(`Expected /examples to return an array, but got ${response}`);
|
|
312
401
|
}
|
|
@@ -324,7 +413,7 @@ export class LangChainPlusClient {
|
|
|
324
413
|
const result = await response.json();
|
|
325
414
|
return result;
|
|
326
415
|
}
|
|
327
|
-
async runLLM(example, tracer, llm, numRepetitions = 1) {
|
|
416
|
+
async runLLM(example, tracer, llm, { numRepetitions = 1 }) {
|
|
328
417
|
const results = await Promise.all(Array.from({ length: numRepetitions }).map(async () => {
|
|
329
418
|
try {
|
|
330
419
|
const prompt = example.inputs.prompt;
|
|
@@ -337,7 +426,7 @@ export class LangChainPlusClient {
|
|
|
337
426
|
}));
|
|
338
427
|
return results;
|
|
339
428
|
}
|
|
340
|
-
async runChain(example, tracer, chainFactory, numRepetitions = 1) {
|
|
429
|
+
async runChain(example, tracer, chainFactory, { numRepetitions = 1, }) {
|
|
341
430
|
const results = await Promise.all(Array.from({ length: numRepetitions }).map(async () => {
|
|
342
431
|
try {
|
|
343
432
|
const chain = await chainFactory();
|
|
@@ -350,7 +439,7 @@ export class LangChainPlusClient {
|
|
|
350
439
|
}));
|
|
351
440
|
return results;
|
|
352
441
|
}
|
|
353
|
-
async runChatModel(example, tracer, chatModel, numRepetitions = 1) {
|
|
442
|
+
async runChatModel(example, tracer, chatModel, { numRepetitions = 1, }) {
|
|
354
443
|
const results = await Promise.all(Array.from({ length: numRepetitions }).map(async () => {
|
|
355
444
|
try {
|
|
356
445
|
const messages = example.inputs.messages;
|
|
@@ -363,8 +452,8 @@ export class LangChainPlusClient {
|
|
|
363
452
|
}));
|
|
364
453
|
return results;
|
|
365
454
|
}
|
|
366
|
-
async runOnDataset(datasetName, llmOrChainFactory, numRepetitions = 1, sessionName =
|
|
367
|
-
const examples = await this.listExamples(
|
|
455
|
+
async runOnDataset(datasetName, llmOrChainFactory, { numRepetitions = 1, sessionName, } = {}) {
|
|
456
|
+
const examples = await this.listExamples({ datasetName });
|
|
368
457
|
let sessionName_;
|
|
369
458
|
if (sessionName === undefined) {
|
|
370
459
|
const currentTime = new Date().toISOString();
|
|
@@ -382,17 +471,19 @@ export class LangChainPlusClient {
|
|
|
382
471
|
});
|
|
383
472
|
if (modelOrFactoryType === "llm") {
|
|
384
473
|
const llm = llmOrChainFactory;
|
|
385
|
-
const llmResult = await this.runLLM(example, tracer, llm,
|
|
474
|
+
const llmResult = await this.runLLM(example, tracer, llm, {
|
|
475
|
+
numRepetitions,
|
|
476
|
+
});
|
|
386
477
|
results[example.id] = llmResult;
|
|
387
478
|
}
|
|
388
479
|
else if (modelOrFactoryType === "chainFactory") {
|
|
389
480
|
const chainFactory = llmOrChainFactory;
|
|
390
|
-
const chainResult = await this.runChain(example, tracer, chainFactory, numRepetitions);
|
|
481
|
+
const chainResult = await this.runChain(example, tracer, chainFactory, { numRepetitions });
|
|
391
482
|
results[example.id] = chainResult;
|
|
392
483
|
}
|
|
393
484
|
else if (modelOrFactoryType === "chatModel") {
|
|
394
485
|
const chatModel = llmOrChainFactory;
|
|
395
|
-
const chatModelResult = await this.runChatModel(example, tracer, chatModel, numRepetitions);
|
|
486
|
+
const chatModelResult = await this.runChatModel(example, tracer, chatModel, { numRepetitions });
|
|
396
487
|
results[example.id] = chatModelResult;
|
|
397
488
|
}
|
|
398
489
|
else {
|
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isChatModel = exports.isLLM = exports.ConditionalPromptSelector = exports.BasePromptSelector = void 0;
|
|
4
4
|
class BasePromptSelector {
|
|
5
|
+
async getPromptAsync(llm, options) {
|
|
6
|
+
const prompt = this.getPrompt(llm);
|
|
7
|
+
return prompt.partial(options?.partialVariables ?? {});
|
|
8
|
+
}
|
|
5
9
|
}
|
|
6
10
|
exports.BasePromptSelector = BasePromptSelector;
|
|
7
11
|
class ConditionalPromptSelector extends BasePromptSelector {
|
|
@@ -2,8 +2,13 @@ import { BaseChatModel } from "../../chat_models/base.js";
|
|
|
2
2
|
import { BasePromptTemplate } from "../base.js";
|
|
3
3
|
import { BaseLanguageModel } from "../../base_language/index.js";
|
|
4
4
|
import { BaseLLM } from "../../llms/base.js";
|
|
5
|
+
import { PartialValues } from "../../schema/index.js";
|
|
6
|
+
export type BaseGetPromptAsyncOptions = {
|
|
7
|
+
partialVariables?: PartialValues;
|
|
8
|
+
};
|
|
5
9
|
export declare abstract class BasePromptSelector {
|
|
6
10
|
abstract getPrompt(llm: BaseLanguageModel): BasePromptTemplate;
|
|
11
|
+
getPromptAsync(llm: BaseLanguageModel, options?: BaseGetPromptAsyncOptions): Promise<BasePromptTemplate>;
|
|
7
12
|
}
|
|
8
13
|
export declare class ConditionalPromptSelector extends BasePromptSelector {
|
|
9
14
|
defaultPrompt: BasePromptTemplate;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
export class BasePromptSelector {
|
|
2
|
+
async getPromptAsync(llm, options) {
|
|
3
|
+
const prompt = this.getPrompt(llm);
|
|
4
|
+
return prompt.partial(options?.partialVariables ?? {});
|
|
5
|
+
}
|
|
2
6
|
}
|
|
3
7
|
export class ConditionalPromptSelector extends BasePromptSelector {
|
|
4
8
|
constructor(default_prompt, conditionals = []) {
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import Metal from "@getmetal/metal-sdk";
|
|
1
2
|
import { BaseRetriever } from "../schema/index.js";
|
|
2
3
|
import { Document } from "../document.js";
|
|
3
4
|
export interface MetalRetrieverFields {
|
|
4
|
-
client:
|
|
5
|
+
client: Metal;
|
|
5
6
|
}
|
|
6
7
|
export declare class MetalRetriever extends BaseRetriever {
|
|
7
8
|
private client;
|
|
@@ -42,16 +42,7 @@ class RedisChatMessageHistory extends index_js_1.BaseListChatMessageHistory {
|
|
|
42
42
|
const orderedMessages = rawStoredMessages
|
|
43
43
|
.reverse()
|
|
44
44
|
.map((message) => JSON.parse(message));
|
|
45
|
-
|
|
46
|
-
.map((item) => ({
|
|
47
|
-
type: item.type,
|
|
48
|
-
data: {
|
|
49
|
-
role: item.role,
|
|
50
|
-
content: item.text,
|
|
51
|
-
},
|
|
52
|
-
}))
|
|
53
|
-
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
54
|
-
return (0, utils_js_1.mapStoredMessagesToChatMessages)(previousMessages);
|
|
45
|
+
return (0, utils_js_1.mapStoredMessagesToChatMessages)(orderedMessages);
|
|
55
46
|
}
|
|
56
47
|
async addMessage(message) {
|
|
57
48
|
await this.ensureReadiness();
|
|
@@ -39,16 +39,7 @@ export class RedisChatMessageHistory extends BaseListChatMessageHistory {
|
|
|
39
39
|
const orderedMessages = rawStoredMessages
|
|
40
40
|
.reverse()
|
|
41
41
|
.map((message) => JSON.parse(message));
|
|
42
|
-
|
|
43
|
-
.map((item) => ({
|
|
44
|
-
type: item.type,
|
|
45
|
-
data: {
|
|
46
|
-
role: item.role,
|
|
47
|
-
content: item.text,
|
|
48
|
-
},
|
|
49
|
-
}))
|
|
50
|
-
.filter((x) => x.type !== undefined && x.data.content !== undefined);
|
|
51
|
-
return mapStoredMessagesToChatMessages(previousMessages);
|
|
42
|
+
return mapStoredMessagesToChatMessages(orderedMessages);
|
|
52
43
|
}
|
|
53
44
|
async addMessage(message) {
|
|
54
45
|
await this.ensureReadiness();
|
|
@@ -85,24 +85,6 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
85
85
|
writable: true,
|
|
86
86
|
value: void 0
|
|
87
87
|
});
|
|
88
|
-
Object.defineProperty(this, "colMgr", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
configurable: true,
|
|
91
|
-
writable: true,
|
|
92
|
-
value: void 0
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(this, "idxMgr", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
configurable: true,
|
|
97
|
-
writable: true,
|
|
98
|
-
value: void 0
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(this, "dataMgr", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
configurable: true,
|
|
103
|
-
writable: true,
|
|
104
|
-
value: void 0
|
|
105
|
-
});
|
|
106
88
|
Object.defineProperty(this, "indexParams", {
|
|
107
89
|
enumerable: true,
|
|
108
90
|
configurable: true,
|
|
@@ -149,9 +131,6 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
149
131
|
throw new Error("Milvus URL address is not provided.");
|
|
150
132
|
}
|
|
151
133
|
this.client = new milvus2_sdk_node_1.MilvusClient(url, args.ssl, args.username, args.password);
|
|
152
|
-
this.colMgr = this.client.collectionManager;
|
|
153
|
-
this.idxMgr = this.client.indexManager;
|
|
154
|
-
this.dataMgr = this.client.dataManager;
|
|
155
134
|
}
|
|
156
135
|
async addDocuments(documents) {
|
|
157
136
|
const texts = documents.map(({ pageContent }) => pageContent);
|
|
@@ -202,17 +181,17 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
202
181
|
});
|
|
203
182
|
insertDatas.push(data);
|
|
204
183
|
}
|
|
205
|
-
const insertResp = await this.
|
|
184
|
+
const insertResp = await this.client.insert({
|
|
206
185
|
collection_name: this.collectionName,
|
|
207
186
|
fields_data: insertDatas,
|
|
208
187
|
});
|
|
209
188
|
if (insertResp.status.error_code !== types_js_1.ErrorCode.SUCCESS) {
|
|
210
189
|
throw new Error(`Error inserting data: ${JSON.stringify(insertResp)}`);
|
|
211
190
|
}
|
|
212
|
-
await this.
|
|
191
|
+
await this.client.flushSync({ collection_names: [this.collectionName] });
|
|
213
192
|
}
|
|
214
193
|
async similaritySearchVectorWithScore(query, k) {
|
|
215
|
-
const hasColResp = await this.
|
|
194
|
+
const hasColResp = await this.client.hasCollection({
|
|
216
195
|
collection_name: this.collectionName,
|
|
217
196
|
});
|
|
218
197
|
if (hasColResp.status.error_code !== types_js_1.ErrorCode.SUCCESS) {
|
|
@@ -222,7 +201,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
222
201
|
throw new Error(`Collection not found: ${this.collectionName}, please create collection before search.`);
|
|
223
202
|
}
|
|
224
203
|
await this.grabCollectionFields();
|
|
225
|
-
const loadResp = await this.
|
|
204
|
+
const loadResp = await this.client.loadCollectionSync({
|
|
226
205
|
collection_name: this.collectionName,
|
|
227
206
|
});
|
|
228
207
|
if (loadResp.error_code !== types_js_1.ErrorCode.SUCCESS) {
|
|
@@ -230,7 +209,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
230
209
|
}
|
|
231
210
|
// clone this.field and remove vectorField
|
|
232
211
|
const outputFields = this.fields.filter((field) => field !== this.vectorField);
|
|
233
|
-
const searchResp = await this.
|
|
212
|
+
const searchResp = await this.client.search({
|
|
234
213
|
collection_name: this.collectionName,
|
|
235
214
|
search_params: {
|
|
236
215
|
anns_field: this.vectorField,
|
|
@@ -269,7 +248,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
269
248
|
return results;
|
|
270
249
|
}
|
|
271
250
|
async ensureCollection(vectors, documents) {
|
|
272
|
-
const hasColResp = await this.
|
|
251
|
+
const hasColResp = await this.client.hasCollection({
|
|
273
252
|
collection_name: this.collectionName,
|
|
274
253
|
});
|
|
275
254
|
if (hasColResp.status.error_code !== types_js_1.ErrorCode.SUCCESS) {
|
|
@@ -314,7 +293,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
314
293
|
this.fields.push(field.name);
|
|
315
294
|
}
|
|
316
295
|
});
|
|
317
|
-
const createRes = await this.
|
|
296
|
+
const createRes = await this.client.createCollection({
|
|
318
297
|
collection_name: this.collectionName,
|
|
319
298
|
fields: fieldList,
|
|
320
299
|
});
|
|
@@ -322,7 +301,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
322
301
|
console.log(createRes);
|
|
323
302
|
throw new Error(`Failed to create collection: ${createRes}`);
|
|
324
303
|
}
|
|
325
|
-
await this.
|
|
304
|
+
await this.client.createIndex({
|
|
326
305
|
collection_name: this.collectionName,
|
|
327
306
|
field_name: this.vectorField,
|
|
328
307
|
extra_params: this.indexCreateParams,
|
|
@@ -338,7 +317,7 @@ class Milvus extends base_js_1.VectorStore {
|
|
|
338
317
|
this.fields.length > 0) {
|
|
339
318
|
return;
|
|
340
319
|
}
|
|
341
|
-
const desc = await this.
|
|
320
|
+
const desc = await this.client.describeCollection({
|
|
342
321
|
collection_name: this.collectionName,
|
|
343
322
|
});
|
|
344
323
|
desc.schema.fields.forEach((field) => {
|
|
@@ -29,9 +29,6 @@ export declare class Milvus extends VectorStore {
|
|
|
29
29
|
textField: string;
|
|
30
30
|
fields: string[];
|
|
31
31
|
client: MilvusClient;
|
|
32
|
-
colMgr: MilvusClient["collectionManager"];
|
|
33
|
-
idxMgr: MilvusClient["indexManager"];
|
|
34
|
-
dataMgr: MilvusClient["dataManager"];
|
|
35
32
|
indexParams: Record<IndexType, IndexParam>;
|
|
36
33
|
indexCreateParams: {
|
|
37
34
|
index_type: string;
|