@ai-sdk/google-vertex 5.0.118 → 5.0.120
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 +29 -0
- package/dist/anthropic/edge/index.js +1 -1
- package/dist/edge/index.d.ts +0 -1
- package/dist/edge/index.d.ts.map +1 -1
- package/dist/edge/index.js +22 -22
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +23 -36
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +22 -22
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/docs/16-google-vertex.mdx +60 -7
- package/package.json +6 -6
- package/src/gemini-transcription/google-vertex-gemini-transcription-model-options.ts +40 -31
- package/src/gemini-transcription/google-vertex-gemini-transcription-model.ts +40 -33
- package/src/google-vertex-cloud-tts-speech-model.ts +9 -3
- package/src/google-vertex-embedding-model-options.ts +52 -43
- package/src/google-vertex-embedding-model.ts +28 -18
- package/src/google-vertex-error.ts +20 -9
- package/src/google-vertex-transcription-model-options.ts +40 -31
- package/src/google-vertex-transcription-model.ts +36 -30
- package/src/google-vertex-video-model.ts +32 -25
|
@@ -1,11 +1,70 @@
|
|
|
1
1
|
---
|
|
2
2
|
title: Google Vertex AI
|
|
3
|
-
description: Learn how to use
|
|
3
|
+
description: Learn how to use Google Vertex AI with AI Gateway and the direct provider.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Google Vertex Provider
|
|
7
7
|
|
|
8
8
|
The Google Vertex provider for the [AI SDK](/docs) contains language model support for the [Google Vertex AI](https://cloud.google.com/vertex-ai) APIs. This includes support for [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models), [Anthropic's Claude partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), [xAI's Grok partner models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/grok), and [MaaS (Model as a Service) open models](https://cloud.google.com/vertex-ai/generative-ai/docs/maas/use-open-models).
|
|
9
|
+
Start with [AI Gateway](/providers/ai-sdk-providers/ai-gateway) for models in its catalog (recommended), or use `@ai-sdk/google-vertex` to connect directly to Google Vertex AI.
|
|
10
|
+
|
|
11
|
+
```ts provider="google-vertex" model="google/gemini-4-argon"
|
|
12
|
+
import { generateText } from 'ai';
|
|
13
|
+
__PROVIDER_IMPORT__;
|
|
14
|
+
|
|
15
|
+
const { text } = await generateText({
|
|
16
|
+
model: __MODEL__,
|
|
17
|
+
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
|
|
18
|
+
__GATEWAY_OPTIONS__,
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
console.log(text);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Using AI Gateway
|
|
25
|
+
|
|
26
|
+
The AI SDK uses AI Gateway by default for model strings. Gateway provides access to models across providers through a single API key, with usage and cost tracking. Install `ai`:
|
|
27
|
+
|
|
28
|
+
<InstallPackages packages="ai" />
|
|
29
|
+
|
|
30
|
+
Set an [AI Gateway API key](https://vercel.com/docs/ai-gateway/getting-started) in your environment:
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
export AI_GATEWAY_API_KEY=your_api_key_here
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Vercel deployments can also use [OIDC authentication](/providers/ai-sdk-providers/ai-gateway#oidc-authentication-vercel-deployments).
|
|
37
|
+
See the [AI Gateway provider documentation](/providers/ai-sdk-providers/ai-gateway) for configuration and the [model catalog](https://vercel.com/ai-gateway/models) for available models.
|
|
38
|
+
|
|
39
|
+
The example sets `providerOptions.gateway.order` to `['vertex']`. This sends the request to Google Vertex AI first, then falls back to other available providers of the same model if Google Vertex AI is unavailable or the request fails. `order` sets a preference; it does not restrict fallback to Google Vertex AI. See [provider ordering](https://vercel.com/docs/ai-gateway/models-and-providers/provider-filtering-and-ordering).
|
|
40
|
+
|
|
41
|
+
The dropdown lists models served by Google Vertex AI through Gateway with a corresponding direct-provider example. Provider availability depends on the model and your team's [Provider Allowlist](https://vercel.com/docs/ai-gateway/models-and-providers/provider-filtering-and-ordering).
|
|
42
|
+
|
|
43
|
+
Gateway uses the `vertex` route for Gemini on Google Vertex AI and handles Google Cloud authentication. The example does not use your `GOOGLE_VERTEX_PROJECT`, location, or service-account credentials; use the direct provider to connect to your own project.
|
|
44
|
+
|
|
45
|
+
## Using `@ai-sdk/google-vertex`
|
|
46
|
+
|
|
47
|
+
For direct access to Google Vertex AI, install `ai` and `@ai-sdk/google-vertex`:
|
|
48
|
+
|
|
49
|
+
<InstallPackages packages="ai @ai-sdk/google-vertex" />
|
|
50
|
+
|
|
51
|
+
Set your Google Cloud project, location, and the path to your service-account credentials file:
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
export GOOGLE_VERTEX_PROJECT=your_project_id
|
|
55
|
+
export GOOGLE_VERTEX_LOCATION=us-central1
|
|
56
|
+
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
The Node.js provider uses Google Application Default Credentials. You can also authenticate locally with `gcloud auth application-default login`. See the runtime sections below for Edge and Express Mode authentication.
|
|
60
|
+
|
|
61
|
+
Use the direct provider for Google Cloud authentication, Vertex deployments, partner models, or Vertex-specific APIs. Gateway requests do not use your project configuration.
|
|
62
|
+
|
|
63
|
+
<Note>
|
|
64
|
+
The following sections document the direct `@ai-sdk/google-vertex` provider,
|
|
65
|
+
including its model factories and settings. Gateway model and feature
|
|
66
|
+
availability can differ.
|
|
67
|
+
</Note>
|
|
9
68
|
|
|
10
69
|
<Note>
|
|
11
70
|
The Google Vertex provider is compatible with both Node.js and Edge runtimes.
|
|
@@ -16,12 +75,6 @@ The Google Vertex provider for the [AI SDK](/docs) contains language model suppo
|
|
|
16
75
|
Runtime](#google-vertex-maas-edge-runtime) sections below.
|
|
17
76
|
</Note>
|
|
18
77
|
|
|
19
|
-
## Setup
|
|
20
|
-
|
|
21
|
-
The Google Vertex, Google Vertex Anthropic, Google Vertex xAI, and Google Vertex MaaS providers are available in the `@ai-sdk/google-vertex` module. You can install it with
|
|
22
|
-
|
|
23
|
-
<InstallPackages packages="@ai-sdk/google-vertex" />
|
|
24
|
-
|
|
25
78
|
## Google Vertex Provider Usage
|
|
26
79
|
|
|
27
80
|
The Google Vertex provider instance is used to create model instances that call the Vertex AI API. The models available with this provider include [Google's Gemini models](https://cloud.google.com/vertex-ai/generative-ai/docs/learn/models). If you're looking to use [Anthropic's Claude models](https://cloud.google.com/vertex-ai/generative-ai/docs/partner-models/use-claude), see the [Google Vertex Anthropic Provider](#google-vertex-anthropic-provider-usage) section below.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/google-vertex",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.120",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -71,11 +71,11 @@
|
|
|
71
71
|
}
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@ai-sdk/anthropic": "4.0.
|
|
75
|
-
"@ai-sdk/google": "4.0.
|
|
76
|
-
"@ai-sdk/openai-compatible": "3.0.
|
|
77
|
-
"@ai-sdk/provider": "4.0.
|
|
78
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
74
|
+
"@ai-sdk/anthropic": "4.0.86",
|
|
75
|
+
"@ai-sdk/google": "4.0.103",
|
|
76
|
+
"@ai-sdk/openai-compatible": "3.0.76",
|
|
77
|
+
"@ai-sdk/provider": "4.0.32",
|
|
78
|
+
"@ai-sdk/provider-utils": "5.0.66",
|
|
79
79
|
"google-auth-library": "^10.6.2"
|
|
80
80
|
},
|
|
81
81
|
"devDependencies": {
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
export type GoogleVertexGeminiTranscriptionModelId =
|
|
@@ -11,41 +16,45 @@ export type GoogleVertexGeminiTranscriptionModelId =
|
|
|
11
16
|
* (`gemini-3.5-transcribe-live`) variants. Maps onto Google's
|
|
12
17
|
* `AudioTranscriptionConfig`.
|
|
13
18
|
*/
|
|
14
|
-
export const googleVertexGeminiTranscriptionModelOptions =
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
export const googleVertexGeminiTranscriptionModelOptions = lazySchema(() =>
|
|
20
|
+
zodSchema(
|
|
21
|
+
z.object({
|
|
22
|
+
/**
|
|
23
|
+
* BCP-47 language codes providing hints about the languages present in the
|
|
24
|
+
* audio. If omitted or empty, defaults to automatic language detection.
|
|
25
|
+
*/
|
|
26
|
+
languageCodes: z.array(z.string()).optional(),
|
|
20
27
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Custom vocabulary phrases, which bias the speech recognition model
|
|
30
|
+
* toward recognizing specific terms.
|
|
31
|
+
*/
|
|
32
|
+
customVocabulary: z.array(z.string()).optional(),
|
|
26
33
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
/**
|
|
35
|
+
* Enables word-level timestamp generation.
|
|
36
|
+
*/
|
|
37
|
+
wordTimestamp: z.boolean().optional(),
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
/**
|
|
40
|
+
* Enables speaker diarization.
|
|
41
|
+
*/
|
|
42
|
+
diarization: z.boolean().optional(),
|
|
36
43
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
})
|
|
44
|
+
/**
|
|
45
|
+
* Transcription output formatting mode.
|
|
46
|
+
*
|
|
47
|
+
* - `VERBATIM` (default): exact literal transcript preserving filler
|
|
48
|
+
* words, repetitions, and false starts.
|
|
49
|
+
* - `SMART`: cleans up and structures the transcript in real time —
|
|
50
|
+
* disfluency removal, inline self-corrections, structured formatting
|
|
51
|
+
* (lists, numbers, dates, paragraph breaks), and grammar/casing polish.
|
|
52
|
+
*/
|
|
53
|
+
mode: z.enum(['SMART', 'VERBATIM']).optional(),
|
|
54
|
+
}),
|
|
55
|
+
),
|
|
56
|
+
);
|
|
48
57
|
|
|
49
|
-
export type GoogleVertexTranscriptionModelGeminiOptions =
|
|
58
|
+
export type GoogleVertexTranscriptionModelGeminiOptions = InferSchema<
|
|
50
59
|
typeof googleVertexGeminiTranscriptionModelOptions
|
|
51
60
|
>;
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
type TranscriptionModelV4,
|
|
8
8
|
} from '@ai-sdk/provider';
|
|
9
9
|
import {
|
|
10
|
+
lazySchema,
|
|
11
|
+
zodSchema,
|
|
10
12
|
combineHeaders,
|
|
11
13
|
connectToWebSocket,
|
|
12
14
|
convertToBase64,
|
|
@@ -674,39 +676,44 @@ function parseOffsetSeconds(
|
|
|
674
676
|
return Number.isFinite(parsed) ? parsed : undefined;
|
|
675
677
|
}
|
|
676
678
|
|
|
677
|
-
const googleVertexGeminiTranscriptionWordSchema =
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
.object({
|
|
679
|
+
const googleVertexGeminiTranscriptionWordSchema = () =>
|
|
680
|
+
z.object({
|
|
681
|
+
word: z.string().nullish(),
|
|
682
|
+
startOffset: z.string().nullish(),
|
|
683
|
+
endOffset: z.string().nullish(),
|
|
684
|
+
});
|
|
685
|
+
|
|
686
|
+
const googleVertexGeminiTranscriptionResponseSchema = lazySchema(() =>
|
|
687
|
+
zodSchema(
|
|
688
|
+
z.object({
|
|
689
|
+
candidates: z
|
|
690
|
+
.array(
|
|
691
|
+
z.object({
|
|
692
|
+
content: z
|
|
693
|
+
.object({
|
|
694
|
+
parts: z
|
|
695
|
+
.array(
|
|
696
|
+
z.object({
|
|
695
697
|
text: z.string().nullish(),
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
698
|
+
audioTranscription: z
|
|
699
|
+
.object({
|
|
700
|
+
text: z.string().nullish(),
|
|
701
|
+
languageCode: z.string().nullish(),
|
|
702
|
+
speakerLabel: z.string().nullish(),
|
|
703
|
+
words: z
|
|
704
|
+
.array(googleVertexGeminiTranscriptionWordSchema())
|
|
705
|
+
.nullish(),
|
|
706
|
+
})
|
|
700
707
|
.nullish(),
|
|
701
|
-
})
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
)
|
|
708
|
+
}),
|
|
709
|
+
)
|
|
710
|
+
.nullish(),
|
|
711
|
+
})
|
|
705
712
|
.nullish(),
|
|
706
|
-
})
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
+
}),
|
|
714
|
+
)
|
|
715
|
+
.nullish(),
|
|
716
|
+
usageMetadata: z.record(z.string(), z.unknown()).nullish(),
|
|
717
|
+
}),
|
|
718
|
+
),
|
|
719
|
+
);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { SharedV4Warning, SpeechModelV4 } from '@ai-sdk/provider';
|
|
2
2
|
import {
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
3
5
|
combineHeaders,
|
|
4
6
|
convertBase64ToUint8Array,
|
|
5
7
|
createJsonResponseHandler,
|
|
@@ -183,6 +185,10 @@ export class GoogleVertexCloudTTSSpeechModel implements SpeechModelV4 {
|
|
|
183
185
|
|
|
184
186
|
// Minimal schema: only the fields the implementation reads, with `.nullish()`
|
|
185
187
|
// so provider API changes don't break parsing.
|
|
186
|
-
const googleVertexCloudTTSResponseSchema =
|
|
187
|
-
|
|
188
|
-
|
|
188
|
+
const googleVertexCloudTTSResponseSchema = lazySchema(() =>
|
|
189
|
+
zodSchema(
|
|
190
|
+
z.object({
|
|
191
|
+
audioContent: z.string().nullish(),
|
|
192
|
+
}),
|
|
193
|
+
),
|
|
194
|
+
);
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api
|
|
@@ -15,52 +20,56 @@ export type GoogleVertexEmbeddingModelId =
|
|
|
15
20
|
| 'gemini-embedding-2-preview'
|
|
16
21
|
| (string & {});
|
|
17
22
|
|
|
18
|
-
export const googleVertexEmbeddingModelOptions =
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
export const googleVertexEmbeddingModelOptions = lazySchema(() =>
|
|
24
|
+
zodSchema(
|
|
25
|
+
z.object({
|
|
26
|
+
/**
|
|
27
|
+
* Optional. Optional reduced dimension for the output embedding.
|
|
28
|
+
* If set, excessive values in the output embedding are truncated from the end.
|
|
29
|
+
*/
|
|
30
|
+
outputDimensionality: z.number().optional(),
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
/**
|
|
33
|
+
* Optional. Specifies the task type for generating embeddings.
|
|
34
|
+
* Supported task types:
|
|
35
|
+
* - SEMANTIC_SIMILARITY: Optimized for text similarity.
|
|
36
|
+
* - CLASSIFICATION: Optimized for text classification.
|
|
37
|
+
* - CLUSTERING: Optimized for clustering texts based on similarity.
|
|
38
|
+
* - RETRIEVAL_DOCUMENT: Optimized for document retrieval.
|
|
39
|
+
* - RETRIEVAL_QUERY: Optimized for query-based retrieval.
|
|
40
|
+
* - QUESTION_ANSWERING: Optimized for answering questions.
|
|
41
|
+
* - FACT_VERIFICATION: Optimized for verifying factual information.
|
|
42
|
+
* - CODE_RETRIEVAL_QUERY: Optimized for retrieving code blocks based on natural language queries.
|
|
43
|
+
*/
|
|
44
|
+
taskType: z
|
|
45
|
+
.enum([
|
|
46
|
+
'SEMANTIC_SIMILARITY',
|
|
47
|
+
'CLASSIFICATION',
|
|
48
|
+
'CLUSTERING',
|
|
49
|
+
'RETRIEVAL_DOCUMENT',
|
|
50
|
+
'RETRIEVAL_QUERY',
|
|
51
|
+
'QUESTION_ANSWERING',
|
|
52
|
+
'FACT_VERIFICATION',
|
|
53
|
+
'CODE_RETRIEVAL_QUERY',
|
|
54
|
+
])
|
|
55
|
+
.optional(),
|
|
49
56
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Optional. The title of the document being embedded.
|
|
59
|
+
* Only valid when task_type is set to 'RETRIEVAL_DOCUMENT'.
|
|
60
|
+
* Helps the model produce better embeddings by providing additional context.
|
|
61
|
+
*/
|
|
62
|
+
title: z.string().optional(),
|
|
56
63
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
})
|
|
64
|
+
/**
|
|
65
|
+
* Optional. When set to true, input text will be truncated. When set to false,
|
|
66
|
+
* an error is returned if the input text is longer than the maximum length supported by the model. Defaults to true.
|
|
67
|
+
*/
|
|
68
|
+
autoTruncate: z.boolean().optional(),
|
|
69
|
+
}),
|
|
70
|
+
),
|
|
71
|
+
);
|
|
63
72
|
|
|
64
|
-
export type GoogleVertexEmbeddingModelOptions =
|
|
73
|
+
export type GoogleVertexEmbeddingModelOptions = InferSchema<
|
|
65
74
|
typeof googleVertexEmbeddingModelOptions
|
|
66
75
|
>;
|
|
@@ -3,6 +3,8 @@ import {
|
|
|
3
3
|
type EmbeddingModelV4,
|
|
4
4
|
} from '@ai-sdk/provider';
|
|
5
5
|
import {
|
|
6
|
+
lazySchema,
|
|
7
|
+
zodSchema,
|
|
6
8
|
combineHeaders,
|
|
7
9
|
createJsonResponseHandler,
|
|
8
10
|
postJsonToApi,
|
|
@@ -190,29 +192,37 @@ export class GoogleVertexEmbeddingModel implements EmbeddingModelV4 {
|
|
|
190
192
|
|
|
191
193
|
// minimal version of the schema, focussed on what is needed for the implementation
|
|
192
194
|
// this approach limits breakages when the API changes and increases efficiency
|
|
193
|
-
const googleVertexTextEmbeddingResponseSchema =
|
|
194
|
-
|
|
195
|
+
const googleVertexTextEmbeddingResponseSchema = lazySchema(() =>
|
|
196
|
+
zodSchema(
|
|
195
197
|
z.object({
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
198
|
+
predictions: z.array(
|
|
199
|
+
z.object({
|
|
200
|
+
embeddings: z.object({
|
|
201
|
+
values: z.array(z.number()),
|
|
202
|
+
statistics: z.object({
|
|
203
|
+
token_count: z.number(),
|
|
204
|
+
}),
|
|
205
|
+
}),
|
|
200
206
|
}),
|
|
207
|
+
),
|
|
208
|
+
}),
|
|
209
|
+
),
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
const googleVertexEmbedContentResponseSchema = lazySchema(() =>
|
|
213
|
+
zodSchema(
|
|
214
|
+
z.object({
|
|
215
|
+
embedding: z.object({
|
|
216
|
+
values: z.array(z.number()),
|
|
201
217
|
}),
|
|
218
|
+
usageMetadata: z
|
|
219
|
+
.object({
|
|
220
|
+
promptTokenCount: z.number().nullish(),
|
|
221
|
+
})
|
|
222
|
+
.nullish(),
|
|
202
223
|
}),
|
|
203
224
|
),
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const googleVertexEmbedContentResponseSchema = z.object({
|
|
207
|
-
embedding: z.object({
|
|
208
|
-
values: z.array(z.number()),
|
|
209
|
-
}),
|
|
210
|
-
usageMetadata: z
|
|
211
|
-
.object({
|
|
212
|
-
promptTokenCount: z.number().nullish(),
|
|
213
|
-
})
|
|
214
|
-
.nullish(),
|
|
215
|
-
});
|
|
225
|
+
);
|
|
216
226
|
|
|
217
227
|
function usesEmbedContentEndpoint(modelId: GoogleVertexEmbeddingModelId) {
|
|
218
228
|
return (
|
|
@@ -1,15 +1,26 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
createJsonErrorResponseHandler,
|
|
6
|
+
} from '@ai-sdk/provider-utils';
|
|
2
7
|
import { z } from 'zod/v4';
|
|
3
8
|
|
|
4
|
-
const googleVertexErrorDataSchema =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
const googleVertexErrorDataSchema = lazySchema(() =>
|
|
10
|
+
zodSchema(
|
|
11
|
+
z.object({
|
|
12
|
+
error: z.object({
|
|
13
|
+
code: z.number().nullable(),
|
|
14
|
+
message: z.string(),
|
|
15
|
+
status: z.string(),
|
|
16
|
+
}),
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
);
|
|
11
20
|
|
|
12
|
-
export type GoogleVertexErrorData =
|
|
21
|
+
export type GoogleVertexErrorData = InferSchema<
|
|
22
|
+
typeof googleVertexErrorDataSchema
|
|
23
|
+
>;
|
|
13
24
|
|
|
14
25
|
export const googleVertexFailedResponseHandler = createJsonErrorResponseHandler(
|
|
15
26
|
{
|
|
@@ -1,3 +1,8 @@
|
|
|
1
|
+
import {
|
|
2
|
+
lazySchema,
|
|
3
|
+
zodSchema,
|
|
4
|
+
type InferSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
1
6
|
import { z } from 'zod/v4';
|
|
2
7
|
|
|
3
8
|
// Google Cloud Speech-to-Text transcription models (Speech-to-Text v2).
|
|
@@ -8,40 +13,44 @@ export type GoogleVertexTranscriptionModelId =
|
|
|
8
13
|
| 'telephony'
|
|
9
14
|
| (string & {});
|
|
10
15
|
|
|
11
|
-
export const googleVertexTranscriptionProviderOptionsSchema =
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
export const googleVertexTranscriptionProviderOptionsSchema = lazySchema(() =>
|
|
17
|
+
zodSchema(
|
|
18
|
+
z.object({
|
|
19
|
+
/**
|
|
20
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
21
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
22
|
+
* `telephony`, pass a supported explicit language code.
|
|
23
|
+
*/
|
|
24
|
+
languageCodes: z.array(z.string()).optional(),
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
28
|
+
*/
|
|
29
|
+
enableAutomaticPunctuation: z.boolean().optional(),
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
/**
|
|
32
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
33
|
+
* transcription result can include segments.
|
|
34
|
+
*
|
|
35
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
36
|
+
* for Chirp models.
|
|
37
|
+
*/
|
|
38
|
+
enableWordTimeOffsets: z.boolean().optional(),
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
})
|
|
40
|
+
/**
|
|
41
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
42
|
+
* `'us-central1'`). Defaults to the provider `location`. Must be a single
|
|
43
|
+
* DNS label (letters, digits, and hyphens).
|
|
44
|
+
*
|
|
45
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
46
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
47
|
+
* `global` location.
|
|
48
|
+
*/
|
|
49
|
+
region: z.string().optional(),
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
52
|
+
);
|
|
44
53
|
|
|
45
|
-
export type GoogleVertexTranscriptionModelOptions =
|
|
54
|
+
export type GoogleVertexTranscriptionModelOptions = InferSchema<
|
|
46
55
|
typeof googleVertexTranscriptionProviderOptionsSchema
|
|
47
56
|
>;
|