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
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RunnablePassthrough = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* A runnable that passes through the input.
|
|
7
|
+
*/
|
|
8
|
+
class RunnablePassthrough extends base_js_1.Runnable {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: ["langchain", "schema", "runnable"]
|
|
16
|
+
});
|
|
17
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: true
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
static lc_name() {
|
|
25
|
+
return "RunnablePassthrough";
|
|
26
|
+
}
|
|
27
|
+
async invoke(input, options) {
|
|
28
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
exports.RunnablePassthrough = RunnablePassthrough;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
import type { RunnableConfig } from "./config.js";
|
|
3
|
+
/**
|
|
4
|
+
* A runnable that passes through the input.
|
|
5
|
+
*/
|
|
6
|
+
export declare class RunnablePassthrough<RunInput> extends Runnable<RunInput, RunInput> {
|
|
7
|
+
static lc_name(): string;
|
|
8
|
+
lc_namespace: string[];
|
|
9
|
+
lc_serializable: boolean;
|
|
10
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunInput>;
|
|
11
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A runnable that passes through the input.
|
|
4
|
+
*/
|
|
5
|
+
export class RunnablePassthrough extends Runnable {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: ["langchain", "schema", "runnable"]
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: true
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
static lc_name() {
|
|
22
|
+
return "RunnablePassthrough";
|
|
23
|
+
}
|
|
24
|
+
async invoke(input, options) {
|
|
25
|
+
return this._callWithConfig((input) => Promise.resolve(input), input, options);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RouterRunnable = void 0;
|
|
4
|
+
const base_js_1 = require("./base.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
7
|
+
* Returns the output of the selected runnable.
|
|
8
|
+
*/
|
|
9
|
+
class RouterRunnable extends base_js_1.Runnable {
|
|
10
|
+
static lc_name() {
|
|
11
|
+
return "RouterRunnable";
|
|
12
|
+
}
|
|
13
|
+
constructor(fields) {
|
|
14
|
+
super(fields);
|
|
15
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: true,
|
|
19
|
+
value: ["langchain", "schema", "runnable"]
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
configurable: true,
|
|
24
|
+
writable: true,
|
|
25
|
+
value: true
|
|
26
|
+
});
|
|
27
|
+
Object.defineProperty(this, "runnables", {
|
|
28
|
+
enumerable: true,
|
|
29
|
+
configurable: true,
|
|
30
|
+
writable: true,
|
|
31
|
+
value: void 0
|
|
32
|
+
});
|
|
33
|
+
this.runnables = fields.runnables;
|
|
34
|
+
}
|
|
35
|
+
async invoke(input, options) {
|
|
36
|
+
const { key, input: actualInput } = input;
|
|
37
|
+
const runnable = this.runnables[key];
|
|
38
|
+
if (runnable === undefined) {
|
|
39
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
40
|
+
}
|
|
41
|
+
return runnable.invoke(actualInput, options);
|
|
42
|
+
}
|
|
43
|
+
async batch(inputs, options, batchOptions) {
|
|
44
|
+
const keys = inputs.map((input) => input.key);
|
|
45
|
+
const actualInputs = inputs.map((input) => input.input);
|
|
46
|
+
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
47
|
+
if (missingKey !== undefined) {
|
|
48
|
+
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
49
|
+
}
|
|
50
|
+
const runnables = keys.map((key) => this.runnables[key]);
|
|
51
|
+
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
52
|
+
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
53
|
+
? batchOptions?.maxConcurrency
|
|
54
|
+
: inputs.length;
|
|
55
|
+
const batchResults = [];
|
|
56
|
+
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
57
|
+
const batchPromises = actualInputs
|
|
58
|
+
.slice(i, i + batchSize)
|
|
59
|
+
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
60
|
+
const batchResult = await Promise.all(batchPromises);
|
|
61
|
+
batchResults.push(batchResult);
|
|
62
|
+
}
|
|
63
|
+
return batchResults.flat();
|
|
64
|
+
}
|
|
65
|
+
async stream(input, options) {
|
|
66
|
+
const { key, input: actualInput } = input;
|
|
67
|
+
const runnable = this.runnables[key];
|
|
68
|
+
if (runnable === undefined) {
|
|
69
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
70
|
+
}
|
|
71
|
+
return runnable.stream(actualInput, options);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.RouterRunnable = RouterRunnable;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { Runnable, type RunnableBatchOptions } from "./base.js";
|
|
2
|
+
import { IterableReadableStream } from "../../util/stream.js";
|
|
3
|
+
import type { RunnableConfig } from "./config.js";
|
|
4
|
+
export type RouterInput = {
|
|
5
|
+
key: string;
|
|
6
|
+
input: any;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
10
|
+
* Returns the output of the selected runnable.
|
|
11
|
+
*/
|
|
12
|
+
export declare class RouterRunnable<RunInput extends RouterInput, RunnableInput, RunOutput> extends Runnable<RunInput, RunOutput> {
|
|
13
|
+
static lc_name(): string;
|
|
14
|
+
lc_namespace: string[];
|
|
15
|
+
lc_serializable: boolean;
|
|
16
|
+
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
17
|
+
constructor(fields: {
|
|
18
|
+
runnables: Record<string, Runnable<RunnableInput, RunOutput>>;
|
|
19
|
+
});
|
|
20
|
+
invoke(input: RunInput, options?: Partial<RunnableConfig>): Promise<RunOutput>;
|
|
21
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
22
|
+
returnExceptions?: false;
|
|
23
|
+
}): Promise<RunOutput[]>;
|
|
24
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions & {
|
|
25
|
+
returnExceptions: true;
|
|
26
|
+
}): Promise<(RunOutput | Error)[]>;
|
|
27
|
+
batch(inputs: RunInput[], options?: Partial<RunnableConfig> | Partial<RunnableConfig>[], batchOptions?: RunnableBatchOptions): Promise<(RunOutput | Error)[]>;
|
|
28
|
+
stream(input: RunInput, options?: Partial<RunnableConfig>): Promise<IterableReadableStream<RunOutput>>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Runnable } from "./base.js";
|
|
2
|
+
/**
|
|
3
|
+
* A runnable that routes to a set of runnables based on Input['key'].
|
|
4
|
+
* Returns the output of the selected runnable.
|
|
5
|
+
*/
|
|
6
|
+
export class RouterRunnable extends Runnable {
|
|
7
|
+
static lc_name() {
|
|
8
|
+
return "RouterRunnable";
|
|
9
|
+
}
|
|
10
|
+
constructor(fields) {
|
|
11
|
+
super(fields);
|
|
12
|
+
Object.defineProperty(this, "lc_namespace", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
configurable: true,
|
|
15
|
+
writable: true,
|
|
16
|
+
value: ["langchain", "schema", "runnable"]
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(this, "lc_serializable", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
configurable: true,
|
|
21
|
+
writable: true,
|
|
22
|
+
value: true
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(this, "runnables", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
configurable: true,
|
|
27
|
+
writable: true,
|
|
28
|
+
value: void 0
|
|
29
|
+
});
|
|
30
|
+
this.runnables = fields.runnables;
|
|
31
|
+
}
|
|
32
|
+
async invoke(input, options) {
|
|
33
|
+
const { key, input: actualInput } = input;
|
|
34
|
+
const runnable = this.runnables[key];
|
|
35
|
+
if (runnable === undefined) {
|
|
36
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
37
|
+
}
|
|
38
|
+
return runnable.invoke(actualInput, options);
|
|
39
|
+
}
|
|
40
|
+
async batch(inputs, options, batchOptions) {
|
|
41
|
+
const keys = inputs.map((input) => input.key);
|
|
42
|
+
const actualInputs = inputs.map((input) => input.input);
|
|
43
|
+
const missingKey = keys.find((key) => this.runnables[key] === undefined);
|
|
44
|
+
if (missingKey !== undefined) {
|
|
45
|
+
throw new Error(`One or more keys do not have a corresponding runnable.`);
|
|
46
|
+
}
|
|
47
|
+
const runnables = keys.map((key) => this.runnables[key]);
|
|
48
|
+
const optionsList = this._getOptionsList(options ?? {}, inputs.length);
|
|
49
|
+
const batchSize = batchOptions?.maxConcurrency && batchOptions.maxConcurrency > 0
|
|
50
|
+
? batchOptions?.maxConcurrency
|
|
51
|
+
: inputs.length;
|
|
52
|
+
const batchResults = [];
|
|
53
|
+
for (let i = 0; i < actualInputs.length; i += batchSize) {
|
|
54
|
+
const batchPromises = actualInputs
|
|
55
|
+
.slice(i, i + batchSize)
|
|
56
|
+
.map((actualInput, i) => runnables[i].invoke(actualInput, optionsList[i]));
|
|
57
|
+
const batchResult = await Promise.all(batchPromises);
|
|
58
|
+
batchResults.push(batchResult);
|
|
59
|
+
}
|
|
60
|
+
return batchResults.flat();
|
|
61
|
+
}
|
|
62
|
+
async stream(input, options) {
|
|
63
|
+
const { key, input: actualInput } = input;
|
|
64
|
+
const runnable = this.runnables[key];
|
|
65
|
+
if (runnable === undefined) {
|
|
66
|
+
throw new Error(`No runnable associated with key "${key}".`);
|
|
67
|
+
}
|
|
68
|
+
return runnable.stream(actualInput, options);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { GoogleAuthOptions } from "google-auth-library";
|
|
2
1
|
import { BaseLLMParams } from "../llms/base.js";
|
|
3
|
-
export interface GoogleVertexAIConnectionParams {
|
|
2
|
+
export interface GoogleVertexAIConnectionParams<AuthOptions> {
|
|
4
3
|
/** Hostname for the API call */
|
|
5
4
|
endpoint?: string;
|
|
6
|
-
authOptions?:
|
|
5
|
+
authOptions?: AuthOptions;
|
|
7
6
|
/** Region where the LLM is stored */
|
|
8
7
|
location?: string;
|
|
9
8
|
/** The version of the API functions. Part of the path. */
|
|
@@ -39,7 +38,7 @@ export interface GoogleVertexAIModelParams {
|
|
|
39
38
|
*/
|
|
40
39
|
topK?: number;
|
|
41
40
|
}
|
|
42
|
-
export interface GoogleVertexAIBaseLLMInput extends BaseLLMParams, GoogleVertexAIConnectionParams
|
|
41
|
+
export interface GoogleVertexAIBaseLLMInput<AuthOptions> extends BaseLLMParams, GoogleVertexAIConnectionParams<AuthOptions>, GoogleVertexAIModelParams {
|
|
43
42
|
}
|
|
44
43
|
export interface GoogleVertexAIResponse {
|
|
45
44
|
data: any;
|
|
@@ -52,3 +51,11 @@ export interface GoogleVertexAILLMResponse<PredictionType extends GoogleVertexAI
|
|
|
52
51
|
predictions: PredictionType[];
|
|
53
52
|
};
|
|
54
53
|
}
|
|
54
|
+
export interface GoogleVertexAIAbstractedClient {
|
|
55
|
+
request: (opts: {
|
|
56
|
+
url?: string;
|
|
57
|
+
method?: "GET" | "POST";
|
|
58
|
+
data?: unknown;
|
|
59
|
+
}) => unknown;
|
|
60
|
+
getProjectId: () => Promise<string>;
|
|
61
|
+
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GoogleVertexAILLMConnection = exports.GoogleVertexAIConnection = void 0;
|
|
4
|
-
const google_auth_library_1 = require("google-auth-library");
|
|
5
4
|
class GoogleVertexAIConnection {
|
|
6
|
-
constructor(fields, caller) {
|
|
5
|
+
constructor(fields, caller, client) {
|
|
7
6
|
Object.defineProperty(this, "caller", {
|
|
8
7
|
enumerable: true,
|
|
9
8
|
configurable: true,
|
|
@@ -28,7 +27,7 @@ class GoogleVertexAIConnection {
|
|
|
28
27
|
writable: true,
|
|
29
28
|
value: "v1"
|
|
30
29
|
});
|
|
31
|
-
Object.defineProperty(this, "
|
|
30
|
+
Object.defineProperty(this, "client", {
|
|
32
31
|
enumerable: true,
|
|
33
32
|
configurable: true,
|
|
34
33
|
writable: true,
|
|
@@ -38,16 +37,12 @@ class GoogleVertexAIConnection {
|
|
|
38
37
|
this.endpoint = fields?.endpoint ?? this.endpoint;
|
|
39
38
|
this.location = fields?.location ?? this.location;
|
|
40
39
|
this.apiVersion = fields?.apiVersion ?? this.apiVersion;
|
|
41
|
-
this.
|
|
42
|
-
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
43
|
-
...fields?.authOptions,
|
|
44
|
-
});
|
|
40
|
+
this.client = client;
|
|
45
41
|
}
|
|
46
42
|
buildMethod() {
|
|
47
43
|
return "POST";
|
|
48
44
|
}
|
|
49
45
|
async _request(data, options) {
|
|
50
|
-
const client = await this.auth.getClient();
|
|
51
46
|
const url = await this.buildUrl();
|
|
52
47
|
const method = this.buildMethod();
|
|
53
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -58,11 +53,8 @@ class GoogleVertexAIConnection {
|
|
|
58
53
|
if (data && method === "POST") {
|
|
59
54
|
opts.data = data;
|
|
60
55
|
}
|
|
61
|
-
async function _request() {
|
|
62
|
-
return client.request(opts);
|
|
63
|
-
}
|
|
64
56
|
try {
|
|
65
|
-
const callResponse = await this.caller.callWithOptions({ signal: options?.signal },
|
|
57
|
+
const callResponse = await this.caller.callWithOptions({ signal: options?.signal }, async () => this.client.request(opts));
|
|
66
58
|
const response = callResponse; // Done for typecast safety, I guess
|
|
67
59
|
return response;
|
|
68
60
|
}
|
|
@@ -74,18 +66,25 @@ class GoogleVertexAIConnection {
|
|
|
74
66
|
}
|
|
75
67
|
exports.GoogleVertexAIConnection = GoogleVertexAIConnection;
|
|
76
68
|
class GoogleVertexAILLMConnection extends GoogleVertexAIConnection {
|
|
77
|
-
constructor(fields, caller) {
|
|
78
|
-
super(fields, caller);
|
|
69
|
+
constructor(fields, caller, client) {
|
|
70
|
+
super(fields, caller, client);
|
|
79
71
|
Object.defineProperty(this, "model", {
|
|
80
72
|
enumerable: true,
|
|
81
73
|
configurable: true,
|
|
82
74
|
writable: true,
|
|
83
75
|
value: void 0
|
|
84
76
|
});
|
|
77
|
+
Object.defineProperty(this, "client", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
configurable: true,
|
|
80
|
+
writable: true,
|
|
81
|
+
value: void 0
|
|
82
|
+
});
|
|
83
|
+
this.client = client;
|
|
85
84
|
this.model = fields?.model ?? this.model;
|
|
86
85
|
}
|
|
87
86
|
async buildUrl() {
|
|
88
|
-
const projectId = await this.
|
|
87
|
+
const projectId = await this.client.getProjectId();
|
|
89
88
|
const url = `https://${this.endpoint}/v1/projects/${projectId}/locations/${this.location}/publishers/google/models/${this.model}:predict`;
|
|
90
89
|
return url;
|
|
91
90
|
}
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { GoogleAuth } from "google-auth-library";
|
|
2
1
|
import { BaseLanguageModelCallOptions } from "../base_language/index.js";
|
|
3
2
|
import { AsyncCaller, AsyncCallerCallOptions } from "./async_caller.js";
|
|
4
|
-
import { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction, GoogleVertexAIConnectionParams, GoogleVertexAILLMResponse, GoogleVertexAIModelParams, GoogleVertexAIResponse } from "../types/googlevertexai-types.js";
|
|
5
|
-
export declare abstract class GoogleVertexAIConnection<CallOptions extends AsyncCallerCallOptions, ResponseType extends GoogleVertexAIResponse> implements GoogleVertexAIConnectionParams {
|
|
3
|
+
import type { GoogleVertexAIBaseLLMInput, GoogleVertexAIBasePrediction, GoogleVertexAIConnectionParams, GoogleVertexAILLMResponse, GoogleVertexAIModelParams, GoogleVertexAIResponse, GoogleVertexAIAbstractedClient } from "../types/googlevertexai-types.js";
|
|
4
|
+
export declare abstract class GoogleVertexAIConnection<CallOptions extends AsyncCallerCallOptions, ResponseType extends GoogleVertexAIResponse, AuthOptions> implements GoogleVertexAIConnectionParams<AuthOptions> {
|
|
6
5
|
caller: AsyncCaller;
|
|
7
6
|
endpoint: string;
|
|
8
7
|
location: string;
|
|
9
8
|
apiVersion: string;
|
|
10
|
-
|
|
11
|
-
constructor(fields: GoogleVertexAIConnectionParams | undefined, caller: AsyncCaller);
|
|
9
|
+
client: GoogleVertexAIAbstractedClient;
|
|
10
|
+
constructor(fields: GoogleVertexAIConnectionParams<AuthOptions> | undefined, caller: AsyncCaller, client: GoogleVertexAIAbstractedClient);
|
|
12
11
|
abstract buildUrl(): Promise<string>;
|
|
13
12
|
buildMethod(): string;
|
|
14
13
|
_request(data: unknown | undefined, options: CallOptions): Promise<ResponseType>;
|
|
15
14
|
}
|
|
16
|
-
export declare class GoogleVertexAILLMConnection<CallOptions extends BaseLanguageModelCallOptions, InstanceType, PredictionType extends GoogleVertexAIBasePrediction> extends GoogleVertexAIConnection<CallOptions, PredictionType> implements GoogleVertexAIBaseLLMInput {
|
|
15
|
+
export declare class GoogleVertexAILLMConnection<CallOptions extends BaseLanguageModelCallOptions, InstanceType, PredictionType extends GoogleVertexAIBasePrediction, AuthOptions> extends GoogleVertexAIConnection<CallOptions, PredictionType, AuthOptions> implements GoogleVertexAIBaseLLMInput<AuthOptions> {
|
|
17
16
|
model: string;
|
|
18
|
-
|
|
17
|
+
client: GoogleVertexAIAbstractedClient;
|
|
18
|
+
constructor(fields: GoogleVertexAIBaseLLMInput<AuthOptions> | undefined, caller: AsyncCaller, client: GoogleVertexAIAbstractedClient);
|
|
19
19
|
buildUrl(): Promise<string>;
|
|
20
20
|
request(instances: InstanceType[], parameters: GoogleVertexAIModelParams, options: CallOptions): Promise<GoogleVertexAILLMResponse<PredictionType>>;
|
|
21
21
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { GoogleAuth } from "google-auth-library";
|
|
2
1
|
export class GoogleVertexAIConnection {
|
|
3
|
-
constructor(fields, caller) {
|
|
2
|
+
constructor(fields, caller, client) {
|
|
4
3
|
Object.defineProperty(this, "caller", {
|
|
5
4
|
enumerable: true,
|
|
6
5
|
configurable: true,
|
|
@@ -25,7 +24,7 @@ export class GoogleVertexAIConnection {
|
|
|
25
24
|
writable: true,
|
|
26
25
|
value: "v1"
|
|
27
26
|
});
|
|
28
|
-
Object.defineProperty(this, "
|
|
27
|
+
Object.defineProperty(this, "client", {
|
|
29
28
|
enumerable: true,
|
|
30
29
|
configurable: true,
|
|
31
30
|
writable: true,
|
|
@@ -35,16 +34,12 @@ export class GoogleVertexAIConnection {
|
|
|
35
34
|
this.endpoint = fields?.endpoint ?? this.endpoint;
|
|
36
35
|
this.location = fields?.location ?? this.location;
|
|
37
36
|
this.apiVersion = fields?.apiVersion ?? this.apiVersion;
|
|
38
|
-
this.
|
|
39
|
-
scopes: "https://www.googleapis.com/auth/cloud-platform",
|
|
40
|
-
...fields?.authOptions,
|
|
41
|
-
});
|
|
37
|
+
this.client = client;
|
|
42
38
|
}
|
|
43
39
|
buildMethod() {
|
|
44
40
|
return "POST";
|
|
45
41
|
}
|
|
46
42
|
async _request(data, options) {
|
|
47
|
-
const client = await this.auth.getClient();
|
|
48
43
|
const url = await this.buildUrl();
|
|
49
44
|
const method = this.buildMethod();
|
|
50
45
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -55,11 +50,8 @@ export class GoogleVertexAIConnection {
|
|
|
55
50
|
if (data && method === "POST") {
|
|
56
51
|
opts.data = data;
|
|
57
52
|
}
|
|
58
|
-
async function _request() {
|
|
59
|
-
return client.request(opts);
|
|
60
|
-
}
|
|
61
53
|
try {
|
|
62
|
-
const callResponse = await this.caller.callWithOptions({ signal: options?.signal },
|
|
54
|
+
const callResponse = await this.caller.callWithOptions({ signal: options?.signal }, async () => this.client.request(opts));
|
|
63
55
|
const response = callResponse; // Done for typecast safety, I guess
|
|
64
56
|
return response;
|
|
65
57
|
}
|
|
@@ -70,18 +62,25 @@ export class GoogleVertexAIConnection {
|
|
|
70
62
|
}
|
|
71
63
|
}
|
|
72
64
|
export class GoogleVertexAILLMConnection extends GoogleVertexAIConnection {
|
|
73
|
-
constructor(fields, caller) {
|
|
74
|
-
super(fields, caller);
|
|
65
|
+
constructor(fields, caller, client) {
|
|
66
|
+
super(fields, caller, client);
|
|
75
67
|
Object.defineProperty(this, "model", {
|
|
76
68
|
enumerable: true,
|
|
77
69
|
configurable: true,
|
|
78
70
|
writable: true,
|
|
79
71
|
value: void 0
|
|
80
72
|
});
|
|
73
|
+
Object.defineProperty(this, "client", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
configurable: true,
|
|
76
|
+
writable: true,
|
|
77
|
+
value: void 0
|
|
78
|
+
});
|
|
79
|
+
this.client = client;
|
|
81
80
|
this.model = fields?.model ?? this.model;
|
|
82
81
|
}
|
|
83
82
|
async buildUrl() {
|
|
84
|
-
const projectId = await this.
|
|
83
|
+
const projectId = await this.client.getProjectId();
|
|
85
84
|
const url = `https://${this.endpoint}/v1/projects/${projectId}/locations/${this.location}/publishers/google/models/${this.model}:predict`;
|
|
86
85
|
return url;
|
|
87
86
|
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebGoogleAuth = void 0;
|
|
4
|
+
const google_1 = require("web-auth-library/google");
|
|
5
|
+
const env_js_1 = require("./env.cjs");
|
|
6
|
+
class WebGoogleAuth {
|
|
7
|
+
constructor(options) {
|
|
8
|
+
Object.defineProperty(this, "options", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
const credentials = options?.credentials ??
|
|
15
|
+
(0, env_js_1.getEnvironmentVariable)("GOOGLE_VERTEX_AI_WEB_CREDENTIALS");
|
|
16
|
+
if (credentials === undefined)
|
|
17
|
+
throw new Error(`Credentials not found. Please set the GOOGLE_VERTEX_AI_WEB_CREDENTIALS or pass credentials into "authOptions.credentials".`);
|
|
18
|
+
const scope = options?.scope ?? "https://www.googleapis.com/auth/cloud-platform";
|
|
19
|
+
this.options = { ...options, credentials, scope };
|
|
20
|
+
}
|
|
21
|
+
async getProjectId() {
|
|
22
|
+
const credentials = (0, google_1.getCredentials)(this.options.credentials);
|
|
23
|
+
return credentials.project_id;
|
|
24
|
+
}
|
|
25
|
+
async request(opts) {
|
|
26
|
+
const accessToken = await (0, google_1.getAccessToken)(this.options);
|
|
27
|
+
if (opts.url == null)
|
|
28
|
+
throw new Error("Missing URL");
|
|
29
|
+
const fetchOptions = {
|
|
30
|
+
method: opts.method,
|
|
31
|
+
headers: {
|
|
32
|
+
Authorization: `Bearer ${accessToken}`,
|
|
33
|
+
"Content-Type": "application/json",
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
if (opts.data !== undefined) {
|
|
37
|
+
fetchOptions.body = JSON.stringify(opts.data);
|
|
38
|
+
}
|
|
39
|
+
const res = await fetch(opts.url, fetchOptions);
|
|
40
|
+
if (!res.ok) {
|
|
41
|
+
const error = new Error(`Could not get access token for Vertex AI with status code: ${res.status}`);
|
|
42
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
43
|
+
error.response = res;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
data: await res.json(),
|
|
48
|
+
config: {},
|
|
49
|
+
status: res.status,
|
|
50
|
+
statusText: res.statusText,
|
|
51
|
+
headers: res.headers,
|
|
52
|
+
request: { responseURL: res.url },
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.WebGoogleAuth = WebGoogleAuth;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Credentials } from "web-auth-library/google";
|
|
2
|
+
import type { GoogleVertexAIAbstractedClient } from "../types/googlevertexai-types.js";
|
|
3
|
+
export type WebGoogleAuthOptions = {
|
|
4
|
+
credentials: string | Credentials;
|
|
5
|
+
scope?: string | string[];
|
|
6
|
+
};
|
|
7
|
+
export declare class WebGoogleAuth implements GoogleVertexAIAbstractedClient {
|
|
8
|
+
options: WebGoogleAuthOptions;
|
|
9
|
+
constructor(options?: WebGoogleAuthOptions);
|
|
10
|
+
getProjectId(): Promise<string>;
|
|
11
|
+
request(opts: {
|
|
12
|
+
url?: string;
|
|
13
|
+
method?: string;
|
|
14
|
+
data?: unknown;
|
|
15
|
+
}): Promise<{
|
|
16
|
+
data: any;
|
|
17
|
+
config: {};
|
|
18
|
+
status: number;
|
|
19
|
+
statusText: string;
|
|
20
|
+
headers: Headers;
|
|
21
|
+
request: {
|
|
22
|
+
responseURL: string;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { getAccessToken, getCredentials, } from "web-auth-library/google";
|
|
2
|
+
import { getEnvironmentVariable } from "./env.js";
|
|
3
|
+
export class WebGoogleAuth {
|
|
4
|
+
constructor(options) {
|
|
5
|
+
Object.defineProperty(this, "options", {
|
|
6
|
+
enumerable: true,
|
|
7
|
+
configurable: true,
|
|
8
|
+
writable: true,
|
|
9
|
+
value: void 0
|
|
10
|
+
});
|
|
11
|
+
const credentials = options?.credentials ??
|
|
12
|
+
getEnvironmentVariable("GOOGLE_VERTEX_AI_WEB_CREDENTIALS");
|
|
13
|
+
if (credentials === undefined)
|
|
14
|
+
throw new Error(`Credentials not found. Please set the GOOGLE_VERTEX_AI_WEB_CREDENTIALS or pass credentials into "authOptions.credentials".`);
|
|
15
|
+
const scope = options?.scope ?? "https://www.googleapis.com/auth/cloud-platform";
|
|
16
|
+
this.options = { ...options, credentials, scope };
|
|
17
|
+
}
|
|
18
|
+
async getProjectId() {
|
|
19
|
+
const credentials = getCredentials(this.options.credentials);
|
|
20
|
+
return credentials.project_id;
|
|
21
|
+
}
|
|
22
|
+
async request(opts) {
|
|
23
|
+
const accessToken = await getAccessToken(this.options);
|
|
24
|
+
if (opts.url == null)
|
|
25
|
+
throw new Error("Missing URL");
|
|
26
|
+
const fetchOptions = {
|
|
27
|
+
method: opts.method,
|
|
28
|
+
headers: {
|
|
29
|
+
Authorization: `Bearer ${accessToken}`,
|
|
30
|
+
"Content-Type": "application/json",
|
|
31
|
+
},
|
|
32
|
+
};
|
|
33
|
+
if (opts.data !== undefined) {
|
|
34
|
+
fetchOptions.body = JSON.stringify(opts.data);
|
|
35
|
+
}
|
|
36
|
+
const res = await fetch(opts.url, fetchOptions);
|
|
37
|
+
if (!res.ok) {
|
|
38
|
+
const error = new Error(`Could not get access token for Vertex AI with status code: ${res.status}`);
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
40
|
+
error.response = res;
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
return {
|
|
44
|
+
data: await res.json(),
|
|
45
|
+
config: {},
|
|
46
|
+
status: res.status,
|
|
47
|
+
statusText: res.statusText,
|
|
48
|
+
headers: res.headers,
|
|
49
|
+
request: { responseURL: res.url },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|