@ai-sdk/google 2.0.0-canary.6 → 2.0.0-canary.8
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 +35 -0
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +48 -39
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +36 -25
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.js +39 -34
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +29 -22
- package/dist/internal/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,40 @@
|
|
1
1
|
# @ai-sdk/google
|
2
2
|
|
3
|
+
## 2.0.0-canary.8
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 26735b5: chore(embedding-model): add v2 interface
|
8
|
+
- 443d8ec: feat(embedding-model-v2): add response body field
|
9
|
+
- fd65bc6: chore(embedding-model-v2): rename rawResponse to response
|
10
|
+
- Updated dependencies [26735b5]
|
11
|
+
- Updated dependencies [443d8ec]
|
12
|
+
- Updated dependencies [14c9410]
|
13
|
+
- Updated dependencies [d9c98f4]
|
14
|
+
- Updated dependencies [c4a2fec]
|
15
|
+
- Updated dependencies [0054544]
|
16
|
+
- Updated dependencies [9e9c809]
|
17
|
+
- Updated dependencies [32831c6]
|
18
|
+
- Updated dependencies [d0f9495]
|
19
|
+
- Updated dependencies [fd65bc6]
|
20
|
+
- Updated dependencies [393138b]
|
21
|
+
- Updated dependencies [7182d14]
|
22
|
+
- @ai-sdk/provider@2.0.0-canary.6
|
23
|
+
- @ai-sdk/provider-utils@3.0.0-canary.7
|
24
|
+
|
25
|
+
## 2.0.0-canary.7
|
26
|
+
|
27
|
+
### Patch Changes
|
28
|
+
|
29
|
+
- f10304b: feat(tool-calling): don't require the user to have to pass parameters
|
30
|
+
- Updated dependencies [411e483]
|
31
|
+
- Updated dependencies [79457bd]
|
32
|
+
- Updated dependencies [ad80501]
|
33
|
+
- Updated dependencies [1766ede]
|
34
|
+
- Updated dependencies [f10304b]
|
35
|
+
- @ai-sdk/provider@2.0.0-canary.5
|
36
|
+
- @ai-sdk/provider-utils@3.0.0-canary.6
|
37
|
+
|
3
38
|
## 2.0.0-canary.6
|
4
39
|
|
5
40
|
### Patch Changes
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { z } from 'zod';
|
2
|
-
import { ProviderV2, LanguageModelV2,
|
2
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
|
3
3
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
4
4
|
|
5
5
|
declare const googleErrorDataSchema: z.ZodObject<{
|
@@ -308,12 +308,12 @@ interface GoogleGenerativeAIProvider extends ProviderV2 {
|
|
308
308
|
/**
|
309
309
|
@deprecated Use `textEmbeddingModel()` instead.
|
310
310
|
*/
|
311
|
-
embedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
311
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
312
312
|
/**
|
313
313
|
@deprecated Use `textEmbeddingModel()` instead.
|
314
314
|
*/
|
315
|
-
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
316
|
-
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
315
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
316
|
+
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
317
317
|
}
|
318
318
|
interface GoogleGenerativeAIProviderSettings {
|
319
319
|
/**
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
import { z } from 'zod';
|
2
|
-
import { ProviderV2, LanguageModelV2,
|
2
|
+
import { ProviderV2, LanguageModelV2, EmbeddingModelV2 } from '@ai-sdk/provider';
|
3
3
|
import { FetchFunction } from '@ai-sdk/provider-utils';
|
4
4
|
|
5
5
|
declare const googleErrorDataSchema: z.ZodObject<{
|
@@ -308,12 +308,12 @@ interface GoogleGenerativeAIProvider extends ProviderV2 {
|
|
308
308
|
/**
|
309
309
|
@deprecated Use `textEmbeddingModel()` instead.
|
310
310
|
*/
|
311
|
-
embedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
311
|
+
embedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
312
312
|
/**
|
313
313
|
@deprecated Use `textEmbeddingModel()` instead.
|
314
314
|
*/
|
315
|
-
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
316
|
-
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings):
|
315
|
+
textEmbedding(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
316
|
+
textEmbeddingModel(modelId: GoogleGenerativeAIEmbeddingModelId, settings?: GoogleGenerativeAIEmbeddingSettings): EmbeddingModelV2<string>;
|
317
317
|
}
|
318
318
|
interface GoogleGenerativeAIProviderSettings {
|
319
319
|
/**
|
package/dist/index.js
CHANGED
@@ -27,7 +27,7 @@ module.exports = __toCommonJS(src_exports);
|
|
27
27
|
|
28
28
|
// src/google-provider.ts
|
29
29
|
var import_provider4 = require("@ai-sdk/provider");
|
30
|
-
var
|
30
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
31
31
|
|
32
32
|
// src/google-generative-ai-embedding-model.ts
|
33
33
|
var import_provider = require("@ai-sdk/provider");
|
@@ -52,7 +52,7 @@ var googleFailedResponseHandler = (0, import_provider_utils.createJsonErrorRespo
|
|
52
52
|
// src/google-generative-ai-embedding-model.ts
|
53
53
|
var GoogleGenerativeAIEmbeddingModel = class {
|
54
54
|
constructor(modelId, settings, config) {
|
55
|
-
this.specificationVersion = "
|
55
|
+
this.specificationVersion = "v2";
|
56
56
|
this.modelId = modelId;
|
57
57
|
this.settings = settings;
|
58
58
|
this.config = config;
|
@@ -83,7 +83,11 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
83
83
|
await (0, import_provider_utils2.resolve)(this.config.headers),
|
84
84
|
headers
|
85
85
|
);
|
86
|
-
const {
|
86
|
+
const {
|
87
|
+
responseHeaders,
|
88
|
+
value: response,
|
89
|
+
rawValue
|
90
|
+
} = await (0, import_provider_utils2.postJsonToApi)({
|
87
91
|
url: `${this.config.baseURL}/models/${this.modelId}:batchEmbedContents`,
|
88
92
|
headers: mergedHeaders,
|
89
93
|
body: {
|
@@ -103,7 +107,7 @@ var GoogleGenerativeAIEmbeddingModel = class {
|
|
103
107
|
return {
|
104
108
|
embeddings: response.embeddings.map((item) => item.values),
|
105
109
|
usage: void 0,
|
106
|
-
|
110
|
+
response: { headers: responseHeaders, body: rawValue }
|
107
111
|
};
|
108
112
|
}
|
109
113
|
};
|
@@ -112,12 +116,12 @@ var googleGenerativeAITextEmbeddingResponseSchema = import_zod2.z.object({
|
|
112
116
|
});
|
113
117
|
|
114
118
|
// src/google-generative-ai-language-model.ts
|
115
|
-
var
|
119
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
116
120
|
var import_zod3 = require("zod");
|
117
121
|
|
118
122
|
// src/convert-json-schema-to-openapi-schema.ts
|
119
123
|
function convertJSONSchemaToOpenAPISchema(jsonSchema) {
|
120
|
-
if (isEmptyObjectSchema(jsonSchema)) {
|
124
|
+
if (jsonSchema == null || isEmptyObjectSchema(jsonSchema)) {
|
121
125
|
return void 0;
|
122
126
|
}
|
123
127
|
if (typeof jsonSchema === "boolean") {
|
@@ -214,6 +218,7 @@ function isEmptyObjectSchema(jsonSchema) {
|
|
214
218
|
|
215
219
|
// src/convert-to-google-generative-ai-messages.ts
|
216
220
|
var import_provider2 = require("@ai-sdk/provider");
|
221
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
217
222
|
function convertToGoogleGenerativeAIMessages(prompt) {
|
218
223
|
const systemInstructionParts = [];
|
219
224
|
const contents = [];
|
@@ -246,7 +251,12 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
246
251
|
mimeType: mediaType,
|
247
252
|
fileUri: part.data.toString()
|
248
253
|
}
|
249
|
-
} : {
|
254
|
+
} : {
|
255
|
+
inlineData: {
|
256
|
+
mimeType: mediaType,
|
257
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
258
|
+
}
|
259
|
+
}
|
250
260
|
);
|
251
261
|
break;
|
252
262
|
}
|
@@ -278,7 +288,7 @@ function convertToGoogleGenerativeAIMessages(prompt) {
|
|
278
288
|
return {
|
279
289
|
inlineData: {
|
280
290
|
mimeType: part.mediaType,
|
281
|
-
data: part.data
|
291
|
+
data: (0, import_provider_utils3.convertToBase64)(part.data)
|
282
292
|
}
|
283
293
|
};
|
284
294
|
}
|
@@ -455,7 +465,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
455
465
|
}
|
456
466
|
async getArgs({
|
457
467
|
prompt,
|
458
|
-
|
468
|
+
maxOutputTokens,
|
459
469
|
temperature,
|
460
470
|
topP,
|
461
471
|
topK,
|
@@ -470,7 +480,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
470
480
|
}) {
|
471
481
|
var _a;
|
472
482
|
const warnings = [];
|
473
|
-
const googleOptions = (0,
|
483
|
+
const googleOptions = (0, import_provider_utils4.parseProviderOptions)({
|
474
484
|
provider: "google",
|
475
485
|
providerOptions,
|
476
486
|
schema: googleGenerativeAIProviderOptionsSchema
|
@@ -491,7 +501,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
491
501
|
args: {
|
492
502
|
generationConfig: {
|
493
503
|
// standardized settings:
|
494
|
-
maxOutputTokens
|
504
|
+
maxOutputTokens,
|
495
505
|
temperature,
|
496
506
|
topK,
|
497
507
|
topP,
|
@@ -527,26 +537,25 @@ var GoogleGenerativeAILanguageModel = class {
|
|
527
537
|
var _a, _b, _c, _d, _e;
|
528
538
|
const { args, warnings } = await this.getArgs(options);
|
529
539
|
const body = JSON.stringify(args);
|
530
|
-
const mergedHeaders = (0,
|
531
|
-
await (0,
|
540
|
+
const mergedHeaders = (0, import_provider_utils4.combineHeaders)(
|
541
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
532
542
|
options.headers
|
533
543
|
);
|
534
544
|
const {
|
535
545
|
responseHeaders,
|
536
546
|
value: response,
|
537
547
|
rawValue: rawResponse
|
538
|
-
} = await (0,
|
548
|
+
} = await (0, import_provider_utils4.postJsonToApi)({
|
539
549
|
url: `${this.config.baseURL}/${getModelPath(
|
540
550
|
this.modelId
|
541
551
|
)}:generateContent`,
|
542
552
|
headers: mergedHeaders,
|
543
553
|
body: args,
|
544
554
|
failedResponseHandler: googleFailedResponseHandler,
|
545
|
-
successfulResponseHandler: (0,
|
555
|
+
successfulResponseHandler: (0, import_provider_utils4.createJsonResponseHandler)(responseSchema),
|
546
556
|
abortSignal: options.abortSignal,
|
547
557
|
fetch: this.config.fetch
|
548
558
|
});
|
549
|
-
const { contents: rawPrompt, ...rawSettings } = args;
|
550
559
|
const candidate = response.candidates[0];
|
551
560
|
const parts = candidate.content == null || typeof candidate.content !== "object" || !("parts" in candidate.content) ? [] : candidate.content.parts;
|
552
561
|
const toolCalls = getToolCallsFromParts({
|
@@ -557,6 +566,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
557
566
|
return {
|
558
567
|
text: getTextFromParts(parts),
|
559
568
|
files: (_a = getInlineDataParts(parts)) == null ? void 0 : _a.map((part) => ({
|
569
|
+
type: "file",
|
560
570
|
data: part.inlineData.data,
|
561
571
|
mediaType: part.inlineData.mimeType
|
562
572
|
})),
|
@@ -566,8 +576,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
566
576
|
hasToolCalls: toolCalls != null && toolCalls.length > 0
|
567
577
|
}),
|
568
578
|
usage: {
|
569
|
-
|
570
|
-
|
579
|
+
inputTokens: (_b = usageMetadata == null ? void 0 : usageMetadata.promptTokenCount) != null ? _b : void 0,
|
580
|
+
outputTokens: (_c = usageMetadata == null ? void 0 : usageMetadata.candidatesTokenCount) != null ? _c : void 0
|
571
581
|
},
|
572
582
|
warnings,
|
573
583
|
providerMetadata: {
|
@@ -591,26 +601,25 @@ var GoogleGenerativeAILanguageModel = class {
|
|
591
601
|
async doStream(options) {
|
592
602
|
const { args, warnings } = await this.getArgs(options);
|
593
603
|
const body = JSON.stringify(args);
|
594
|
-
const headers = (0,
|
595
|
-
await (0,
|
604
|
+
const headers = (0, import_provider_utils4.combineHeaders)(
|
605
|
+
await (0, import_provider_utils4.resolve)(this.config.headers),
|
596
606
|
options.headers
|
597
607
|
);
|
598
|
-
const { responseHeaders, value: response } = await (0,
|
608
|
+
const { responseHeaders, value: response } = await (0, import_provider_utils4.postJsonToApi)({
|
599
609
|
url: `${this.config.baseURL}/${getModelPath(
|
600
610
|
this.modelId
|
601
611
|
)}:streamGenerateContent?alt=sse`,
|
602
612
|
headers,
|
603
613
|
body: args,
|
604
614
|
failedResponseHandler: googleFailedResponseHandler,
|
605
|
-
successfulResponseHandler: (0,
|
615
|
+
successfulResponseHandler: (0, import_provider_utils4.createEventSourceResponseHandler)(chunkSchema),
|
606
616
|
abortSignal: options.abortSignal,
|
607
617
|
fetch: this.config.fetch
|
608
618
|
});
|
609
|
-
const { contents: rawPrompt, ...rawSettings } = args;
|
610
619
|
let finishReason = "unknown";
|
611
|
-
|
612
|
-
|
613
|
-
|
620
|
+
const usage = {
|
621
|
+
inputTokens: void 0,
|
622
|
+
outputTokens: void 0
|
614
623
|
};
|
615
624
|
let providerMetadata = void 0;
|
616
625
|
const generateId2 = this.config.generateId;
|
@@ -627,10 +636,8 @@ var GoogleGenerativeAILanguageModel = class {
|
|
627
636
|
const value = chunk.value;
|
628
637
|
const usageMetadata = value.usageMetadata;
|
629
638
|
if (usageMetadata != null) {
|
630
|
-
usage =
|
631
|
-
|
632
|
-
completionTokens: (_b = usageMetadata.candidatesTokenCount) != null ? _b : NaN
|
633
|
-
};
|
639
|
+
usage.inputTokens = (_a = usageMetadata.promptTokenCount) != null ? _a : void 0;
|
640
|
+
usage.outputTokens = (_b = usageMetadata.candidatesTokenCount) != null ? _b : void 0;
|
634
641
|
}
|
635
642
|
const candidate = (_c = value.candidates) == null ? void 0 : _c[0];
|
636
643
|
if (candidate == null) {
|
@@ -640,10 +647,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
640
647
|
if (content != null) {
|
641
648
|
const deltaText = getTextFromParts(content.parts);
|
642
649
|
if (deltaText != null) {
|
643
|
-
controller.enqueue(
|
644
|
-
type: "text-delta",
|
645
|
-
textDelta: deltaText
|
646
|
-
});
|
650
|
+
controller.enqueue(deltaText);
|
647
651
|
}
|
648
652
|
const inlineDataParts = getInlineDataParts(content.parts);
|
649
653
|
if (inlineDataParts != null) {
|
@@ -689,7 +693,7 @@ var GoogleGenerativeAILanguageModel = class {
|
|
689
693
|
generateId: generateId2
|
690
694
|
})) != null ? _d : [];
|
691
695
|
for (const source of sources) {
|
692
|
-
controller.enqueue(
|
696
|
+
controller.enqueue(source);
|
693
697
|
}
|
694
698
|
providerMetadata = {
|
695
699
|
google: {
|
@@ -723,6 +727,7 @@ function getToolCallsFromParts({
|
|
723
727
|
(part) => "functionCall" in part
|
724
728
|
);
|
725
729
|
return functionCallParts == null || functionCallParts.length === 0 ? void 0 : functionCallParts.map((part) => ({
|
730
|
+
type: "tool-call",
|
726
731
|
toolCallType: "function",
|
727
732
|
toolCallId: generateId2(),
|
728
733
|
toolName: part.functionCall.name,
|
@@ -731,7 +736,10 @@ function getToolCallsFromParts({
|
|
731
736
|
}
|
732
737
|
function getTextFromParts(parts) {
|
733
738
|
const textParts = parts == null ? void 0 : parts.filter((part) => "text" in part);
|
734
|
-
return textParts == null || textParts.length === 0 ? void 0 :
|
739
|
+
return textParts == null || textParts.length === 0 ? void 0 : {
|
740
|
+
type: "text",
|
741
|
+
text: textParts.map((part) => part.text).join("")
|
742
|
+
};
|
735
743
|
}
|
736
744
|
function getInlineDataParts(parts) {
|
737
745
|
return parts == null ? void 0 : parts.filter(
|
@@ -746,6 +754,7 @@ function extractSources({
|
|
746
754
|
return (_a = groundingMetadata == null ? void 0 : groundingMetadata.groundingChunks) == null ? void 0 : _a.filter(
|
747
755
|
(chunk) => chunk.web != null
|
748
756
|
).map((chunk) => ({
|
757
|
+
type: "source",
|
749
758
|
sourceType: "url",
|
750
759
|
id: generateId2(),
|
751
760
|
url: chunk.web.uri,
|
@@ -854,9 +863,9 @@ function isSupportedFileUrl(url) {
|
|
854
863
|
// src/google-provider.ts
|
855
864
|
function createGoogleGenerativeAI(options = {}) {
|
856
865
|
var _a;
|
857
|
-
const baseURL = (_a = (0,
|
866
|
+
const baseURL = (_a = (0, import_provider_utils5.withoutTrailingSlash)(options.baseURL)) != null ? _a : "https://generativelanguage.googleapis.com/v1beta";
|
858
867
|
const getHeaders = () => ({
|
859
|
-
"x-goog-api-key": (0,
|
868
|
+
"x-goog-api-key": (0, import_provider_utils5.loadApiKey)({
|
860
869
|
apiKey: options.apiKey,
|
861
870
|
environmentVariableName: "GOOGLE_GENERATIVE_AI_API_KEY",
|
862
871
|
description: "Google Generative AI"
|
@@ -869,7 +878,7 @@ function createGoogleGenerativeAI(options = {}) {
|
|
869
878
|
provider: "google.generative-ai",
|
870
879
|
baseURL,
|
871
880
|
headers: getHeaders,
|
872
|
-
generateId: (_a2 = options.generateId) != null ? _a2 :
|
881
|
+
generateId: (_a2 = options.generateId) != null ? _a2 : import_provider_utils5.generateId,
|
873
882
|
isSupportedUrl: isSupportedFileUrl,
|
874
883
|
fetch: options.fetch
|
875
884
|
});
|