-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
index.ts
66 lines (60 loc) · 2 KB
/
index.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 { GoogleAuthOptions } from "google-auth-library";
import { GoogleVertexAILLMConnection } from "../../utils/googlevertexai-connection.js";
import { GoogleVertexAIBaseLLMInput } from "../../types/googlevertexai-types.js";
import { BaseGoogleVertexAI } from "./common.js";
import { GAuthClient } from "../../utils/googlevertexai-gauth.js";
/**
* Interface representing the input to the Google Vertex AI model.
*/
export interface GoogleVertexAITextInput
extends GoogleVertexAIBaseLLMInput<GoogleAuthOptions> {}
/**
* Enables calls to the Google Cloud's Vertex AI API to access
* Large Language Models.
*
* To use, you will need to have one of the following authentication
* methods in place:
* - You are logged into an account permitted to the Google Cloud project
* using Vertex AI.
* - You are running this on a machine using a service account permitted to
* the Google Cloud project using Vertex AI.
* - The `GOOGLE_APPLICATION_CREDENTIALS` environment variable is set to the
* path of a credentials file for a service account permitted to the
* Google Cloud project using Vertex AI.
* @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<GoogleAuthOptions> {
static lc_name() {
return "VertexAI";
}
constructor(fields?: GoogleVertexAITextInput) {
super(fields);
const client = new GAuthClient({
scopes: "https://www.googleapis.com/auth/cloud-platform",
...fields?.authOptions,
});
this.connection = new GoogleVertexAILLMConnection(
{ ...fields, ...this },
this.caller,
client,
false
);
this.streamedConnection = new GoogleVertexAILLMConnection(
{ ...fields, ...this },
this.caller,
client,
true
);
}
}