-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
web.ts
66 lines (59 loc) · 1.85 KB
/
web.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import {
WebGoogleAuth,
WebGoogleAuthOptions,
} from "../../utils/googlevertexai-webauth.js";
import { GoogleVertexAILLMConnection } from "../../utils/googlevertexai-connection.js";
import { GoogleVertexAIBaseLLMInput } from "../../types/googlevertexai-types.js";
import { BaseGoogleVertexAI } from "./common.js";
/**
* Interface representing the input to the Google Vertex AI model.
*/
export interface GoogleVertexAITextInput
extends GoogleVertexAIBaseLLMInput<WebGoogleAuthOptions> {}
/**
* Enables calls to the Google Cloud's Vertex AI API to access
* Large Language Models.
*
* This entrypoint and class are intended to be used in web environments like Edge
* functions where you do not have access to the file system. It supports passing
* service account credentials directly as a "GOOGLE_VERTEX_AI_WEB_CREDENTIALS"
* environment variable or directly as "authOptions.credentials".
* @example
* ```typescript
* const model = new GoogleVertexAI({
* temperature: 0.7,
* });
* const stream = await model.stream(
* "What would be a good company name for a company that makes colorful socks?",
* );
* for await (const chunk of stream) {
* console.log(chunk);
* }
* ```
*/
export class GoogleVertexAI extends BaseGoogleVertexAI<WebGoogleAuthOptions> {
static lc_name() {
return "VertexAI";
}
get lc_secrets(): { [key: string]: string } {
return {
"authOptions.credentials": "GOOGLE_VERTEX_AI_WEB_CREDENTIALS",
};
}
constructor(fields?: GoogleVertexAITextInput) {
super(fields);
const client = new WebGoogleAuth(fields?.authOptions);
this.connection = new GoogleVertexAILLMConnection(
{ ...fields, ...this },
this.caller,
client,
false
);
this.streamedConnection = new GoogleVertexAILLMConnection(
{ ...fields, ...this },
this.caller,
client,
true
);
}
}