@ai-sdk/google-vertex 1.0.4 → 2.0.0
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/CHANGELOG.md +14 -0
- package/README.md +74 -8
- package/dist/index.d.mts +25 -35
- package/dist/index.d.ts +25 -35
- package/dist/index.js +69 -639
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +65 -641
- package/dist/index.mjs.map +1 -1
- package/edge/dist/index.d.mts +73 -0
- package/edge/dist/index.d.ts +73 -0
- package/edge/dist/index.js +298 -0
- package/edge/dist/index.js.map +1 -0
- package/edge/dist/index.mjs +280 -0
- package/edge/dist/index.mjs.map +1 -0
- package/package.json +12 -6
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# @ai-sdk/google-vertex
|
2
2
|
|
3
|
+
## 2.0.0
|
4
|
+
|
5
|
+
### Major Changes
|
6
|
+
|
7
|
+
- 0984f0b: feat (provider/google-vertex): Rewrite for Edge runtime support.
|
8
|
+
|
9
|
+
### Patch Changes
|
10
|
+
|
11
|
+
- 0984f0b: chore (providers/google-vertex): Remove unref'd base default provider.
|
12
|
+
- Updated dependencies [0984f0b]
|
13
|
+
- Updated dependencies [0984f0b]
|
14
|
+
- @ai-sdk/google@1.0.5
|
15
|
+
- @ai-sdk/provider-utils@2.0.3
|
16
|
+
|
3
17
|
## 1.0.4
|
4
18
|
|
5
19
|
### Patch Changes
|
package/README.md
CHANGED
@@ -10,24 +10,90 @@ The Google provider is available in the `@ai-sdk/google-vertex` module. You can
|
|
10
10
|
npm i @ai-sdk/google-vertex
|
11
11
|
```
|
12
12
|
|
13
|
-
##
|
13
|
+
## Authentication & Usage Examples
|
14
14
|
|
15
|
-
|
15
|
+
The Google Vertex provider has two different authentication implementations depending on your runtime environment:
|
16
|
+
|
17
|
+
### Node.js Runtime
|
18
|
+
|
19
|
+
The Node.js runtime is the default runtime supported by the AI SDK. You can use the default provider instance to generate text with the `gemini-1.5-flash` model like this:
|
16
20
|
|
17
21
|
```ts
|
18
22
|
import { vertex } from '@ai-sdk/google-vertex';
|
23
|
+
import { generateText } from 'ai';
|
24
|
+
|
25
|
+
const { text } = await generateText({
|
26
|
+
model: vertex('gemini-1.5-flash'),
|
27
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
28
|
+
});
|
29
|
+
```
|
30
|
+
|
31
|
+
This provider supports all standard Google Cloud authentication options through the [`google-auth-library` ](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#ways-to-authenticate). The most common authentication method is to set the path to a json credentials file in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable. Credentials can be obtained from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
|
32
|
+
|
33
|
+
### Edge Runtime
|
34
|
+
|
35
|
+
The Edge runtime is supported through the `@ai-sdk/google-vertex/edge` module. Note the additional sub-module path `/edge` required to differentiate the Edge provider from the Node.js provider.
|
36
|
+
|
37
|
+
You can use the default provider instance to generate text with the `gemini-1.5-flash` model like this:
|
38
|
+
|
39
|
+
```ts
|
40
|
+
import { vertex } from '@ai-sdk/google-vertex/edge';
|
41
|
+
import { generateText } from 'ai';
|
42
|
+
|
43
|
+
const { text } = await generateText({
|
44
|
+
model: vertex('gemini-1.5-flash'),
|
45
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
46
|
+
});
|
47
|
+
```
|
48
|
+
|
49
|
+
This method supports Google's [Application Default Credentials](https://github.com/googleapis/google-auth-library-nodejs?tab=readme-ov-file#application-default-credentials) through the environment variables `GOOGLE_CLIENT_EMAIL`, `GOOGLE_PRIVATE_KEY`, and (optionally) `GOOGLE_PRIVATE_KEY_ID`. The values can be obtained from a json credentials file obtained from the [Google Cloud Console](https://console.cloud.google.com/apis/credentials).
|
50
|
+
|
51
|
+
## Custom Provider Configuration
|
52
|
+
|
53
|
+
You can create a custom provider instance using the `createVertex` function. This allows you to specify additional configuration options. Below is an example with the default Node.js provider which includes a `googleAuthOptions` object.
|
54
|
+
|
55
|
+
```ts
|
56
|
+
import { createVertex } from '@ai-sdk/google-vertex';
|
57
|
+
import { generateText } from 'ai';
|
58
|
+
|
59
|
+
const customProvider = createVertex({
|
60
|
+
projectId: 'your-project-id',
|
61
|
+
location: 'us-central1',
|
62
|
+
googleAuthOptions: {
|
63
|
+
credentials: {
|
64
|
+
client_email: 'your-client-email',
|
65
|
+
private_key: 'your-private-key',
|
66
|
+
},
|
67
|
+
},
|
68
|
+
});
|
69
|
+
|
70
|
+
const { text } = await generateText({
|
71
|
+
model: customProvider('gemini-1.5-flash'),
|
72
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
73
|
+
});
|
19
74
|
```
|
20
75
|
|
21
|
-
|
76
|
+
The `googleAuthOptions` object is not present in the Edge provider options but custom provider creation is otherwise identical.
|
77
|
+
|
78
|
+
The Edge provider supports a `googleCredentials` option rather than `googleAuthOptions`. This can be used to specify the Google Cloud service account credentials and will take precedence over the environment variables used otherwise.
|
22
79
|
|
23
80
|
```ts
|
24
|
-
import {
|
25
|
-
import { generateText } from 'ai'
|
81
|
+
import { createVertex } from '@ai-sdk/google-vertex/edge';
|
82
|
+
import { generateText } from 'ai';
|
83
|
+
|
84
|
+
const customProvider = createVertex({
|
85
|
+
projectId: 'your-project-id',
|
86
|
+
location: 'us-central1',
|
87
|
+
googleCredentials: {
|
88
|
+
clientEmail: 'your-client-email',
|
89
|
+
privateKey: 'your-private-key',
|
90
|
+
},
|
91
|
+
});
|
26
92
|
|
27
93
|
const { text } = await generateText({
|
28
|
-
model:
|
29
|
-
prompt: 'Write a vegetarian lasagna recipe
|
30
|
-
})
|
94
|
+
model: customProvider('gemini-1.5-flash'),
|
95
|
+
prompt: 'Write a vegetarian lasagna recipe.',
|
96
|
+
});
|
31
97
|
```
|
32
98
|
|
33
99
|
## Documentation
|
package/dist/index.d.mts
CHANGED
@@ -1,30 +1,10 @@
|
|
1
1
|
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider';
|
2
|
-
import {
|
2
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
|
+
import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal';
|
4
|
+
import { GoogleAuthOptions } from 'google-auth-library';
|
3
5
|
|
4
|
-
type GoogleVertexModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro
|
5
|
-
interface GoogleVertexSettings {
|
6
|
-
/**
|
7
|
-
* Optional. Enable structured output. Default is true.
|
8
|
-
*
|
9
|
-
* This is useful when the JSON Schema contains elements that are
|
10
|
-
* not supported by the OpenAPI schema version that
|
11
|
-
* Google Generative AI uses. You can use this to disable
|
12
|
-
* structured outputs if you need to.
|
13
|
-
*/
|
14
|
-
structuredOutputs?: boolean;
|
15
|
-
/**
|
16
|
-
Optional. A list of unique safety settings for blocking unsafe content.
|
17
|
-
*/
|
18
|
-
safetySettings?: Array<{
|
19
|
-
category: 'HARM_CATEGORY_UNSPECIFIED' | 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT';
|
20
|
-
threshold: 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' | 'BLOCK_LOW_AND_ABOVE' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_NONE';
|
21
|
-
}>;
|
22
|
-
/**
|
23
|
-
Optional. When enabled, the model will use Google search to ground the response.
|
24
|
-
|
25
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
26
|
-
*/
|
27
|
-
useSearchGrounding?: boolean;
|
6
|
+
type GoogleVertexModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-vision-001' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-002' | (string & {});
|
7
|
+
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
28
8
|
}
|
29
9
|
|
30
10
|
interface GoogleVertexProvider extends ProviderV1 {
|
@@ -34,7 +14,7 @@ interface GoogleVertexProvider extends ProviderV1 {
|
|
34
14
|
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings): LanguageModelV1;
|
35
15
|
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV1;
|
36
16
|
}
|
37
|
-
interface GoogleVertexProviderSettings {
|
17
|
+
interface GoogleVertexProviderSettings$1 {
|
38
18
|
/**
|
39
19
|
Your Google Vertex location. Defaults to the environment variable `GOOGLE_VERTEX_LOCATION`.
|
40
20
|
*/
|
@@ -43,22 +23,32 @@ interface GoogleVertexProviderSettings {
|
|
43
23
|
Your Google Vertex project. Defaults to the environment variable `GOOGLE_VERTEX_PROJECT`.
|
44
24
|
*/
|
45
25
|
project?: string;
|
26
|
+
/**
|
27
|
+
* Headers to use for requests. Can be:
|
28
|
+
* - A headers object
|
29
|
+
* - A Promise that resolves to a headers object
|
30
|
+
* - A function that returns a headers object
|
31
|
+
* - A function that returns a Promise of a headers object
|
32
|
+
*/
|
33
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
34
|
+
/**
|
35
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
36
|
+
or to provide a custom fetch implementation for e.g. testing.
|
37
|
+
*/
|
38
|
+
fetch?: FetchFunction;
|
39
|
+
generateId?: () => string;
|
40
|
+
}
|
41
|
+
|
42
|
+
interface GoogleVertexProviderSettings extends GoogleVertexProviderSettings$1 {
|
46
43
|
/**
|
47
44
|
Optional. The Authentication options provided by google-auth-library.
|
48
45
|
Complete list of authentication options is documented in the
|
49
46
|
GoogleAuthOptions interface:
|
50
47
|
https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
51
48
|
*/
|
52
|
-
googleAuthOptions?:
|
53
|
-
generateId?: () => string;
|
54
|
-
createVertexAI?: ({ project, location, }: {
|
55
|
-
project: string;
|
56
|
-
location: string;
|
57
|
-
}) => VertexAI;
|
49
|
+
googleAuthOptions?: GoogleAuthOptions;
|
58
50
|
}
|
59
|
-
|
60
|
-
Create a Google Vertex AI provider instance.
|
61
|
-
*/
|
51
|
+
|
62
52
|
declare function createVertex(options?: GoogleVertexProviderSettings): GoogleVertexProvider;
|
63
53
|
/**
|
64
54
|
Default Google Vertex AI provider instance.
|
package/dist/index.d.ts
CHANGED
@@ -1,30 +1,10 @@
|
|
1
1
|
import { ProviderV1, LanguageModelV1 } from '@ai-sdk/provider';
|
2
|
-
import {
|
2
|
+
import { Resolvable, FetchFunction } from '@ai-sdk/provider-utils';
|
3
|
+
import { InternalGoogleGenerativeAISettings } from '@ai-sdk/google/internal';
|
4
|
+
import { GoogleAuthOptions } from 'google-auth-library';
|
3
5
|
|
4
|
-
type GoogleVertexModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro
|
5
|
-
interface GoogleVertexSettings {
|
6
|
-
/**
|
7
|
-
* Optional. Enable structured output. Default is true.
|
8
|
-
*
|
9
|
-
* This is useful when the JSON Schema contains elements that are
|
10
|
-
* not supported by the OpenAPI schema version that
|
11
|
-
* Google Generative AI uses. You can use this to disable
|
12
|
-
* structured outputs if you need to.
|
13
|
-
*/
|
14
|
-
structuredOutputs?: boolean;
|
15
|
-
/**
|
16
|
-
Optional. A list of unique safety settings for blocking unsafe content.
|
17
|
-
*/
|
18
|
-
safetySettings?: Array<{
|
19
|
-
category: 'HARM_CATEGORY_UNSPECIFIED' | 'HARM_CATEGORY_HATE_SPEECH' | 'HARM_CATEGORY_DANGEROUS_CONTENT' | 'HARM_CATEGORY_HARASSMENT' | 'HARM_CATEGORY_SEXUALLY_EXPLICIT';
|
20
|
-
threshold: 'HARM_BLOCK_THRESHOLD_UNSPECIFIED' | 'BLOCK_LOW_AND_ABOVE' | 'BLOCK_MEDIUM_AND_ABOVE' | 'BLOCK_ONLY_HIGH' | 'BLOCK_NONE';
|
21
|
-
}>;
|
22
|
-
/**
|
23
|
-
Optional. When enabled, the model will use Google search to ground the response.
|
24
|
-
|
25
|
-
@see https://cloud.google.com/vertex-ai/generative-ai/docs/grounding/overview
|
26
|
-
*/
|
27
|
-
useSearchGrounding?: boolean;
|
6
|
+
type GoogleVertexModelId = 'gemini-1.5-flash' | 'gemini-1.5-flash-001' | 'gemini-1.5-flash-002' | 'gemini-1.5-pro' | 'gemini-1.5-pro-001' | 'gemini-1.5-pro-002' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-vision-001' | 'gemini-1.0-pro' | 'gemini-1.0-pro-001' | 'gemini-1.0-pro-002' | (string & {});
|
7
|
+
interface GoogleVertexSettings extends InternalGoogleGenerativeAISettings {
|
28
8
|
}
|
29
9
|
|
30
10
|
interface GoogleVertexProvider extends ProviderV1 {
|
@@ -34,7 +14,7 @@ interface GoogleVertexProvider extends ProviderV1 {
|
|
34
14
|
(modelId: GoogleVertexModelId, settings?: GoogleVertexSettings): LanguageModelV1;
|
35
15
|
languageModel: (modelId: GoogleVertexModelId, settings?: GoogleVertexSettings) => LanguageModelV1;
|
36
16
|
}
|
37
|
-
interface GoogleVertexProviderSettings {
|
17
|
+
interface GoogleVertexProviderSettings$1 {
|
38
18
|
/**
|
39
19
|
Your Google Vertex location. Defaults to the environment variable `GOOGLE_VERTEX_LOCATION`.
|
40
20
|
*/
|
@@ -43,22 +23,32 @@ interface GoogleVertexProviderSettings {
|
|
43
23
|
Your Google Vertex project. Defaults to the environment variable `GOOGLE_VERTEX_PROJECT`.
|
44
24
|
*/
|
45
25
|
project?: string;
|
26
|
+
/**
|
27
|
+
* Headers to use for requests. Can be:
|
28
|
+
* - A headers object
|
29
|
+
* - A Promise that resolves to a headers object
|
30
|
+
* - A function that returns a headers object
|
31
|
+
* - A function that returns a Promise of a headers object
|
32
|
+
*/
|
33
|
+
headers?: Resolvable<Record<string, string | undefined>>;
|
34
|
+
/**
|
35
|
+
Custom fetch implementation. You can use it as a middleware to intercept requests,
|
36
|
+
or to provide a custom fetch implementation for e.g. testing.
|
37
|
+
*/
|
38
|
+
fetch?: FetchFunction;
|
39
|
+
generateId?: () => string;
|
40
|
+
}
|
41
|
+
|
42
|
+
interface GoogleVertexProviderSettings extends GoogleVertexProviderSettings$1 {
|
46
43
|
/**
|
47
44
|
Optional. The Authentication options provided by google-auth-library.
|
48
45
|
Complete list of authentication options is documented in the
|
49
46
|
GoogleAuthOptions interface:
|
50
47
|
https://github.com/googleapis/google-auth-library-nodejs/blob/main/src/auth/googleauth.ts.
|
51
48
|
*/
|
52
|
-
googleAuthOptions?:
|
53
|
-
generateId?: () => string;
|
54
|
-
createVertexAI?: ({ project, location, }: {
|
55
|
-
project: string;
|
56
|
-
location: string;
|
57
|
-
}) => VertexAI;
|
49
|
+
googleAuthOptions?: GoogleAuthOptions;
|
58
50
|
}
|
59
|
-
|
60
|
-
Create a Google Vertex AI provider instance.
|
61
|
-
*/
|
51
|
+
|
62
52
|
declare function createVertex(options?: GoogleVertexProviderSettings): GoogleVertexProvider;
|
63
53
|
/**
|
64
54
|
Default Google Vertex AI provider instance.
|