@ai-sdk/google-vertex 5.0.0-canary.98 → 5.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 +195 -0
- package/dist/anthropic/edge/index.d.ts +1 -1
- package/dist/anthropic/edge/index.js +11 -2
- package/dist/anthropic/edge/index.js.map +1 -1
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +10 -1
- package/dist/anthropic/index.js.map +1 -1
- package/dist/edge/index.d.ts +22 -2
- package/dist/edge/index.js +329 -59
- package/dist/edge/index.js.map +1 -1
- package/dist/index.d.ts +32 -3
- package/dist/index.js +329 -59
- package/dist/index.js.map +1 -1
- package/dist/maas/edge/index.js +11 -2
- package/dist/maas/edge/index.js.map +1 -1
- package/dist/maas/index.js +10 -1
- package/dist/maas/index.js.map +1 -1
- package/dist/xai/edge/index.js +1 -1
- package/dist/xai/edge/index.js.map +1 -1
- package/docs/16-google-vertex.mdx +112 -0
- package/package.json +7 -7
- package/src/anthropic/google-vertex-anthropic-options.ts +1 -0
- package/src/anthropic/google-vertex-anthropic-provider.ts +11 -1
- package/src/google-vertex-embedding-model.ts +59 -1
- package/src/google-vertex-provider-base.ts +71 -5
- package/src/google-vertex-speech-model-options.ts +11 -0
- package/src/google-vertex-transcription-model-options.ts +46 -0
- package/src/google-vertex-transcription-model.ts +231 -0
- package/src/google-vertex-video-model.ts +6 -3
- package/src/index.ts +8 -0
- package/src/maas/google-vertex-maas-provider.ts +11 -2
package/dist/edge/index.js
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
// src/edge/google-vertex-provider-edge.ts
|
|
2
|
-
import { loadOptionalSetting as loadOptionalSetting3, resolve as
|
|
2
|
+
import { loadOptionalSetting as loadOptionalSetting3, resolve as resolve6 } from "@ai-sdk/provider-utils";
|
|
3
3
|
|
|
4
4
|
// src/google-vertex-provider-base.ts
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
GoogleLanguageModel as GoogleLanguageModel2,
|
|
7
|
+
GoogleSpeechModel
|
|
8
|
+
} from "@ai-sdk/google/internal";
|
|
6
9
|
import {
|
|
7
10
|
generateId,
|
|
8
11
|
loadOptionalSetting,
|
|
9
12
|
loadSetting,
|
|
10
13
|
normalizeHeaders,
|
|
11
|
-
resolve as
|
|
14
|
+
resolve as resolve5,
|
|
12
15
|
withoutTrailingSlash,
|
|
13
16
|
withUserAgentSuffix
|
|
14
17
|
} from "@ai-sdk/provider-utils";
|
|
15
18
|
|
|
16
19
|
// src/version.ts
|
|
17
|
-
var VERSION = true ? "5.0.0
|
|
20
|
+
var VERSION = true ? "5.0.0" : "0.0.0-test";
|
|
18
21
|
|
|
19
22
|
// src/google-vertex-embedding-model.ts
|
|
20
23
|
import {
|
|
@@ -96,7 +99,6 @@ var googleVertexEmbeddingModelOptions = z2.object({
|
|
|
96
99
|
var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
97
100
|
constructor(modelId, config) {
|
|
98
101
|
this.specificationVersion = "v4";
|
|
99
|
-
this.maxEmbeddingsPerCall = 2048;
|
|
100
102
|
this.supportsParallelCalls = true;
|
|
101
103
|
this.modelId = modelId;
|
|
102
104
|
this.config = config;
|
|
@@ -113,12 +115,18 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
113
115
|
get provider() {
|
|
114
116
|
return this.config.provider;
|
|
115
117
|
}
|
|
118
|
+
// gemini-embedding-2 models only support :embedContent (one value per call),
|
|
119
|
+
// not the :predict batch endpoint. https://github.com/vercel/ai/issues/15853
|
|
120
|
+
get maxEmbeddingsPerCall() {
|
|
121
|
+
return usesEmbedContentEndpoint(this.modelId) ? 1 : 2048;
|
|
122
|
+
}
|
|
116
123
|
async doEmbed({
|
|
117
124
|
values,
|
|
118
125
|
headers,
|
|
119
126
|
abortSignal,
|
|
120
127
|
providerOptions
|
|
121
128
|
}) {
|
|
129
|
+
var _a;
|
|
122
130
|
let googleOptions = await parseProviderOptions({
|
|
123
131
|
provider: "googleVertex",
|
|
124
132
|
providerOptions,
|
|
@@ -151,6 +159,37 @@ var GoogleVertexEmbeddingModel = class _GoogleVertexEmbeddingModel {
|
|
|
151
159
|
this.config.headers ? await resolve(this.config.headers) : void 0,
|
|
152
160
|
headers
|
|
153
161
|
);
|
|
162
|
+
if (usesEmbedContentEndpoint(this.modelId)) {
|
|
163
|
+
const {
|
|
164
|
+
responseHeaders: responseHeaders2,
|
|
165
|
+
value: response2,
|
|
166
|
+
rawValue: rawValue2
|
|
167
|
+
} = await postJsonToApi({
|
|
168
|
+
url: `${this.config.baseURL}/models/${this.modelId}:embedContent`,
|
|
169
|
+
headers: mergedHeaders,
|
|
170
|
+
body: {
|
|
171
|
+
content: { parts: [{ text: values[0] }] },
|
|
172
|
+
embedContentConfig: {
|
|
173
|
+
outputDimensionality: googleOptions.outputDimensionality,
|
|
174
|
+
taskType: googleOptions.taskType,
|
|
175
|
+
title: googleOptions.title,
|
|
176
|
+
autoTruncate: googleOptions.autoTruncate
|
|
177
|
+
}
|
|
178
|
+
},
|
|
179
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
180
|
+
successfulResponseHandler: createJsonResponseHandler(
|
|
181
|
+
googleVertexEmbedContentResponseSchema
|
|
182
|
+
),
|
|
183
|
+
abortSignal,
|
|
184
|
+
fetch: this.config.fetch
|
|
185
|
+
});
|
|
186
|
+
return {
|
|
187
|
+
warnings: [],
|
|
188
|
+
embeddings: [response2.embedding.values],
|
|
189
|
+
usage: ((_a = response2.usageMetadata) == null ? void 0 : _a.promptTokenCount) == null ? void 0 : { tokens: response2.usageMetadata.promptTokenCount },
|
|
190
|
+
response: { headers: responseHeaders2, body: rawValue2 }
|
|
191
|
+
};
|
|
192
|
+
}
|
|
154
193
|
const url = `${this.config.baseURL}/models/${this.modelId}:predict`;
|
|
155
194
|
const {
|
|
156
195
|
responseHeaders,
|
|
@@ -204,6 +243,17 @@ var googleVertexTextEmbeddingResponseSchema = z3.object({
|
|
|
204
243
|
})
|
|
205
244
|
)
|
|
206
245
|
});
|
|
246
|
+
var googleVertexEmbedContentResponseSchema = z3.object({
|
|
247
|
+
embedding: z3.object({
|
|
248
|
+
values: z3.array(z3.number())
|
|
249
|
+
}),
|
|
250
|
+
usageMetadata: z3.object({
|
|
251
|
+
promptTokenCount: z3.number().nullish()
|
|
252
|
+
}).nullish()
|
|
253
|
+
});
|
|
254
|
+
function usesEmbedContentEndpoint(modelId) {
|
|
255
|
+
return modelId === "gemini-embedding-2" || modelId === "gemini-embedding-2-preview";
|
|
256
|
+
}
|
|
207
257
|
|
|
208
258
|
// src/google-vertex-image-model.ts
|
|
209
259
|
import { GoogleLanguageModel } from "@ai-sdk/google/internal";
|
|
@@ -590,37 +640,228 @@ var googleVertexTools = {
|
|
|
590
640
|
vertexRagStore: googleTools.vertexRagStore
|
|
591
641
|
};
|
|
592
642
|
|
|
593
|
-
// src/google-vertex-
|
|
594
|
-
import {
|
|
595
|
-
AISDKError
|
|
596
|
-
} from "@ai-sdk/provider";
|
|
643
|
+
// src/google-vertex-transcription-model.ts
|
|
597
644
|
import {
|
|
598
645
|
combineHeaders as combineHeaders3,
|
|
599
646
|
convertUint8ArrayToBase64 as convertUint8ArrayToBase642,
|
|
600
647
|
createJsonResponseHandler as createJsonResponseHandler3,
|
|
601
|
-
delay,
|
|
602
648
|
parseProviderOptions as parseProviderOptions3,
|
|
603
649
|
postJsonToApi as postJsonToApi3,
|
|
604
|
-
resolve as resolve3
|
|
650
|
+
resolve as resolve3,
|
|
651
|
+
serializeModelOptions as serializeModelOptions3,
|
|
652
|
+
WORKFLOW_DESERIALIZE as WORKFLOW_DESERIALIZE3,
|
|
653
|
+
WORKFLOW_SERIALIZE as WORKFLOW_SERIALIZE3
|
|
605
654
|
} from "@ai-sdk/provider-utils";
|
|
606
655
|
import { z as z7 } from "zod/v4";
|
|
607
656
|
|
|
657
|
+
// src/google-vertex-transcription-model-options.ts
|
|
658
|
+
import { z as z6 } from "zod/v4";
|
|
659
|
+
var googleVertexTranscriptionProviderOptionsSchema = z6.object({
|
|
660
|
+
/**
|
|
661
|
+
* BCP-47 language codes to recognize (e.g. `['en-US']`), or `['auto']` to let
|
|
662
|
+
* Chirp auto-detect the spoken language. Defaults to `['auto']`. For
|
|
663
|
+
* `telephony`, pass a supported explicit language code.
|
|
664
|
+
*/
|
|
665
|
+
languageCodes: z6.array(z6.string()).optional(),
|
|
666
|
+
/**
|
|
667
|
+
* Whether to add punctuation to the transcript. Defaults to `true`.
|
|
668
|
+
*/
|
|
669
|
+
enableAutomaticPunctuation: z6.boolean().optional(),
|
|
670
|
+
/**
|
|
671
|
+
* Whether to include word-level timestamps. Defaults to `true` so the
|
|
672
|
+
* transcription result can include segments.
|
|
673
|
+
*
|
|
674
|
+
* Enabling word-level timestamps can reduce transcription quality and speed
|
|
675
|
+
* for Chirp models.
|
|
676
|
+
*/
|
|
677
|
+
enableWordTimeOffsets: z6.boolean().optional(),
|
|
678
|
+
/**
|
|
679
|
+
* The Cloud Speech-to-Text region for the request (e.g. `'us'`, `'eu'`,
|
|
680
|
+
* `'us-central1'`). Defaults to the provider `location`.
|
|
681
|
+
*
|
|
682
|
+
* Note: Speech-to-Text regions differ from Vertex AI regions. Chirp is only
|
|
683
|
+
* available in specific Speech-to-Text regions and is not available in the
|
|
684
|
+
* `global` location.
|
|
685
|
+
*/
|
|
686
|
+
region: z6.string().optional()
|
|
687
|
+
});
|
|
688
|
+
|
|
689
|
+
// src/google-vertex-transcription-model.ts
|
|
690
|
+
function parseDurationSeconds(value) {
|
|
691
|
+
if (value == null) {
|
|
692
|
+
return void 0;
|
|
693
|
+
}
|
|
694
|
+
const seconds = Number.parseFloat(value);
|
|
695
|
+
return Number.isFinite(seconds) ? seconds : void 0;
|
|
696
|
+
}
|
|
697
|
+
function convertBcp47ToIso6391(value) {
|
|
698
|
+
if (value == null) {
|
|
699
|
+
return void 0;
|
|
700
|
+
}
|
|
701
|
+
try {
|
|
702
|
+
const language = new Intl.Locale(value).language;
|
|
703
|
+
return language.length === 2 ? language : void 0;
|
|
704
|
+
} catch (e) {
|
|
705
|
+
return void 0;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
var GoogleVertexTranscriptionModel = class _GoogleVertexTranscriptionModel {
|
|
709
|
+
constructor(modelId, config) {
|
|
710
|
+
this.modelId = modelId;
|
|
711
|
+
this.config = config;
|
|
712
|
+
this.specificationVersion = "v4";
|
|
713
|
+
}
|
|
714
|
+
static [WORKFLOW_SERIALIZE3](model) {
|
|
715
|
+
return serializeModelOptions3({
|
|
716
|
+
modelId: model.modelId,
|
|
717
|
+
config: model.config
|
|
718
|
+
});
|
|
719
|
+
}
|
|
720
|
+
static [WORKFLOW_DESERIALIZE3](options) {
|
|
721
|
+
return new _GoogleVertexTranscriptionModel(options.modelId, options.config);
|
|
722
|
+
}
|
|
723
|
+
get provider() {
|
|
724
|
+
return this.config.provider;
|
|
725
|
+
}
|
|
726
|
+
async doGenerate(options) {
|
|
727
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
728
|
+
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
729
|
+
const warnings = [];
|
|
730
|
+
let googleOptions;
|
|
731
|
+
for (const provider of ["googleVertex", "vertex", "google"]) {
|
|
732
|
+
googleOptions = await parseProviderOptions3({
|
|
733
|
+
provider,
|
|
734
|
+
providerOptions: options.providerOptions,
|
|
735
|
+
schema: googleVertexTranscriptionProviderOptionsSchema
|
|
736
|
+
});
|
|
737
|
+
if (googleOptions != null) {
|
|
738
|
+
break;
|
|
739
|
+
}
|
|
740
|
+
}
|
|
741
|
+
const region = (_d = googleOptions == null ? void 0 : googleOptions.region) != null ? _d : this.config.location;
|
|
742
|
+
const languageCodes = (_e = googleOptions == null ? void 0 : googleOptions.languageCodes) != null ? _e : ["auto"];
|
|
743
|
+
const content = typeof options.audio === "string" ? options.audio : convertUint8ArrayToBase642(options.audio);
|
|
744
|
+
const requestBody = {
|
|
745
|
+
config: {
|
|
746
|
+
model: this.modelId,
|
|
747
|
+
languageCodes,
|
|
748
|
+
// Let Speech-to-Text auto-detect the audio encoding (wav/mp3/flac/…).
|
|
749
|
+
autoDecodingConfig: {},
|
|
750
|
+
features: {
|
|
751
|
+
// Word timing populates `segments`.
|
|
752
|
+
enableWordTimeOffsets: (_f = googleOptions == null ? void 0 : googleOptions.enableWordTimeOffsets) != null ? _f : true,
|
|
753
|
+
enableAutomaticPunctuation: (_g = googleOptions == null ? void 0 : googleOptions.enableAutomaticPunctuation) != null ? _g : true
|
|
754
|
+
}
|
|
755
|
+
},
|
|
756
|
+
content
|
|
757
|
+
};
|
|
758
|
+
const host = region === "global" ? "speech.googleapis.com" : `${region}-speech.googleapis.com`;
|
|
759
|
+
const url = `https://${host}/v2/projects/${this.config.project}/locations/${region}/recognizers/_:recognize`;
|
|
760
|
+
const {
|
|
761
|
+
value: response,
|
|
762
|
+
responseHeaders,
|
|
763
|
+
rawValue: rawResponse
|
|
764
|
+
} = await postJsonToApi3({
|
|
765
|
+
url,
|
|
766
|
+
headers: combineHeaders3(
|
|
767
|
+
this.config.headers ? await resolve3(this.config.headers) : void 0,
|
|
768
|
+
options.headers
|
|
769
|
+
),
|
|
770
|
+
body: requestBody,
|
|
771
|
+
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
772
|
+
successfulResponseHandler: createJsonResponseHandler3(
|
|
773
|
+
googleVertexTranscriptionResponseSchema
|
|
774
|
+
),
|
|
775
|
+
abortSignal: options.abortSignal,
|
|
776
|
+
fetch: this.config.fetch
|
|
777
|
+
});
|
|
778
|
+
const results = (_h = response.results) != null ? _h : [];
|
|
779
|
+
const text = results.map((result) => {
|
|
780
|
+
var _a2, _b2, _c2;
|
|
781
|
+
return (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.transcript) != null ? _c2 : "";
|
|
782
|
+
}).join(" ").trim();
|
|
783
|
+
const segments = results.flatMap(
|
|
784
|
+
(result) => {
|
|
785
|
+
var _a2, _b2, _c2, _d2;
|
|
786
|
+
return (_d2 = (_c2 = (_b2 = (_a2 = result.alternatives) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.words) == null ? void 0 : _c2.flatMap((word) => {
|
|
787
|
+
const startSecond = parseDurationSeconds(word.startOffset);
|
|
788
|
+
const endSecond = parseDurationSeconds(word.endOffset);
|
|
789
|
+
return word.word == null || startSecond == null || endSecond == null ? [] : [{ text: word.word, startSecond, endSecond }];
|
|
790
|
+
})) != null ? _d2 : [];
|
|
791
|
+
}
|
|
792
|
+
);
|
|
793
|
+
const language = convertBcp47ToIso6391((_i = results[0]) == null ? void 0 : _i.languageCode);
|
|
794
|
+
return {
|
|
795
|
+
text,
|
|
796
|
+
segments,
|
|
797
|
+
language,
|
|
798
|
+
durationInSeconds: parseDurationSeconds(
|
|
799
|
+
(_j = response.metadata) == null ? void 0 : _j.totalBilledDuration
|
|
800
|
+
),
|
|
801
|
+
warnings,
|
|
802
|
+
response: {
|
|
803
|
+
timestamp: currentDate,
|
|
804
|
+
modelId: this.modelId,
|
|
805
|
+
headers: responseHeaders,
|
|
806
|
+
body: rawResponse
|
|
807
|
+
}
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
var googleVertexTranscriptionResponseSchema = z7.object({
|
|
812
|
+
results: z7.array(
|
|
813
|
+
z7.object({
|
|
814
|
+
alternatives: z7.array(
|
|
815
|
+
z7.object({
|
|
816
|
+
transcript: z7.string().nullish(),
|
|
817
|
+
words: z7.array(
|
|
818
|
+
z7.object({
|
|
819
|
+
word: z7.string().nullish(),
|
|
820
|
+
startOffset: z7.string().nullish(),
|
|
821
|
+
endOffset: z7.string().nullish()
|
|
822
|
+
})
|
|
823
|
+
).nullish()
|
|
824
|
+
})
|
|
825
|
+
).nullish(),
|
|
826
|
+
languageCode: z7.string().nullish()
|
|
827
|
+
})
|
|
828
|
+
).nullish(),
|
|
829
|
+
metadata: z7.object({
|
|
830
|
+
totalBilledDuration: z7.string().nullish()
|
|
831
|
+
}).nullish()
|
|
832
|
+
});
|
|
833
|
+
|
|
834
|
+
// src/google-vertex-video-model.ts
|
|
835
|
+
import {
|
|
836
|
+
AISDKError
|
|
837
|
+
} from "@ai-sdk/provider";
|
|
838
|
+
import {
|
|
839
|
+
combineHeaders as combineHeaders4,
|
|
840
|
+
convertUint8ArrayToBase64 as convertUint8ArrayToBase643,
|
|
841
|
+
createJsonResponseHandler as createJsonResponseHandler4,
|
|
842
|
+
delay,
|
|
843
|
+
parseProviderOptions as parseProviderOptions4,
|
|
844
|
+
postJsonToApi as postJsonToApi4,
|
|
845
|
+
resolve as resolve4
|
|
846
|
+
} from "@ai-sdk/provider-utils";
|
|
847
|
+
import { z as z9 } from "zod/v4";
|
|
848
|
+
|
|
608
849
|
// src/google-vertex-video-model-options.ts
|
|
609
850
|
import { lazySchema, zodSchema } from "@ai-sdk/provider-utils";
|
|
610
|
-
import { z as
|
|
851
|
+
import { z as z8 } from "zod/v4";
|
|
611
852
|
var googleVertexVideoModelOptionsSchema = lazySchema(
|
|
612
853
|
() => zodSchema(
|
|
613
|
-
|
|
614
|
-
pollIntervalMs:
|
|
615
|
-
pollTimeoutMs:
|
|
616
|
-
personGeneration:
|
|
617
|
-
negativePrompt:
|
|
618
|
-
generateAudio:
|
|
619
|
-
gcsOutputDirectory:
|
|
620
|
-
referenceImages:
|
|
621
|
-
|
|
622
|
-
bytesBase64Encoded:
|
|
623
|
-
gcsUri:
|
|
854
|
+
z8.object({
|
|
855
|
+
pollIntervalMs: z8.number().positive().nullish(),
|
|
856
|
+
pollTimeoutMs: z8.number().positive().nullish(),
|
|
857
|
+
personGeneration: z8.enum(["dont_allow", "allow_adult", "allow_all"]).nullish(),
|
|
858
|
+
negativePrompt: z8.string().nullish(),
|
|
859
|
+
generateAudio: z8.boolean().nullish(),
|
|
860
|
+
gcsOutputDirectory: z8.string().nullish(),
|
|
861
|
+
referenceImages: z8.array(
|
|
862
|
+
z8.object({
|
|
863
|
+
bytesBase64Encoded: z8.string().nullish(),
|
|
864
|
+
gcsUri: z8.string().nullish()
|
|
624
865
|
})
|
|
625
866
|
).nullish()
|
|
626
867
|
}).passthrough()
|
|
@@ -641,14 +882,14 @@ var GoogleVertexVideoModel = class {
|
|
|
641
882
|
return 4;
|
|
642
883
|
}
|
|
643
884
|
async doGenerate(options) {
|
|
644
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
885
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
645
886
|
const currentDate = (_c = (_b = (_a = this.config._internal) == null ? void 0 : _a.currentDate) == null ? void 0 : _b.call(_a)) != null ? _c : /* @__PURE__ */ new Date();
|
|
646
887
|
const warnings = [];
|
|
647
|
-
const googleVertexOptions = (_d = await
|
|
888
|
+
const googleVertexOptions = (_d = await parseProviderOptions4({
|
|
648
889
|
provider: "googleVertex",
|
|
649
890
|
providerOptions: options.providerOptions,
|
|
650
891
|
schema: googleVertexVideoModelOptionsSchema
|
|
651
|
-
})) != null ? _d : await
|
|
892
|
+
})) != null ? _d : await parseProviderOptions4({
|
|
652
893
|
provider: "vertex",
|
|
653
894
|
providerOptions: options.providerOptions,
|
|
654
895
|
schema: googleVertexVideoModelOptionsSchema
|
|
@@ -666,7 +907,7 @@ var GoogleVertexVideoModel = class {
|
|
|
666
907
|
details: "Vertex AI video models require base64-encoded images or GCS URIs. URL will be ignored."
|
|
667
908
|
});
|
|
668
909
|
} else {
|
|
669
|
-
const base64Data = typeof options.image.data === "string" ? options.image.data :
|
|
910
|
+
const base64Data = typeof options.image.data === "string" ? options.image.data : convertUint8ArrayToBase643(options.image.data);
|
|
670
911
|
instance.image = {
|
|
671
912
|
bytesBase64Encoded: base64Data,
|
|
672
913
|
mimeType: options.image.mediaType
|
|
@@ -696,6 +937,10 @@ var GoogleVertexVideoModel = class {
|
|
|
696
937
|
if (options.seed) {
|
|
697
938
|
parameters.seed = options.seed;
|
|
698
939
|
}
|
|
940
|
+
const generateAudio = (_e = options.generateAudio) != null ? _e : googleVertexOptions == null ? void 0 : googleVertexOptions.generateAudio;
|
|
941
|
+
if (generateAudio != null) {
|
|
942
|
+
parameters.generateAudio = generateAudio;
|
|
943
|
+
}
|
|
699
944
|
if (googleVertexOptions != null) {
|
|
700
945
|
const opts = googleVertexOptions;
|
|
701
946
|
if (opts.personGeneration !== void 0 && opts.personGeneration !== null) {
|
|
@@ -704,9 +949,6 @@ var GoogleVertexVideoModel = class {
|
|
|
704
949
|
if (opts.negativePrompt !== void 0 && opts.negativePrompt !== null) {
|
|
705
950
|
parameters.negativePrompt = opts.negativePrompt;
|
|
706
951
|
}
|
|
707
|
-
if (opts.generateAudio !== void 0 && opts.generateAudio !== null) {
|
|
708
|
-
parameters.generateAudio = opts.generateAudio;
|
|
709
|
-
}
|
|
710
952
|
if (opts.gcsOutputDirectory !== void 0 && opts.gcsOutputDirectory !== null) {
|
|
711
953
|
parameters.gcsOutputDirectory = opts.gcsOutputDirectory;
|
|
712
954
|
}
|
|
@@ -724,17 +966,17 @@ var GoogleVertexVideoModel = class {
|
|
|
724
966
|
}
|
|
725
967
|
}
|
|
726
968
|
}
|
|
727
|
-
const { value: operation } = await
|
|
969
|
+
const { value: operation } = await postJsonToApi4({
|
|
728
970
|
url: `${this.config.baseURL}/models/${this.modelId}:predictLongRunning`,
|
|
729
|
-
headers:
|
|
730
|
-
await
|
|
971
|
+
headers: combineHeaders4(
|
|
972
|
+
await resolve4(this.config.headers),
|
|
731
973
|
options.headers
|
|
732
974
|
),
|
|
733
975
|
body: {
|
|
734
976
|
instances,
|
|
735
977
|
parameters
|
|
736
978
|
},
|
|
737
|
-
successfulResponseHandler:
|
|
979
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
738
980
|
googleVertexOperationSchema
|
|
739
981
|
),
|
|
740
982
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -748,8 +990,8 @@ var GoogleVertexVideoModel = class {
|
|
|
748
990
|
message: "No operation name returned from API"
|
|
749
991
|
});
|
|
750
992
|
}
|
|
751
|
-
const pollIntervalMs = (
|
|
752
|
-
const pollTimeoutMs = (
|
|
993
|
+
const pollIntervalMs = (_f = googleVertexOptions == null ? void 0 : googleVertexOptions.pollIntervalMs) != null ? _f : 1e4;
|
|
994
|
+
const pollTimeoutMs = (_g = googleVertexOptions == null ? void 0 : googleVertexOptions.pollTimeoutMs) != null ? _g : 6e5;
|
|
753
995
|
const startTime = Date.now();
|
|
754
996
|
let finalOperation = operation;
|
|
755
997
|
let responseHeaders;
|
|
@@ -761,22 +1003,22 @@ var GoogleVertexVideoModel = class {
|
|
|
761
1003
|
});
|
|
762
1004
|
}
|
|
763
1005
|
await delay(pollIntervalMs);
|
|
764
|
-
if ((
|
|
1006
|
+
if ((_h = options.abortSignal) == null ? void 0 : _h.aborted) {
|
|
765
1007
|
throw new AISDKError({
|
|
766
1008
|
name: "VERTEX_VIDEO_GENERATION_ABORTED",
|
|
767
1009
|
message: "Video generation request was aborted"
|
|
768
1010
|
});
|
|
769
1011
|
}
|
|
770
|
-
const { value: statusOperation, responseHeaders: pollHeaders } = await
|
|
1012
|
+
const { value: statusOperation, responseHeaders: pollHeaders } = await postJsonToApi4({
|
|
771
1013
|
url: `${this.config.baseURL}/models/${this.modelId}:fetchPredictOperation`,
|
|
772
|
-
headers:
|
|
773
|
-
await
|
|
1014
|
+
headers: combineHeaders4(
|
|
1015
|
+
await resolve4(this.config.headers),
|
|
774
1016
|
options.headers
|
|
775
1017
|
),
|
|
776
1018
|
body: {
|
|
777
1019
|
operationName
|
|
778
1020
|
},
|
|
779
|
-
successfulResponseHandler:
|
|
1021
|
+
successfulResponseHandler: createJsonResponseHandler4(
|
|
780
1022
|
googleVertexOperationSchema
|
|
781
1023
|
),
|
|
782
1024
|
failedResponseHandler: googleVertexFailedResponseHandler,
|
|
@@ -849,23 +1091,23 @@ var GoogleVertexVideoModel = class {
|
|
|
849
1091
|
};
|
|
850
1092
|
}
|
|
851
1093
|
};
|
|
852
|
-
var googleVertexOperationSchema =
|
|
853
|
-
name:
|
|
854
|
-
done:
|
|
855
|
-
error:
|
|
856
|
-
code:
|
|
857
|
-
message:
|
|
858
|
-
status:
|
|
1094
|
+
var googleVertexOperationSchema = z9.object({
|
|
1095
|
+
name: z9.string().nullish(),
|
|
1096
|
+
done: z9.boolean().nullish(),
|
|
1097
|
+
error: z9.object({
|
|
1098
|
+
code: z9.number().nullish(),
|
|
1099
|
+
message: z9.string(),
|
|
1100
|
+
status: z9.string().nullish()
|
|
859
1101
|
}).nullish(),
|
|
860
|
-
response:
|
|
861
|
-
videos:
|
|
862
|
-
|
|
863
|
-
bytesBase64Encoded:
|
|
864
|
-
gcsUri:
|
|
865
|
-
mimeType:
|
|
1102
|
+
response: z9.object({
|
|
1103
|
+
videos: z9.array(
|
|
1104
|
+
z9.object({
|
|
1105
|
+
bytesBase64Encoded: z9.string().nullish(),
|
|
1106
|
+
gcsUri: z9.string().nullish(),
|
|
1107
|
+
mimeType: z9.string().nullish()
|
|
866
1108
|
})
|
|
867
1109
|
).nullish(),
|
|
868
|
-
raiMediaFilteredCount:
|
|
1110
|
+
raiMediaFilteredCount: z9.number().nullish()
|
|
869
1111
|
}).nullish()
|
|
870
1112
|
});
|
|
871
1113
|
|
|
@@ -907,13 +1149,21 @@ function createGoogleVertex(options = {}) {
|
|
|
907
1149
|
}
|
|
908
1150
|
const region = loadGoogleVertexLocation();
|
|
909
1151
|
const project = loadGoogleVertexProject();
|
|
910
|
-
const
|
|
911
|
-
|
|
1152
|
+
const getHost = () => {
|
|
1153
|
+
if (region === "global") {
|
|
1154
|
+
return "aiplatform.googleapis.com";
|
|
1155
|
+
} else if (region === "eu" || region === "us") {
|
|
1156
|
+
return `aiplatform.${region}.rep.googleapis.com`;
|
|
1157
|
+
} else {
|
|
1158
|
+
return `${region}-aiplatform.googleapis.com`;
|
|
1159
|
+
}
|
|
1160
|
+
};
|
|
1161
|
+
return (_b = withoutTrailingSlash(options.baseURL)) != null ? _b : `https://${getHost()}/v1beta1/projects/${project}/locations/${region}/publishers/google`;
|
|
912
1162
|
};
|
|
913
1163
|
const createConfig = (name) => {
|
|
914
1164
|
const getHeaders = async () => {
|
|
915
1165
|
var _a;
|
|
916
|
-
const originalHeaders = await
|
|
1166
|
+
const originalHeaders = await resolve5((_a = options.headers) != null ? _a : {});
|
|
917
1167
|
return withUserAgentSuffix(
|
|
918
1168
|
originalHeaders,
|
|
919
1169
|
`ai-sdk/google-vertex/${VERSION}`
|
|
@@ -956,6 +1206,22 @@ function createGoogleVertex(options = {}) {
|
|
|
956
1206
|
generateId: (_a = options.generateId) != null ? _a : generateId
|
|
957
1207
|
});
|
|
958
1208
|
};
|
|
1209
|
+
const createSpeechModel = (modelId) => new GoogleSpeechModel(modelId, createConfig("speech"));
|
|
1210
|
+
const createTranscriptionModel = (modelId) => {
|
|
1211
|
+
if (apiKey) {
|
|
1212
|
+
throw new Error(
|
|
1213
|
+
"Google Vertex transcription models do not support Express Mode API keys. Use standard Google Cloud credentials instead."
|
|
1214
|
+
);
|
|
1215
|
+
}
|
|
1216
|
+
const config = createConfig("transcription");
|
|
1217
|
+
return new GoogleVertexTranscriptionModel(modelId, {
|
|
1218
|
+
provider: config.provider,
|
|
1219
|
+
headers: config.headers,
|
|
1220
|
+
fetch: config.fetch,
|
|
1221
|
+
project: loadGoogleVertexProject(),
|
|
1222
|
+
location: loadGoogleVertexLocation()
|
|
1223
|
+
});
|
|
1224
|
+
};
|
|
959
1225
|
const provider = function(modelId) {
|
|
960
1226
|
if (new.target) {
|
|
961
1227
|
throw new Error(
|
|
@@ -972,6 +1238,10 @@ function createGoogleVertex(options = {}) {
|
|
|
972
1238
|
provider.imageModel = createImageModel;
|
|
973
1239
|
provider.video = createVideoModel;
|
|
974
1240
|
provider.videoModel = createVideoModel;
|
|
1241
|
+
provider.speech = createSpeechModel;
|
|
1242
|
+
provider.speechModel = createSpeechModel;
|
|
1243
|
+
provider.transcription = createTranscriptionModel;
|
|
1244
|
+
provider.transcriptionModel = createTranscriptionModel;
|
|
975
1245
|
provider.tools = googleVertexTools;
|
|
976
1246
|
return provider;
|
|
977
1247
|
}
|
|
@@ -1102,7 +1372,7 @@ function createGoogleVertex2(options = {}) {
|
|
|
1102
1372
|
Authorization: `Bearer ${await generateAuthToken(
|
|
1103
1373
|
options.googleCredentials
|
|
1104
1374
|
)}`,
|
|
1105
|
-
...await
|
|
1375
|
+
...await resolve6(options.headers)
|
|
1106
1376
|
})
|
|
1107
1377
|
});
|
|
1108
1378
|
}
|