langchain 0.0.147 → 0.0.149
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/chains/constitutional_ai/constitutional_principle.cjs +272 -1
- package/dist/chains/constitutional_ai/constitutional_principle.js +272 -1
- package/dist/chains/question_answering/load.cjs +12 -4
- package/dist/chains/question_answering/load.d.ts +2 -0
- package/dist/chains/question_answering/load.js +12 -4
- package/dist/chains/summarization/load.cjs +8 -4
- package/dist/chains/summarization/load.d.ts +2 -0
- package/dist/chains/summarization/load.js +8 -4
- package/dist/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/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/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/llms/bedrock.cjs +9 -1
- package/dist/llms/bedrock.d.ts +3 -0
- package/dist/llms/bedrock.js +9 -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/load/import_constants.cjs +2 -0
- package/dist/load/import_constants.js +2 -0
- package/dist/load/import_map.cjs +2 -1
- package/dist/load/import_map.d.ts +1 -0
- package/dist/load/import_map.js +1 -0
- package/dist/load/serializable.cjs +23 -4
- package/dist/load/serializable.js +23 -4
- 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/retrievers/self_query/base.cjs +1 -1
- package/dist/retrievers/self_query/base.js +2 -2
- package/dist/retrievers/self_query/functional.cjs +1 -1
- package/dist/retrievers/self_query/functional.js +2 -2
- package/dist/retrievers/self_query/utils.cjs +46 -6
- package/dist/retrievers/self_query/utils.d.ts +7 -0
- package/dist/retrievers/self_query/utils.js +44 -5
- package/dist/schema/runnable/base.cjs +910 -0
- package/dist/schema/runnable/base.d.ts +300 -0
- package/dist/schema/runnable/base.js +896 -0
- package/dist/schema/runnable/index.cjs +19 -926
- package/dist/schema/runnable/index.d.ts +4 -298
- package/dist/schema/runnable/index.js +3 -914
- package/dist/schema/runnable/passthrough.cjs +31 -0
- package/dist/schema/runnable/passthrough.d.ts +11 -0
- package/dist/schema/runnable/passthrough.js +27 -0
- package/dist/schema/runnable/router.cjs +74 -0
- package/dist/schema/runnable/router.d.ts +29 -0
- package/dist/schema/runnable/router.js +70 -0
- package/dist/types/googlevertexai-types.d.ts +11 -4
- 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/opensearch.cjs +4 -2
- package/dist/vectorstores/opensearch.d.ts +4 -1
- package/dist/vectorstores/opensearch.js +4 -2
- 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 +32 -3
- package/retrievers/multi_query.cjs +1 -0
- package/retrievers/multi_query.d.ts +1 -0
- package/retrievers/multi_query.js +1 -0
|
@@ -1,25 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GoogleVertexAI = void 0;
|
|
4
|
-
const base_js_1 = require("./base.cjs");
|
|
5
|
-
const googlevertexai_connection_js_1 = require("../util/googlevertexai-connection.cjs");
|
|
1
|
+
import { BaseLLM } from "../base.js";
|
|
6
2
|
/**
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* To use, you will need to have one of the following authentication
|
|
11
|
-
* methods in place:
|
|
12
|
-
* - You are logged into an account permitted to the Google Cloud project
|
|
13
|
-
* using Vertex AI.
|
|
14
|
-
* - You are running this on a machine using a service account permitted to
|
|
15
|
-
* the Google Cloud project using Vertex AI.
|
|
16
|
-
* - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
|
|
17
|
-
* path of a credentials file for a service account permitted to the
|
|
18
|
-
* Google Cloud project using Vertex AI.
|
|
3
|
+
* Base class for Google Vertex AI LLMs.
|
|
4
|
+
* Implemented subclasses must provide a GoogleVertexAILLMConnection
|
|
5
|
+
* with an appropriate auth client.
|
|
19
6
|
*/
|
|
20
|
-
class
|
|
7
|
+
export class BaseGoogleVertexAI extends BaseLLM {
|
|
8
|
+
get lc_aliases() {
|
|
9
|
+
return {
|
|
10
|
+
model: "model_name",
|
|
11
|
+
};
|
|
12
|
+
}
|
|
21
13
|
constructor(fields) {
|
|
22
14
|
super(fields ?? {});
|
|
15
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: true
|
|
20
|
+
});
|
|
23
21
|
Object.defineProperty(this, "model", {
|
|
24
22
|
enumerable: true,
|
|
25
23
|
configurable: true,
|
|
@@ -68,10 +66,9 @@ class GoogleVertexAI extends base_js_1.BaseLLM {
|
|
|
68
66
|
this.maxOutputTokens = fields?.maxOutputTokens ?? this.maxOutputTokens;
|
|
69
67
|
this.topP = fields?.topP ?? this.topP;
|
|
70
68
|
this.topK = fields?.topK ?? this.topK;
|
|
71
|
-
this.connection = new googlevertexai_connection_js_1.GoogleVertexAILLMConnection({ ...fields, ...this }, this.caller);
|
|
72
69
|
}
|
|
73
70
|
_llmType() {
|
|
74
|
-
return "
|
|
71
|
+
return "vertexai";
|
|
75
72
|
}
|
|
76
73
|
async _generate(prompts, options) {
|
|
77
74
|
const generations = await Promise.all(prompts.map((prompt) => this._generatePrompt(prompt, options)));
|
|
@@ -132,4 +129,3 @@ class GoogleVertexAI extends base_js_1.BaseLLM {
|
|
|
132
129
|
return result?.data?.predictions[0];
|
|
133
130
|
}
|
|
134
131
|
}
|
|
135
|
-
exports.GoogleVertexAI = GoogleVertexAI;
|
|
@@ -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
|
+
}
|
|
@@ -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",
|
|
@@ -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",
|
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"));
|
|
@@ -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"));
|
|
@@ -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
|
@@ -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";
|
|
@@ -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",
|
|
@@ -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;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { LLMChain } from "../chains/llm_chain.js";
|
|
2
|
+
import { Document } from "../document.js";
|
|
3
|
+
import { BaseRetriever, BaseRetrieverInput } from "../schema/retriever.js";
|
|
4
|
+
import { CallbackManagerForRetrieverRun } from "../callbacks/index.js";
|
|
5
|
+
import { BaseLanguageModel } from "../base_language/index.js";
|
|
6
|
+
import { BasePromptTemplate } from "../prompts/base.js";
|
|
7
|
+
interface LineList {
|
|
8
|
+
lines: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface MultiQueryRetrieverInput extends BaseRetrieverInput {
|
|
11
|
+
retriever: BaseRetriever;
|
|
12
|
+
llmChain: LLMChain<LineList>;
|
|
13
|
+
queryCount?: number;
|
|
14
|
+
parserKey?: string;
|
|
15
|
+
}
|
|
16
|
+
export declare class MultiQueryRetriever extends BaseRetriever {
|
|
17
|
+
static lc_name(): string;
|
|
18
|
+
lc_namespace: string[];
|
|
19
|
+
private retriever;
|
|
20
|
+
private llmChain;
|
|
21
|
+
private queryCount;
|
|
22
|
+
private parserKey;
|
|
23
|
+
constructor(fields: MultiQueryRetrieverInput);
|
|
24
|
+
static fromLLM(fields: Omit<MultiQueryRetrieverInput, "llmChain"> & {
|
|
25
|
+
llm: BaseLanguageModel;
|
|
26
|
+
prompt?: BasePromptTemplate;
|
|
27
|
+
}): MultiQueryRetriever;
|
|
28
|
+
private _generateQueries;
|
|
29
|
+
private _retrieveDocuments;
|
|
30
|
+
private _uniqueUnion;
|
|
31
|
+
_getRelevantDocuments(question: string, runManager?: CallbackManagerForRetrieverRun): Promise<Document[]>;
|
|
32
|
+
}
|
|
33
|
+
export {};
|