@ai-sdk/google 4.0.55 → 4.0.57
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 +15 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +29 -8
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +14 -0
- package/dist/internal/index.js +22 -5
- package/dist/internal/index.js.map +1 -1
- package/package.json +2 -2
- package/src/convert-google-usage.ts +3 -0
- package/src/google-language-model.ts +48 -19
- package/src/google-provider.ts +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/google
|
|
2
2
|
|
|
3
|
+
## 4.0.57
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 949ef93: fix(google): recognize Google Files URLs when using a baseUrl
|
|
8
|
+
- Updated dependencies [90192f1]
|
|
9
|
+
- @ai-sdk/provider-utils@5.0.33
|
|
10
|
+
|
|
11
|
+
## 4.0.56
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- 3ad9da9: Preserve complete Google Generative Language usage metadata in raw usage results.
|
|
16
|
+
- e9bc618: Omit unsupported frequency and presence penalties from Gemini 2.5 requests and return warnings instead.
|
|
17
|
+
|
|
3
18
|
## 4.0.55
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -175,18 +175,32 @@ declare const responseSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
175
175
|
} | null | undefined;
|
|
176
176
|
}[] | null | undefined;
|
|
177
177
|
usageMetadata?: {
|
|
178
|
+
[x: string]: unknown;
|
|
178
179
|
cachedContentTokenCount?: number | null | undefined;
|
|
179
180
|
thoughtsTokenCount?: number | null | undefined;
|
|
180
181
|
promptTokenCount?: number | null | undefined;
|
|
181
182
|
candidatesTokenCount?: number | null | undefined;
|
|
183
|
+
toolUsePromptTokenCount?: number | null | undefined;
|
|
182
184
|
totalTokenCount?: number | null | undefined;
|
|
183
185
|
trafficType?: string | null | undefined;
|
|
184
186
|
serviceTier?: string | null | undefined;
|
|
185
187
|
promptTokensDetails?: {
|
|
188
|
+
[x: string]: unknown;
|
|
189
|
+
modality: string;
|
|
190
|
+
tokenCount: number;
|
|
191
|
+
}[] | null | undefined;
|
|
192
|
+
cacheTokensDetails?: {
|
|
193
|
+
[x: string]: unknown;
|
|
186
194
|
modality: string;
|
|
187
195
|
tokenCount: number;
|
|
188
196
|
}[] | null | undefined;
|
|
189
197
|
candidatesTokensDetails?: {
|
|
198
|
+
[x: string]: unknown;
|
|
199
|
+
modality: string;
|
|
200
|
+
tokenCount: number;
|
|
201
|
+
}[] | null | undefined;
|
|
202
|
+
toolUsePromptTokensDetails?: {
|
|
203
|
+
[x: string]: unknown;
|
|
190
204
|
modality: string;
|
|
191
205
|
tokenCount: number;
|
|
192
206
|
}[] | null | undefined;
|
package/dist/index.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
} from "@ai-sdk/provider-utils";
|
|
8
8
|
|
|
9
9
|
// src/version.ts
|
|
10
|
-
var VERSION = true ? "4.0.
|
|
10
|
+
var VERSION = true ? "4.0.57" : "0.0.0-test";
|
|
11
11
|
|
|
12
12
|
// src/google-embedding-model.ts
|
|
13
13
|
import {
|
|
@@ -1806,6 +1806,7 @@ var configurableSafetySettingCategories = [
|
|
|
1806
1806
|
"HARM_CATEGORY_HARASSMENT",
|
|
1807
1807
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT"
|
|
1808
1808
|
];
|
|
1809
|
+
var gemini25ModelPattern2 = /(^|\/)gemini-2\.5(?:[.-]|$)/i;
|
|
1809
1810
|
var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
1810
1811
|
constructor(modelId, config) {
|
|
1811
1812
|
this.specificationVersion = "v4";
|
|
@@ -1923,6 +1924,19 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1923
1924
|
}
|
|
1924
1925
|
}
|
|
1925
1926
|
const isGemmaModel = this.modelId.toLowerCase().startsWith("gemma-");
|
|
1927
|
+
const isGemini25DeveloperApiModel = !isVertexProvider && gemini25ModelPattern2.test(this.modelId);
|
|
1928
|
+
if (isGemini25DeveloperApiModel && frequencyPenalty != null) {
|
|
1929
|
+
warnings.push({
|
|
1930
|
+
type: "unsupported",
|
|
1931
|
+
feature: "frequencyPenalty"
|
|
1932
|
+
});
|
|
1933
|
+
}
|
|
1934
|
+
if (isGemini25DeveloperApiModel && presencePenalty != null) {
|
|
1935
|
+
warnings.push({
|
|
1936
|
+
type: "unsupported",
|
|
1937
|
+
feature: "presencePenalty"
|
|
1938
|
+
});
|
|
1939
|
+
}
|
|
1926
1940
|
const { usesGemini3Features } = getGoogleModelCapabilities(this.modelId);
|
|
1927
1941
|
const { contents, systemInstruction } = convertToGoogleMessages(prompt, {
|
|
1928
1942
|
isGemmaModel,
|
|
@@ -1974,8 +1988,8 @@ var GoogleLanguageModel = class _GoogleLanguageModel {
|
|
|
1974
1988
|
temperature,
|
|
1975
1989
|
topK,
|
|
1976
1990
|
topP,
|
|
1977
|
-
frequencyPenalty,
|
|
1978
|
-
presencePenalty,
|
|
1991
|
+
frequencyPenalty: isGemini25DeveloperApiModel ? void 0 : frequencyPenalty,
|
|
1992
|
+
presencePenalty: isGemini25DeveloperApiModel ? void 0 : presencePenalty,
|
|
1979
1993
|
stopSequences,
|
|
1980
1994
|
seed,
|
|
1981
1995
|
// response format:
|
|
@@ -2936,21 +2950,24 @@ var tokenDetailsSchema = z5.array(
|
|
|
2936
2950
|
z5.object({
|
|
2937
2951
|
modality: z5.string(),
|
|
2938
2952
|
tokenCount: z5.number()
|
|
2939
|
-
})
|
|
2953
|
+
}).loose()
|
|
2940
2954
|
).nullish();
|
|
2941
2955
|
var usageSchema = z5.object({
|
|
2942
2956
|
cachedContentTokenCount: z5.number().nullish(),
|
|
2943
2957
|
thoughtsTokenCount: z5.number().nullish(),
|
|
2944
2958
|
promptTokenCount: z5.number().nullish(),
|
|
2945
2959
|
candidatesTokenCount: z5.number().nullish(),
|
|
2960
|
+
toolUsePromptTokenCount: z5.number().nullish(),
|
|
2946
2961
|
totalTokenCount: z5.number().nullish(),
|
|
2947
2962
|
// https://cloud.google.com/vertex-ai/generative-ai/docs/reference/rest/v1/GenerateContentResponse#TrafficType
|
|
2948
2963
|
trafficType: z5.string().nullish(),
|
|
2949
2964
|
serviceTier: z5.string().nullish(),
|
|
2950
2965
|
// https://ai.google.dev/api/generate-content#Modality
|
|
2951
2966
|
promptTokensDetails: tokenDetailsSchema,
|
|
2952
|
-
|
|
2953
|
-
|
|
2967
|
+
cacheTokensDetails: tokenDetailsSchema,
|
|
2968
|
+
candidatesTokensDetails: tokenDetailsSchema,
|
|
2969
|
+
toolUsePromptTokensDetails: tokenDetailsSchema
|
|
2970
|
+
}).loose();
|
|
2954
2971
|
var getUrlContextMetadataSchema = () => z5.object({
|
|
2955
2972
|
urlMetadata: z5.array(
|
|
2956
2973
|
z5.object({
|
|
@@ -8996,6 +9013,8 @@ function validateGoogleSpeechTranslationInputAudioFormat(inputAudioFormat) {
|
|
|
8996
9013
|
}
|
|
8997
9014
|
|
|
8998
9015
|
// src/google-provider.ts
|
|
9016
|
+
var DEFAULT_BASE_URL = "https://generativelanguage.googleapis.com/v1beta";
|
|
9017
|
+
var googleFilesUrlPattern = /^https:\/\/generativelanguage\.googleapis\.com\/v1beta\/files\/.*$/;
|
|
8999
9018
|
var supportedExternalUrlMediaTypes = [
|
|
9000
9019
|
"text/html",
|
|
9001
9020
|
"text/css",
|
|
@@ -9026,7 +9045,7 @@ function supportsExternalFileUrls(modelId) {
|
|
|
9026
9045
|
}
|
|
9027
9046
|
function createGoogle(options = {}) {
|
|
9028
9047
|
var _a, _b;
|
|
9029
|
-
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a :
|
|
9048
|
+
const baseURL = (_a = withoutTrailingSlash(options.baseURL)) != null ? _a : DEFAULT_BASE_URL;
|
|
9030
9049
|
const providerName = (_b = options.name) != null ? _b : "google.generative-ai";
|
|
9031
9050
|
const getHeaders = () => withUserAgentSuffix2(
|
|
9032
9051
|
{
|
|
@@ -9048,8 +9067,10 @@ function createGoogle(options = {}) {
|
|
|
9048
9067
|
generateId: (_a2 = options.generateId) != null ? _a2 : generateId3,
|
|
9049
9068
|
supportedUrls: () => ({
|
|
9050
9069
|
"*": [
|
|
9051
|
-
// Google Generative Language "files" endpoint
|
|
9070
|
+
// Default Google Generative Language "files" endpoint
|
|
9052
9071
|
// e.g. https://generativelanguage.googleapis.com/v1beta/files/...
|
|
9072
|
+
googleFilesUrlPattern,
|
|
9073
|
+
// Configured Google Generative Language "files" endpoint
|
|
9053
9074
|
new RegExp(`^${baseURL}/files/.*$`),
|
|
9054
9075
|
// YouTube URLs (public or unlisted videos)
|
|
9055
9076
|
new RegExp(
|