langchain 0.0.146 → 0.0.148
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/chat_models/googlevertexai/web.cjs +1 -0
- package/chat_models/googlevertexai/web.d.ts +1 -0
- package/chat_models/googlevertexai/web.js +1 -0
- package/chat_models/googlevertexai.cjs +1 -1
- package/chat_models/googlevertexai.d.ts +1 -1
- package/chat_models/googlevertexai.js +1 -1
- package/dist/base_language/index.cjs +2 -2
- package/dist/base_language/index.d.ts +2 -1
- package/dist/base_language/index.js +1 -1
- package/dist/chains/base.d.ts +1 -1
- package/dist/chains/constitutional_ai/constitutional_principle.cjs +272 -1
- package/dist/chains/constitutional_ai/constitutional_principle.js +272 -1
- package/dist/chains/openai_functions/openapi.cjs +32 -27
- package/dist/chains/openai_functions/openapi.d.ts +9 -0
- package/dist/chains/openai_functions/openapi.js +31 -27
- package/dist/chat_models/base.d.ts +1 -1
- package/dist/chat_models/{googlevertexai.cjs → googlevertexai/common.cjs} +14 -26
- package/dist/chat_models/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -22
- package/dist/chat_models/{googlevertexai.js → googlevertexai/common.js} +12 -24
- package/dist/chat_models/googlevertexai/index.cjs +36 -0
- package/dist/chat_models/googlevertexai/index.d.ts +21 -0
- package/dist/chat_models/googlevertexai/index.js +31 -0
- package/dist/chat_models/googlevertexai/web.cjs +33 -0
- package/dist/chat_models/googlevertexai/web.d.ts +19 -0
- package/dist/chat_models/googlevertexai/web.js +28 -0
- package/dist/chat_models/openai.cjs +1 -1
- package/dist/chat_models/openai.js +1 -1
- package/dist/document_loaders/web/notionapi.cjs +93 -70
- package/dist/document_loaders/web/notionapi.d.ts +33 -1
- package/dist/document_loaders/web/notionapi.js +89 -71
- package/dist/embeddings/googlevertexai.cjs +5 -1
- package/dist/embeddings/googlevertexai.d.ts +2 -1
- package/dist/embeddings/googlevertexai.js +5 -1
- package/dist/evaluation/agents/index.cjs +17 -0
- package/dist/evaluation/agents/index.d.ts +1 -0
- package/dist/evaluation/agents/index.js +1 -0
- package/dist/evaluation/agents/prompt.cjs +132 -0
- package/dist/evaluation/agents/prompt.d.ts +6 -0
- package/dist/evaluation/agents/prompt.js +129 -0
- package/dist/evaluation/agents/trajectory.cjs +189 -0
- package/dist/evaluation/agents/trajectory.d.ts +54 -0
- package/dist/evaluation/agents/trajectory.js +184 -0
- package/dist/evaluation/base.cjs +274 -0
- package/dist/evaluation/base.d.ts +232 -0
- package/dist/evaluation/base.js +263 -0
- package/dist/evaluation/comparison/index.cjs +17 -0
- package/dist/evaluation/comparison/index.d.ts +1 -0
- package/dist/evaluation/comparison/index.js +1 -0
- package/dist/evaluation/comparison/pairwise.cjs +244 -0
- package/dist/evaluation/comparison/pairwise.d.ts +50 -0
- package/dist/evaluation/comparison/pairwise.js +238 -0
- package/dist/evaluation/comparison/prompt.cjs +74 -0
- package/dist/evaluation/comparison/prompt.d.ts +21 -0
- package/dist/evaluation/comparison/prompt.js +71 -0
- package/dist/evaluation/criteria/criteria.cjs +259 -0
- package/dist/evaluation/criteria/criteria.d.ts +73 -0
- package/dist/evaluation/criteria/criteria.js +253 -0
- package/dist/evaluation/criteria/index.cjs +17 -0
- package/dist/evaluation/criteria/index.d.ts +1 -0
- package/dist/evaluation/criteria/index.js +1 -0
- package/dist/evaluation/criteria/prompt.cjs +36 -0
- package/dist/evaluation/criteria/prompt.d.ts +12 -0
- package/dist/evaluation/criteria/prompt.js +33 -0
- package/dist/evaluation/embedding_distance/base.cjs +163 -0
- package/dist/evaluation/embedding_distance/base.d.ts +78 -0
- package/dist/evaluation/embedding_distance/base.js +156 -0
- package/dist/evaluation/embedding_distance/index.cjs +17 -0
- package/dist/evaluation/embedding_distance/index.d.ts +1 -0
- package/dist/evaluation/embedding_distance/index.js +1 -0
- package/dist/evaluation/index.cjs +6 -0
- package/dist/evaluation/index.d.ts +6 -0
- package/dist/evaluation/index.js +6 -0
- package/dist/evaluation/loader.cjs +60 -0
- package/dist/evaluation/loader.d.ts +27 -0
- package/dist/evaluation/loader.js +56 -0
- package/dist/evaluation/types.cjs +2 -0
- package/dist/evaluation/types.d.ts +35 -0
- package/dist/evaluation/types.js +1 -0
- package/dist/experimental/llms/bittensor.cjs +141 -0
- package/dist/experimental/llms/bittensor.d.ts +33 -0
- package/dist/experimental/llms/bittensor.js +137 -0
- package/dist/experimental/multimodal_embeddings/googlevertexai.cjs +5 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.d.ts +2 -1
- package/dist/experimental/multimodal_embeddings/googlevertexai.js +5 -1
- package/dist/hub.d.ts +1 -1
- package/dist/llms/base.d.ts +1 -1
- package/dist/llms/{googlevertexai.js → googlevertexai/common.cjs} +21 -17
- package/dist/llms/{googlevertexai.d.ts → googlevertexai/common.d.ts} +13 -23
- package/dist/llms/{googlevertexai.cjs → googlevertexai/common.js} +17 -21
- package/dist/llms/googlevertexai/index.cjs +34 -0
- package/dist/llms/googlevertexai/index.d.ts +26 -0
- package/dist/llms/googlevertexai/index.js +30 -0
- package/dist/llms/googlevertexai/web.cjs +31 -0
- package/dist/llms/googlevertexai/web.d.ts +24 -0
- package/dist/llms/googlevertexai/web.js +27 -0
- package/dist/llms/openai-chat.cjs +1 -1
- package/dist/llms/openai-chat.js +1 -1
- package/dist/llms/openai.cjs +1 -1
- package/dist/llms/openai.js +1 -1
- package/dist/load/import_constants.cjs +3 -0
- package/dist/load/import_constants.js +3 -0
- package/dist/load/import_map.cjs +3 -2
- package/dist/load/import_map.d.ts +2 -1
- package/dist/load/import_map.js +2 -1
- package/dist/load/index.cjs +2 -1
- package/dist/load/index.js +2 -1
- package/dist/load/serializable.cjs +23 -4
- package/dist/load/serializable.js +23 -4
- package/dist/prompts/base.cjs +2 -2
- package/dist/prompts/base.d.ts +1 -1
- package/dist/prompts/base.js +1 -1
- package/dist/prompts/chat.cjs +2 -2
- package/dist/prompts/chat.d.ts +1 -1
- package/dist/prompts/chat.js +1 -1
- package/dist/retrievers/multi_query.cjs +140 -0
- package/dist/retrievers/multi_query.d.ts +33 -0
- package/dist/retrievers/multi_query.js +136 -0
- package/dist/schema/document.cjs +2 -2
- package/dist/schema/document.d.ts +1 -1
- package/dist/schema/document.js +1 -1
- package/dist/schema/output_parser.cjs +2 -2
- package/dist/schema/output_parser.d.ts +2 -1
- package/dist/schema/output_parser.js +1 -1
- package/dist/schema/retriever.cjs +2 -2
- package/dist/schema/retriever.d.ts +2 -1
- package/dist/schema/retriever.js +1 -1
- package/dist/schema/runnable/config.cjs +8 -0
- package/dist/schema/runnable/config.d.ts +3 -0
- package/dist/schema/runnable/config.js +4 -0
- package/dist/schema/{runnable.cjs → runnable/index.cjs} +290 -101
- package/dist/schema/{runnable.d.ts → runnable/index.d.ts} +127 -41
- package/dist/schema/{runnable.js → runnable/index.js} +284 -99
- package/dist/tools/base.d.ts +1 -1
- package/dist/types/googlevertexai-types.d.ts +11 -4
- package/dist/util/async_caller.cjs +35 -25
- package/dist/util/async_caller.d.ts +8 -0
- package/dist/util/async_caller.js +35 -25
- package/dist/util/googlevertexai-connection.cjs +14 -15
- package/dist/util/googlevertexai-connection.d.ts +7 -7
- package/dist/util/googlevertexai-connection.js +14 -15
- package/dist/util/googlevertexai-webauth.cjs +56 -0
- package/dist/util/googlevertexai-webauth.d.ts +25 -0
- package/dist/util/googlevertexai-webauth.js +52 -0
- package/dist/vectorstores/googlevertexai.cjs +9 -8
- package/dist/vectorstores/googlevertexai.d.ts +8 -7
- package/dist/vectorstores/googlevertexai.js +9 -8
- package/dist/vectorstores/pinecone.cjs +30 -22
- package/dist/vectorstores/pinecone.d.ts +3 -1
- package/dist/vectorstores/pinecone.js +30 -22
- package/dist/vectorstores/vectara.cjs +20 -23
- package/dist/vectorstores/vectara.d.ts +9 -2
- package/dist/vectorstores/vectara.js +20 -23
- package/experimental/llms/bittensor.cjs +1 -0
- package/experimental/llms/bittensor.d.ts +1 -0
- package/experimental/llms/bittensor.js +1 -0
- package/llms/googlevertexai/web.cjs +1 -0
- package/llms/googlevertexai/web.d.ts +1 -0
- package/llms/googlevertexai/web.js +1 -0
- package/llms/googlevertexai.cjs +1 -1
- package/llms/googlevertexai.d.ts +1 -1
- package/llms/googlevertexai.js +1 -1
- package/package.json +40 -3
- package/retrievers/multi_query.cjs +1 -0
- package/retrievers/multi_query.d.ts +1 -0
- package/retrievers/multi_query.js +1 -0
- package/schema/runnable.cjs +1 -1
- package/schema/runnable.d.ts +1 -1
- package/schema/runnable.js +1 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleVertexAI = void 0;
|
|
4
|
+
const google_auth_library_1 = require("google-auth-library");
|
|
5
|
+
const googlevertexai_connection_js_1 = require("../../util/googlevertexai-connection.cjs");
|
|
6
|
+
const common_js_1 = require("./common.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
9
|
+
* Large Language Models.
|
|
10
|
+
*
|
|
11
|
+
* To use, you will need to have one of the following authentication
|
|
12
|
+
* methods in place:
|
|
13
|
+
* - You are logged into an account permitted to the Google Cloud project
|
|
14
|
+
* using Vertex AI.
|
|
15
|
+
* - You are running this on a machine using a service account permitted to
|
|
16
|
+
* the Google Cloud project using Vertex AI.
|
|
17
|
+
* - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
|
|
18
|
+
* path of a credentials file for a service account permitted to the
|
|
19
|
+
* Google Cloud project using Vertex AI.
|
|
20
|
+
*/
|
|
21
|
+
class GoogleVertexAI extends common_js_1.BaseGoogleVertexAI {
|
|
22
|
+
static lc_name() {
|
|
23
|
+
return "VertexAI";
|
|
24
|
+
}
|
|
25
|
+
constructor(fields) {
|
|
26
|
+
super(fields);
|
|
27
|
+
const client = new google_auth_library_1.GoogleAuth({
|
|
28
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
29
|
+
...fields?.authOptions,
|
|
30
|
+
});
|
|
31
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
exports.GoogleVertexAI = GoogleVertexAI;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { GoogleAuthOptions } from "google-auth-library";
|
|
2
|
+
import { GoogleVertexAIBaseLLMInput } from "../../types/googlevertexai-types.js";
|
|
3
|
+
import { BaseGoogleVertexAI } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Interface representing the input to the Google Vertex AI model.
|
|
6
|
+
*/
|
|
7
|
+
export interface GoogleVertexAITextInput extends GoogleVertexAIBaseLLMInput<GoogleAuthOptions> {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
11
|
+
* Large Language Models.
|
|
12
|
+
*
|
|
13
|
+
* To use, you will need to have one of the following authentication
|
|
14
|
+
* methods in place:
|
|
15
|
+
* - You are logged into an account permitted to the Google Cloud project
|
|
16
|
+
* using Vertex AI.
|
|
17
|
+
* - You are running this on a machine using a service account permitted to
|
|
18
|
+
* the Google Cloud project using Vertex AI.
|
|
19
|
+
* - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
|
|
20
|
+
* path of a credentials file for a service account permitted to the
|
|
21
|
+
* Google Cloud project using Vertex AI.
|
|
22
|
+
*/
|
|
23
|
+
export declare class GoogleVertexAI extends BaseGoogleVertexAI<GoogleAuthOptions> {
|
|
24
|
+
static lc_name(): string;
|
|
25
|
+
constructor(fields?: GoogleVertexAITextInput);
|
|
26
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { GoogleAuth } from "google-auth-library";
|
|
2
|
+
import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
|
|
3
|
+
import { BaseGoogleVertexAI } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
6
|
+
* Large Language Models.
|
|
7
|
+
*
|
|
8
|
+
* To use, you will need to have one of the following authentication
|
|
9
|
+
* methods in place:
|
|
10
|
+
* - You are logged into an account permitted to the Google Cloud project
|
|
11
|
+
* using Vertex AI.
|
|
12
|
+
* - You are running this on a machine using a service account permitted to
|
|
13
|
+
* the Google Cloud project using Vertex AI.
|
|
14
|
+
* - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
|
|
15
|
+
* path of a credentials file for a service account permitted to the
|
|
16
|
+
* Google Cloud project using Vertex AI.
|
|
17
|
+
*/
|
|
18
|
+
export class GoogleVertexAI extends BaseGoogleVertexAI {
|
|
19
|
+
static lc_name() {
|
|
20
|
+
return "VertexAI";
|
|
21
|
+
}
|
|
22
|
+
constructor(fields) {
|
|
23
|
+
super(fields);
|
|
24
|
+
const client = new GoogleAuth({
|
|
25
|
+
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
26
|
+
...fields?.authOptions,
|
|
27
|
+
});
|
|
28
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GoogleVertexAI = void 0;
|
|
4
|
+
const googlevertexai_webauth_js_1 = require("../../util/googlevertexai-webauth.cjs");
|
|
5
|
+
const googlevertexai_connection_js_1 = require("../../util/googlevertexai-connection.cjs");
|
|
6
|
+
const common_js_1 = require("./common.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
9
|
+
* Large Language Models.
|
|
10
|
+
*
|
|
11
|
+
* This entrypoint and class are intended to be used in web environments like Edge
|
|
12
|
+
* functions where you do not have access to the file system. It supports passing
|
|
13
|
+
* service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
|
|
14
|
+
* environment variable or directly as "authOptions.credentials".
|
|
15
|
+
*/
|
|
16
|
+
class GoogleVertexAI extends common_js_1.BaseGoogleVertexAI {
|
|
17
|
+
static lc_name() {
|
|
18
|
+
return "VertexAI";
|
|
19
|
+
}
|
|
20
|
+
get lc_secrets() {
|
|
21
|
+
return {
|
|
22
|
+
"authOptions.credentials": "GOOGLE_VERTEX_AI_WEB_CREDENTIALS",
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
constructor(fields) {
|
|
26
|
+
super(fields);
|
|
27
|
+
const client = new googlevertexai_webauth_js_1.WebGoogleAuth(fields?.authOptions);
|
|
28
|
+
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.GoogleVertexAI = GoogleVertexAI;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WebGoogleAuthOptions } from "../../util/googlevertexai-webauth.js";
|
|
2
|
+
import { GoogleVertexAIBaseLLMInput } from "../../types/googlevertexai-types.js";
|
|
3
|
+
import { BaseGoogleVertexAI } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Interface representing the input to the Google Vertex AI model.
|
|
6
|
+
*/
|
|
7
|
+
export interface GoogleVertexAITextInput extends GoogleVertexAIBaseLLMInput<WebGoogleAuthOptions> {
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
11
|
+
* Large Language Models.
|
|
12
|
+
*
|
|
13
|
+
* This entrypoint and class are intended to be used in web environments like Edge
|
|
14
|
+
* functions where you do not have access to the file system. It supports passing
|
|
15
|
+
* service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
|
|
16
|
+
* environment variable or directly as "authOptions.credentials".
|
|
17
|
+
*/
|
|
18
|
+
export declare class GoogleVertexAI extends BaseGoogleVertexAI<WebGoogleAuthOptions> {
|
|
19
|
+
static lc_name(): string;
|
|
20
|
+
get lc_secrets(): {
|
|
21
|
+
[key: string]: string;
|
|
22
|
+
};
|
|
23
|
+
constructor(fields?: GoogleVertexAITextInput);
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { WebGoogleAuth, } from "../../util/googlevertexai-webauth.js";
|
|
2
|
+
import { GoogleVertexAILLMConnection } from "../../util/googlevertexai-connection.js";
|
|
3
|
+
import { BaseGoogleVertexAI } from "./common.js";
|
|
4
|
+
/**
|
|
5
|
+
* Enables calls to the Google Cloud's Vertex AI API to access
|
|
6
|
+
* Large Language Models.
|
|
7
|
+
*
|
|
8
|
+
* This entrypoint and class are intended to be used in web environments like Edge
|
|
9
|
+
* functions where you do not have access to the file system. It supports passing
|
|
10
|
+
* service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
|
|
11
|
+
* environment variable or directly as "authOptions.credentials".
|
|
12
|
+
*/
|
|
13
|
+
export class GoogleVertexAI extends BaseGoogleVertexAI {
|
|
14
|
+
static lc_name() {
|
|
15
|
+
return "VertexAI";
|
|
16
|
+
}
|
|
17
|
+
get lc_secrets() {
|
|
18
|
+
return {
|
|
19
|
+
"authOptions.credentials": "GOOGLE_VERTEX_AI_WEB_CREDENTIALS",
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
constructor(fields) {
|
|
23
|
+
super(fields);
|
|
24
|
+
const client = new WebGoogleAuth(fields?.authOptions);
|
|
25
|
+
this.connection = new GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller, client);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -330,7 +330,7 @@ class OpenAIChat extends base_js_1.LLM {
|
|
|
330
330
|
};
|
|
331
331
|
const stream = await this.completionWithRetry(params, options);
|
|
332
332
|
for await (const data of stream) {
|
|
333
|
-
const choice = data
|
|
333
|
+
const choice = data?.choices[0];
|
|
334
334
|
if (!choice) {
|
|
335
335
|
continue;
|
|
336
336
|
}
|
package/dist/llms/openai-chat.js
CHANGED
|
@@ -327,7 +327,7 @@ export class OpenAIChat extends LLM {
|
|
|
327
327
|
};
|
|
328
328
|
const stream = await this.completionWithRetry(params, options);
|
|
329
329
|
for await (const data of stream) {
|
|
330
|
-
const choice = data
|
|
330
|
+
const choice = data?.choices[0];
|
|
331
331
|
if (!choice) {
|
|
332
332
|
continue;
|
|
333
333
|
}
|
package/dist/llms/openai.cjs
CHANGED
|
@@ -436,7 +436,7 @@ class OpenAI extends base_js_1.BaseLLM {
|
|
|
436
436
|
};
|
|
437
437
|
const stream = await this.completionWithRetry(params, options);
|
|
438
438
|
for await (const data of stream) {
|
|
439
|
-
const choice = data
|
|
439
|
+
const choice = data?.choices[0];
|
|
440
440
|
if (!choice) {
|
|
441
441
|
continue;
|
|
442
442
|
}
|
package/dist/llms/openai.js
CHANGED
|
@@ -433,7 +433,7 @@ export class OpenAI extends BaseLLM {
|
|
|
433
433
|
};
|
|
434
434
|
const stream = await this.completionWithRetry(params, options);
|
|
435
435
|
for await (const data of stream) {
|
|
436
|
-
const choice = data
|
|
436
|
+
const choice = data?.choices[0];
|
|
437
437
|
if (!choice) {
|
|
438
438
|
continue;
|
|
439
439
|
}
|
|
@@ -27,6 +27,7 @@ exports.optionalImportEntrypoints = [
|
|
|
27
27
|
"langchain/llms/raycast",
|
|
28
28
|
"langchain/llms/replicate",
|
|
29
29
|
"langchain/llms/googlevertexai",
|
|
30
|
+
"langchain/llms/googlevertexai/web",
|
|
30
31
|
"langchain/llms/googlepalm",
|
|
31
32
|
"langchain/llms/sagemaker_endpoint",
|
|
32
33
|
"langchain/llms/bedrock",
|
|
@@ -93,6 +94,7 @@ exports.optionalImportEntrypoints = [
|
|
|
93
94
|
"langchain/document_transformers/html_to_text",
|
|
94
95
|
"langchain/document_transformers/mozilla_readability",
|
|
95
96
|
"langchain/chat_models/googlevertexai",
|
|
97
|
+
"langchain/chat_models/googlevertexai/web",
|
|
96
98
|
"langchain/chat_models/googlepalm",
|
|
97
99
|
"langchain/sql_db",
|
|
98
100
|
"langchain/callbacks/handlers/llmonitor",
|
|
@@ -126,4 +128,5 @@ exports.optionalImportEntrypoints = [
|
|
|
126
128
|
"langchain/hub",
|
|
127
129
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
128
130
|
"langchain/experimental/chat_models/anthropic_functions",
|
|
131
|
+
"langchain/experimental/llms/bittensor",
|
|
129
132
|
];
|
|
@@ -24,6 +24,7 @@ export const optionalImportEntrypoints = [
|
|
|
24
24
|
"langchain/llms/raycast",
|
|
25
25
|
"langchain/llms/replicate",
|
|
26
26
|
"langchain/llms/googlevertexai",
|
|
27
|
+
"langchain/llms/googlevertexai/web",
|
|
27
28
|
"langchain/llms/googlepalm",
|
|
28
29
|
"langchain/llms/sagemaker_endpoint",
|
|
29
30
|
"langchain/llms/bedrock",
|
|
@@ -90,6 +91,7 @@ export const optionalImportEntrypoints = [
|
|
|
90
91
|
"langchain/document_transformers/html_to_text",
|
|
91
92
|
"langchain/document_transformers/mozilla_readability",
|
|
92
93
|
"langchain/chat_models/googlevertexai",
|
|
94
|
+
"langchain/chat_models/googlevertexai/web",
|
|
93
95
|
"langchain/chat_models/googlepalm",
|
|
94
96
|
"langchain/sql_db",
|
|
95
97
|
"langchain/callbacks/handlers/llmonitor",
|
|
@@ -123,4 +125,5 @@ export const optionalImportEntrypoints = [
|
|
|
123
125
|
"langchain/hub",
|
|
124
126
|
"langchain/experimental/multimodal_embeddings/googlevertexai",
|
|
125
127
|
"langchain/experimental/chat_models/anthropic_functions",
|
|
128
|
+
"langchain/experimental/llms/bittensor",
|
|
126
129
|
];
|
package/dist/load/import_map.cjs
CHANGED
|
@@ -25,7 +25,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
};
|
|
26
26
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
27
|
exports.retrievers__document_compressors = exports.retrievers__contextual_compression = exports.retrievers__databerry = exports.retrievers__remote = exports.output_parsers = exports.callbacks = exports.schema__storage = exports.schema__runnable = exports.schema__retriever = exports.schema__query_constructor = exports.schema__output_parser = exports.schema__document = exports.schema = exports.chat_models__minimax = exports.chat_models__ollama = exports.chat_models__baiduwenxin = exports.chat_models__anthropic = exports.chat_models__openai = exports.chat_models__base = exports.document_transformers__openai_functions = exports.document_loaders__web__sort_xyz_blockchain = exports.document_loaders__web__serpapi = exports.document_loaders__base = exports.document = exports.memory = exports.text_splitter = exports.vectorstores__xata = exports.vectorstores__vectara = exports.vectorstores__prisma = exports.vectorstores__memory = exports.vectorstores__base = exports.prompts = exports.llms__ollama = exports.llms__aleph_alpha = exports.llms__ai21 = exports.llms__openai = exports.llms__base = exports.embeddings__minimax = exports.embeddings__openai = exports.embeddings__ollama = exports.embeddings__fake = exports.embeddings__cache_backed = exports.embeddings__base = exports.chains__openai_functions = exports.chains = exports.tools = exports.base_language = exports.agents__toolkits = exports.agents = exports.load__serializable = void 0;
|
|
28
|
-
exports.evaluation = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = void 0;
|
|
28
|
+
exports.evaluation = exports.experimental__plan_and_execute = exports.experimental__generative_agents = exports.experimental__babyagi = exports.experimental__autogpt = exports.util__math = exports.storage__in_memory = exports.stores__message__in_memory = exports.stores__file__in_memory = exports.stores__doc__in_memory = exports.cache = exports.retrievers__vespa = exports.retrievers__score_threshold = exports.retrievers__hyde = exports.retrievers__document_compressors__chain_extract = exports.retrievers__time_weighted = exports.retrievers__parent_document = exports.retrievers__multi_vector = exports.retrievers__multi_query = void 0;
|
|
29
29
|
exports.load__serializable = __importStar(require("../load/serializable.cjs"));
|
|
30
30
|
exports.agents = __importStar(require("../agents/index.cjs"));
|
|
31
31
|
exports.agents__toolkits = __importStar(require("../agents/toolkits/index.cjs"));
|
|
@@ -68,7 +68,7 @@ exports.schema__document = __importStar(require("../schema/document.cjs"));
|
|
|
68
68
|
exports.schema__output_parser = __importStar(require("../schema/output_parser.cjs"));
|
|
69
69
|
exports.schema__query_constructor = __importStar(require("../schema/query_constructor.cjs"));
|
|
70
70
|
exports.schema__retriever = __importStar(require("../schema/retriever.cjs"));
|
|
71
|
-
exports.schema__runnable = __importStar(require("../schema/runnable.cjs"));
|
|
71
|
+
exports.schema__runnable = __importStar(require("../schema/runnable/index.cjs"));
|
|
72
72
|
exports.schema__storage = __importStar(require("../schema/storage.cjs"));
|
|
73
73
|
exports.callbacks = __importStar(require("../callbacks/index.cjs"));
|
|
74
74
|
exports.output_parsers = __importStar(require("../output_parsers/index.cjs"));
|
|
@@ -76,6 +76,7 @@ exports.retrievers__remote = __importStar(require("../retrievers/remote/index.cj
|
|
|
76
76
|
exports.retrievers__databerry = __importStar(require("../retrievers/databerry.cjs"));
|
|
77
77
|
exports.retrievers__contextual_compression = __importStar(require("../retrievers/contextual_compression.cjs"));
|
|
78
78
|
exports.retrievers__document_compressors = __importStar(require("../retrievers/document_compressors/index.cjs"));
|
|
79
|
+
exports.retrievers__multi_query = __importStar(require("../retrievers/multi_query.cjs"));
|
|
79
80
|
exports.retrievers__multi_vector = __importStar(require("../retrievers/multi_vector.cjs"));
|
|
80
81
|
exports.retrievers__parent_document = __importStar(require("../retrievers/parent_document.cjs"));
|
|
81
82
|
exports.retrievers__time_weighted = __importStar(require("../retrievers/time_weighted.cjs"));
|
|
@@ -40,7 +40,7 @@ export * as schema__document from "../schema/document.js";
|
|
|
40
40
|
export * as schema__output_parser from "../schema/output_parser.js";
|
|
41
41
|
export * as schema__query_constructor from "../schema/query_constructor.js";
|
|
42
42
|
export * as schema__retriever from "../schema/retriever.js";
|
|
43
|
-
export * as schema__runnable from "../schema/runnable.js";
|
|
43
|
+
export * as schema__runnable from "../schema/runnable/index.js";
|
|
44
44
|
export * as schema__storage from "../schema/storage.js";
|
|
45
45
|
export * as callbacks from "../callbacks/index.js";
|
|
46
46
|
export * as output_parsers from "../output_parsers/index.js";
|
|
@@ -48,6 +48,7 @@ export * as retrievers__remote from "../retrievers/remote/index.js";
|
|
|
48
48
|
export * as retrievers__databerry from "../retrievers/databerry.js";
|
|
49
49
|
export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
|
|
50
50
|
export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
|
|
51
|
+
export * as retrievers__multi_query from "../retrievers/multi_query.js";
|
|
51
52
|
export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
|
|
52
53
|
export * as retrievers__parent_document from "../retrievers/parent_document.js";
|
|
53
54
|
export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
|
package/dist/load/import_map.js
CHANGED
|
@@ -41,7 +41,7 @@ export * as schema__document from "../schema/document.js";
|
|
|
41
41
|
export * as schema__output_parser from "../schema/output_parser.js";
|
|
42
42
|
export * as schema__query_constructor from "../schema/query_constructor.js";
|
|
43
43
|
export * as schema__retriever from "../schema/retriever.js";
|
|
44
|
-
export * as schema__runnable from "../schema/runnable.js";
|
|
44
|
+
export * as schema__runnable from "../schema/runnable/index.js";
|
|
45
45
|
export * as schema__storage from "../schema/storage.js";
|
|
46
46
|
export * as callbacks from "../callbacks/index.js";
|
|
47
47
|
export * as output_parsers from "../output_parsers/index.js";
|
|
@@ -49,6 +49,7 @@ export * as retrievers__remote from "../retrievers/remote/index.js";
|
|
|
49
49
|
export * as retrievers__databerry from "../retrievers/databerry.js";
|
|
50
50
|
export * as retrievers__contextual_compression from "../retrievers/contextual_compression.js";
|
|
51
51
|
export * as retrievers__document_compressors from "../retrievers/document_compressors/index.js";
|
|
52
|
+
export * as retrievers__multi_query from "../retrievers/multi_query.js";
|
|
52
53
|
export * as retrievers__multi_vector from "../retrievers/multi_vector.js";
|
|
53
54
|
export * as retrievers__parent_document from "../retrievers/parent_document.js";
|
|
54
55
|
export * as retrievers__time_weighted from "../retrievers/time_weighted.js";
|
package/dist/load/index.cjs
CHANGED
|
@@ -138,7 +138,8 @@ async function reviver(value) {
|
|
|
138
138
|
module[name] ??
|
|
139
139
|
// look for an export with a lc_name property matching the class name
|
|
140
140
|
// this is necessary for classes that are minified
|
|
141
|
-
Object.values(module).find((v) => typeof v === "function" &&
|
|
141
|
+
Object.values(module).find((v) => typeof v === "function" &&
|
|
142
|
+
(0, serializable_js_1.get_lc_unique_name)(v) === name);
|
|
142
143
|
if (typeof builder !== "function") {
|
|
143
144
|
throw new Error(`Invalid identifer: ${pathStr} -> ${str}`);
|
|
144
145
|
}
|
package/dist/load/index.js
CHANGED
|
@@ -112,7 +112,8 @@ async function reviver(value) {
|
|
|
112
112
|
module[name] ??
|
|
113
113
|
// look for an export with a lc_name property matching the class name
|
|
114
114
|
// this is necessary for classes that are minified
|
|
115
|
-
Object.values(module).find((v) => typeof v === "function" &&
|
|
115
|
+
Object.values(module).find((v) => typeof v === "function" &&
|
|
116
|
+
get_lc_unique_name(v) === name);
|
|
116
117
|
if (typeof builder !== "function") {
|
|
117
118
|
throw new Error(`Invalid identifer: ${pathStr} -> ${str}`);
|
|
118
119
|
}
|
|
@@ -138,11 +138,30 @@ class Serializable {
|
|
|
138
138
|
}
|
|
139
139
|
// include all secrets used, even if not in kwargs,
|
|
140
140
|
// will be replaced with sentinel value in replaceSecrets
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
141
|
+
Object.keys(secrets).forEach((keyPath) => {
|
|
142
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
|
|
143
|
+
let read = this;
|
|
144
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
145
|
+
let write = kwargs;
|
|
146
|
+
const [last, ...partsReverse] = keyPath.split(".").reverse();
|
|
147
|
+
for (const key of partsReverse.reverse()) {
|
|
148
|
+
if (!(key in read) || read[key] === undefined)
|
|
149
|
+
return;
|
|
150
|
+
if (!(key in write) || write[key] === undefined) {
|
|
151
|
+
if (typeof read[key] === "object" && read[key] != null) {
|
|
152
|
+
write[key] = {};
|
|
153
|
+
}
|
|
154
|
+
else if (Array.isArray(read[key])) {
|
|
155
|
+
write[key] = [];
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
read = read[key];
|
|
159
|
+
write = write[key];
|
|
144
160
|
}
|
|
145
|
-
|
|
161
|
+
if (last in read && read[last] !== undefined) {
|
|
162
|
+
write[last] = write[last] || read[last];
|
|
163
|
+
}
|
|
164
|
+
});
|
|
146
165
|
return {
|
|
147
166
|
lc: 1,
|
|
148
167
|
type: "constructor",
|
|
@@ -134,11 +134,30 @@ export class Serializable {
|
|
|
134
134
|
}
|
|
135
135
|
// include all secrets used, even if not in kwargs,
|
|
136
136
|
// will be replaced with sentinel value in replaceSecrets
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
137
|
+
Object.keys(secrets).forEach((keyPath) => {
|
|
138
|
+
// eslint-disable-next-line @typescript-eslint/no-this-alias, @typescript-eslint/no-explicit-any
|
|
139
|
+
let read = this;
|
|
140
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
141
|
+
let write = kwargs;
|
|
142
|
+
const [last, ...partsReverse] = keyPath.split(".").reverse();
|
|
143
|
+
for (const key of partsReverse.reverse()) {
|
|
144
|
+
if (!(key in read) || read[key] === undefined)
|
|
145
|
+
return;
|
|
146
|
+
if (!(key in write) || write[key] === undefined) {
|
|
147
|
+
if (typeof read[key] === "object" && read[key] != null) {
|
|
148
|
+
write[key] = {};
|
|
149
|
+
}
|
|
150
|
+
else if (Array.isArray(read[key])) {
|
|
151
|
+
write[key] = [];
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
read = read[key];
|
|
155
|
+
write = write[key];
|
|
140
156
|
}
|
|
141
|
-
|
|
157
|
+
if (last in read && read[last] !== undefined) {
|
|
158
|
+
write[last] = write[last] || read[last];
|
|
159
|
+
}
|
|
160
|
+
});
|
|
142
161
|
return {
|
|
143
162
|
lc: 1,
|
|
144
163
|
type: "constructor",
|
package/dist/prompts/base.cjs
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
5
5
|
exports.BaseExampleSelector = exports.BaseStringPromptTemplate = exports.BasePromptTemplate = exports.StringPromptValue = void 0;
|
|
6
6
|
const index_js_1 = require("../schema/index.cjs");
|
|
7
7
|
const serializable_js_1 = require("../load/serializable.cjs");
|
|
8
|
-
const
|
|
8
|
+
const index_js_2 = require("../schema/runnable/index.cjs");
|
|
9
9
|
/**
|
|
10
10
|
* Represents a prompt value as a string. It extends the BasePromptValue
|
|
11
11
|
* class and overrides the toString and toChatMessages methods.
|
|
@@ -39,7 +39,7 @@ exports.StringPromptValue = StringPromptValue;
|
|
|
39
39
|
* Base class for prompt templates. Exposes a format method that returns a
|
|
40
40
|
* string prompt given a set of input values.
|
|
41
41
|
*/
|
|
42
|
-
class BasePromptTemplate extends
|
|
42
|
+
class BasePromptTemplate extends index_js_2.Runnable {
|
|
43
43
|
get lc_attributes() {
|
|
44
44
|
return {
|
|
45
45
|
partialVariables: undefined, // python doesn't support this yet
|
package/dist/prompts/base.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { BaseOutputParser } from "../schema/output_parser.js";
|
|
|
3
3
|
import { Serializable } from "../load/serializable.js";
|
|
4
4
|
import { SerializedBasePromptTemplate } from "./serde.js";
|
|
5
5
|
import { SerializedFields } from "../load/map_keys.js";
|
|
6
|
-
import { Runnable } from "../schema/runnable.js";
|
|
6
|
+
import { Runnable } from "../schema/runnable/index.js";
|
|
7
7
|
import { BaseCallbackConfig } from "../callbacks/manager.js";
|
|
8
8
|
export type TypedPromptInputValues<RunInput> = InputValues<Extract<keyof RunInput, string> | (string & Record<never, never>)>;
|
|
9
9
|
/**
|
package/dist/prompts/base.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// Replace with "string" when we are comfortable with a breaking change.
|
|
3
3
|
import { BasePromptValue, HumanMessage, } from "../schema/index.js";
|
|
4
4
|
import { Serializable } from "../load/serializable.js";
|
|
5
|
-
import { Runnable } from "../schema/runnable.js";
|
|
5
|
+
import { Runnable } from "../schema/runnable/index.js";
|
|
6
6
|
/**
|
|
7
7
|
* Represents a prompt value as a string. It extends the BasePromptValue
|
|
8
8
|
* class and overrides the toString and toChatMessages methods.
|
package/dist/prompts/chat.cjs
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
5
|
exports.ChatPromptTemplate = exports.SystemMessagePromptTemplate = exports.AIMessagePromptTemplate = exports.HumanMessagePromptTemplate = exports.ChatMessagePromptTemplate = exports.BaseChatPromptTemplate = exports.BaseMessageStringPromptTemplate = exports.MessagesPlaceholder = exports.ChatPromptValue = exports.BaseMessagePromptTemplate = void 0;
|
|
6
6
|
const index_js_1 = require("../schema/index.cjs");
|
|
7
|
-
const
|
|
7
|
+
const index_js_2 = require("../schema/runnable/index.cjs");
|
|
8
8
|
const base_js_1 = require("./base.cjs");
|
|
9
9
|
const prompt_js_1 = require("./prompt.cjs");
|
|
10
10
|
/**
|
|
@@ -12,7 +12,7 @@ const prompt_js_1 = require("./prompt.cjs");
|
|
|
12
12
|
* templates. It defines how to format messages for different roles in a
|
|
13
13
|
* conversation.
|
|
14
14
|
*/
|
|
15
|
-
class BaseMessagePromptTemplate extends
|
|
15
|
+
class BaseMessagePromptTemplate extends index_js_2.Runnable {
|
|
16
16
|
constructor() {
|
|
17
17
|
super(...arguments);
|
|
18
18
|
Object.defineProperty(this, "lc_namespace", {
|
package/dist/prompts/chat.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { BaseCallbackConfig } from "../callbacks/manager.js";
|
|
2
2
|
import { BaseMessage, BaseMessageLike, BasePromptValue, InputValues, PartialValues } from "../schema/index.js";
|
|
3
|
-
import { Runnable } from "../schema/runnable.js";
|
|
3
|
+
import { Runnable } from "../schema/runnable/index.js";
|
|
4
4
|
import { BasePromptTemplate, BasePromptTemplateInput, BaseStringPromptTemplate, TypedPromptInputValues } from "./base.js";
|
|
5
5
|
/**
|
|
6
6
|
* Abstract class that serves as a base for creating message prompt
|
package/dist/prompts/chat.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Default generic "any" values are for backwards compatibility.
|
|
2
2
|
// Replace with "string" when we are comfortable with a breaking change.
|
|
3
3
|
import { AIMessage, BaseMessage, BasePromptValue, ChatMessage, HumanMessage, SystemMessage, coerceMessageLikeToMessage, isBaseMessage, } from "../schema/index.js";
|
|
4
|
-
import { Runnable } from "../schema/runnable.js";
|
|
4
|
+
import { Runnable } from "../schema/runnable/index.js";
|
|
5
5
|
import { BasePromptTemplate, } from "./base.js";
|
|
6
6
|
import { PromptTemplate } from "./prompt.js";
|
|
7
7
|
/**
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MultiQueryRetriever = void 0;
|
|
4
|
+
const llm_chain_js_1 = require("../chains/llm_chain.cjs");
|
|
5
|
+
const prompt_js_1 = require("../prompts/prompt.cjs");
|
|
6
|
+
const output_parser_js_1 = require("../schema/output_parser.cjs");
|
|
7
|
+
const retriever_js_1 = require("../schema/retriever.cjs");
|
|
8
|
+
class LineListOutputParser extends output_parser_js_1.BaseOutputParser {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ["langchain", "retrievers", "multiquery"]
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
static lc_name() {
|
|
19
|
+
return "LineListOutputParser";
|
|
20
|
+
}
|
|
21
|
+
async parse(text) {
|
|
22
|
+
const startKeyIndex = text.indexOf("<questions>");
|
|
23
|
+
const endKeyIndex = text.indexOf("</questions>");
|
|
24
|
+
const questionsStartIndex = startKeyIndex === -1 ? 0 : startKeyIndex + "<questions>".length;
|
|
25
|
+
const questionsEndIndex = endKeyIndex === -1 ? text.length : endKeyIndex;
|
|
26
|
+
const lines = text
|
|
27
|
+
.slice(questionsStartIndex, questionsEndIndex)
|
|
28
|
+
.trim()
|
|
29
|
+
.split("\n")
|
|
30
|
+
.filter((line) => line.trim() !== "");
|
|
31
|
+
return { lines };
|
|
32
|
+
}
|
|
33
|
+
getFormatInstructions() {
|
|
34
|
+
throw new Error("Not implemented.");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
// Create template
|
|
38
|
+
const DEFAULT_QUERY_PROMPT = /* #__PURE__ */ new prompt_js_1.PromptTemplate({
|
|
39
|
+
inputVariables: ["question", "queryCount"],
|
|
40
|
+
template: `You are an AI language model assistant. Your task is
|
|
41
|
+
to generate {queryCount} different versions of the given user
|
|
42
|
+
question to retrieve relevant documents from a vector database.
|
|
43
|
+
By generating multiple perspectives on the user question,
|
|
44
|
+
your goal is to help the user overcome some of the limitations
|
|
45
|
+
of distance-based similarity search.
|
|
46
|
+
|
|
47
|
+
Provide these alternative questions separated by newlines between XML tags. For example:
|
|
48
|
+
|
|
49
|
+
<questions>
|
|
50
|
+
Question 1
|
|
51
|
+
Question 2
|
|
52
|
+
Question 3
|
|
53
|
+
</questions>
|
|
54
|
+
|
|
55
|
+
Original question: {question}`,
|
|
56
|
+
});
|
|
57
|
+
// Export class
|
|
58
|
+
class MultiQueryRetriever extends retriever_js_1.BaseRetriever {
|
|
59
|
+
static lc_name() {
|
|
60
|
+
return "MultiQueryRetriever";
|
|
61
|
+
}
|
|
62
|
+
constructor(fields) {
|
|
63
|
+
super(fields);
|
|
64
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
configurable: true,
|
|
67
|
+
writable: true,
|
|
68
|
+
value: ["langchain", "retrievers", "multiquery"]
|
|
69
|
+
});
|
|
70
|
+
Object.defineProperty(this, "retriever", {
|
|
71
|
+
enumerable: true,
|
|
72
|
+
configurable: true,
|
|
73
|
+
writable: true,
|
|
74
|
+
value: void 0
|
|
75
|
+
});
|
|
76
|
+
Object.defineProperty(this, "llmChain", {
|
|
77
|
+
enumerable: true,
|
|
78
|
+
configurable: true,
|
|
79
|
+
writable: true,
|
|
80
|
+
value: void 0
|
|
81
|
+
});
|
|
82
|
+
Object.defineProperty(this, "queryCount", {
|
|
83
|
+
enumerable: true,
|
|
84
|
+
configurable: true,
|
|
85
|
+
writable: true,
|
|
86
|
+
value: 3
|
|
87
|
+
});
|
|
88
|
+
Object.defineProperty(this, "parserKey", {
|
|
89
|
+
enumerable: true,
|
|
90
|
+
configurable: true,
|
|
91
|
+
writable: true,
|
|
92
|
+
value: "lines"
|
|
93
|
+
});
|
|
94
|
+
this.retriever = fields.retriever;
|
|
95
|
+
this.llmChain = fields.llmChain;
|
|
96
|
+
this.queryCount = fields.queryCount ?? this.queryCount;
|
|
97
|
+
this.parserKey = fields.parserKey ?? this.parserKey;
|
|
98
|
+
}
|
|
99
|
+
static fromLLM(fields) {
|
|
100
|
+
const { retriever, llm, prompt = DEFAULT_QUERY_PROMPT, queryCount, parserKey, ...rest } = fields;
|
|
101
|
+
const outputParser = new LineListOutputParser();
|
|
102
|
+
const llmChain = new llm_chain_js_1.LLMChain({ llm, prompt, outputParser });
|
|
103
|
+
return new this({ retriever, llmChain, queryCount, parserKey, ...rest });
|
|
104
|
+
}
|
|
105
|
+
// Generate the different queries for each retrieval, using our llmChain
|
|
106
|
+
async _generateQueries(question, runManager) {
|
|
107
|
+
const response = await this.llmChain.call({ question, queryCount: this.queryCount }, runManager?.getChild());
|
|
108
|
+
const lines = response.text[this.parserKey] || [];
|
|
109
|
+
if (this.verbose) {
|
|
110
|
+
console.log(`Generated queries: ${lines}`);
|
|
111
|
+
}
|
|
112
|
+
return lines;
|
|
113
|
+
}
|
|
114
|
+
// Retrieve documents using the original retriever
|
|
115
|
+
async _retrieveDocuments(queries, runManager) {
|
|
116
|
+
const documents = [];
|
|
117
|
+
for (const query of queries) {
|
|
118
|
+
const docs = await this.retriever.getRelevantDocuments(query, runManager?.getChild());
|
|
119
|
+
documents.push(...docs);
|
|
120
|
+
}
|
|
121
|
+
return documents;
|
|
122
|
+
}
|
|
123
|
+
// Deduplicate the documents that were returned in multiple retrievals
|
|
124
|
+
_uniqueUnion(documents) {
|
|
125
|
+
const uniqueDocumentsDict = {};
|
|
126
|
+
for (const doc of documents) {
|
|
127
|
+
const key = `${doc.pageContent}:${JSON.stringify(Object.entries(doc.metadata).sort())}`;
|
|
128
|
+
uniqueDocumentsDict[key] = doc;
|
|
129
|
+
}
|
|
130
|
+
const uniqueDocuments = Object.values(uniqueDocumentsDict);
|
|
131
|
+
return uniqueDocuments;
|
|
132
|
+
}
|
|
133
|
+
async _getRelevantDocuments(question, runManager) {
|
|
134
|
+
const queries = await this._generateQueries(question, runManager);
|
|
135
|
+
const documents = await this._retrieveDocuments(queries, runManager);
|
|
136
|
+
const uniqueDocuments = this._uniqueUnion(documents);
|
|
137
|
+
return uniqueDocuments;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
exports.MultiQueryRetriever = MultiQueryRetriever;
|