@ai-sdk/google 4.0.73 → 4.0.75

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.
@@ -2304,3 +2304,54 @@ const result = await generateSpeech({
2304
2304
  | `gemini-2.5-flash-preview-tts` | <Check /> | <Check /> |
2305
2305
  | `gemini-2.5-pro-preview-tts` | <Check /> | <Check /> |
2306
2306
  | `gemini-3.1-flash-tts-preview` | <Check /> | <Check /> |
2307
+
2308
+ ## Evaluation Models
2309
+
2310
+ Create an experimental evaluation model with `google.evaluationModel(modelId)`.
2311
+ It uses Gemini structured output for Choice, Score, and Boolean questions. Choose a model
2312
+ that supports structured output, such as `gemini-3.5-flash-lite`.
2313
+
2314
+ ```ts
2315
+ import { google } from '@ai-sdk/google';
2316
+ import { experimental_evaluate } from 'ai';
2317
+
2318
+ const { answers } = await experimental_evaluate({
2319
+ model: google.evaluationModel('gemini-3.5-flash-lite'),
2320
+ state: 'I was charged twice.',
2321
+ questions: {
2322
+ requestsRefund: {
2323
+ type: 'boolean',
2324
+ instructions: 'Is the customer requesting money back?',
2325
+ },
2326
+ department: {
2327
+ type: 'choice',
2328
+ instructions: 'Which team should handle this?',
2329
+ criteria: { billing: 'Charges and refunds', support: 'Other requests' },
2330
+ },
2331
+ },
2332
+ providerOptions: {
2333
+ google: { thinkingConfig: { thinkingLevel: 'minimal' } },
2334
+ },
2335
+ });
2336
+ ```
2337
+
2338
+ The factory respects `createGoogle` settings and forwards `providerOptions.google`,
2339
+ including thinking configuration. Thinking controls depend on the selected model;
2340
+ use options supported by that model. The existing Gemini implementation sends the
2341
+ answer schema as `generationConfig.responseJsonSchema`.
2342
+
2343
+ Choice labels are returned exactly, and Scores are finite fractional positions
2344
+ within the ordered rubric. The adapter validates complete answers after parsing
2345
+ and rejects safety-blocked, truncated, or invalid output. It preserves usage
2346
+ (including reasoning tokens), warnings, response data, and provider metadata.
2347
+
2348
+ Choice and Score answers do not include probability distributions. Boolean
2349
+ answers contain prompted estimates of P(true), validated to be finite and in
2350
+ `[0, 1]`. These estimates are not guaranteed to be calibrated. Apply thresholds
2351
+ in application code, for example `answers.requestsRefund.probability >= 0.5`. See [Evaluation](/docs/ai-sdk-core/evaluation).
2352
+
2353
+ Evaluation models can also be accessed through `customProvider` aliases or
2354
+ `createProviderRegistry().evaluationModel('provider:model')`. Direct string IDs
2355
+ use Gateway by default, or an explicitly configured default provider with an
2356
+ `evaluationModel` method. See
2357
+ [model aliases and registries](/docs/ai-sdk-core/evaluation#model-aliases-and-registries).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ai-sdk/google",
3
- "version": "4.0.73",
3
+ "version": "4.0.75",
4
4
  "type": "module",
5
5
  "license": "Apache-2.0",
6
6
  "sideEffects": false,
@@ -35,8 +35,8 @@
35
35
  }
36
36
  },
37
37
  "dependencies": {
38
- "@ai-sdk/provider": "4.0.16",
39
- "@ai-sdk/provider-utils": "5.0.42"
38
+ "@ai-sdk/provider": "4.0.17",
39
+ "@ai-sdk/provider-utils": "5.0.44"
40
40
  },
41
41
  "devDependencies": {
42
42
  "@ai-sdk/test-server": "2.0.1",
@@ -30,13 +30,15 @@ export function convertGoogleUsage(
30
30
 
31
31
  const promptTokens = usage.promptTokenCount ?? 0;
32
32
  const candidatesTokens = usage.candidatesTokenCount ?? 0;
33
+ const toolUsePromptTokens = usage.toolUsePromptTokenCount ?? 0;
33
34
  const cachedContentTokens = usage.cachedContentTokenCount ?? 0;
34
35
  const thoughtsTokens = usage.thoughtsTokenCount ?? 0;
36
+ const inputTokens = promptTokens + toolUsePromptTokens;
35
37
 
36
38
  return {
37
39
  inputTokens: {
38
- total: promptTokens,
39
- noCache: promptTokens - cachedContentTokens,
40
+ total: inputTokens,
41
+ noCache: inputTokens - cachedContentTokens,
40
42
  cacheRead: cachedContentTokens,
41
43
  cacheWrite: undefined,
42
44
  },
@@ -53,7 +53,7 @@ export class GoogleImageModel implements ImageModelV4 {
53
53
  if (this.settings.maxImagesPerCall != null) {
54
54
  return this.settings.maxImagesPerCall;
55
55
  }
56
- return 10;
56
+ return 1;
57
57
  }
58
58
 
59
59
  get provider(): string {
@@ -77,7 +77,6 @@ export class GoogleImageModel implements ImageModelV4 {
77
77
 
78
78
  const {
79
79
  prompt,
80
- n,
81
80
  size,
82
81
  aspectRatio,
83
82
  seed,
@@ -96,13 +95,6 @@ export class GoogleImageModel implements ImageModelV4 {
96
95
  );
97
96
  }
98
97
 
99
- // Gemini does not support generating multiple images per call via n parameter
100
- if (n != null && n > 1) {
101
- throw new Error(
102
- 'Gemini image models do not support generating a set number of images per call. Use n=1 or omit the n parameter.',
103
- );
104
- }
105
-
106
98
  if (size != null) {
107
99
  warnings.push({
108
100
  type: 'unsupported',
@@ -7,7 +7,7 @@ export type GoogleImageModelId =
7
7
 
8
8
  export interface GoogleImageSettings {
9
9
  /**
10
- * Override the maximum number of images per call (default 10)
10
+ * Override the maximum number of images per call (default 1)
11
11
  */
12
12
  maxImagesPerCall?: number;
13
13
  }
@@ -463,10 +463,15 @@ export class GoogleLanguageModel implements LanguageModelV4 {
463
463
  ) as SharedV4ProviderMetadata;
464
464
  const candidate = response.candidates?.[0];
465
465
  const promptBlockReason = response.promptFeedback?.blockReason;
466
+ const confirmedPromptBlockReason = isConfirmedPromptBlockReason(
467
+ promptBlockReason,
468
+ )
469
+ ? promptBlockReason
470
+ : undefined;
466
471
  const isPromptBlocked =
467
- candidate?.finishReason == null && promptBlockReason != null;
472
+ candidate?.finishReason == null && confirmedPromptBlockReason != null;
468
473
  const rawFinishReason =
469
- candidate?.finishReason ?? promptBlockReason ?? undefined;
474
+ candidate?.finishReason ?? confirmedPromptBlockReason;
470
475
  const content: Array<LanguageModelV4Content> = [];
471
476
 
472
477
  // map ordered parts to content:
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  EmbeddingModelV4,
3
3
  Experimental_BatchV4 as BatchV4,
4
+ Experimental_EvaluationModelV4 as EvaluationModelV4,
4
5
  Experimental_VideoModelV4,
5
6
  FilesV4,
6
7
  ImageModelV4,
@@ -20,6 +21,7 @@ import {
20
21
  type FetchFunction,
21
22
  type WebSocketConstructor,
22
23
  } from '@ai-sdk/provider-utils';
24
+ import { Experimental_EvaluationLanguageModel as EvaluationLanguageModel } from '@ai-sdk/provider-utils/experimental-evaluation';
23
25
  import { VERSION } from './version';
24
26
  import { GoogleEmbeddingModel } from './google-embedding-model';
25
27
  import type { GoogleEmbeddingModelId } from './google-embedding-model-options';
@@ -61,6 +63,9 @@ export interface GoogleProvider extends ProviderV4 {
61
63
 
62
64
  chat(modelId: GoogleModelId): LanguageModelV4;
63
65
 
66
+ /** Creates an experimental Choice/Score/Boolean evaluation model using Gemini. */
67
+ evaluationModel(modelId: GoogleModelId): EvaluationModelV4;
68
+
64
69
  experimental_batch(): BatchV4<{
65
70
  text: GoogleModelId;
66
71
  image: GoogleImageModelId;
@@ -430,6 +435,11 @@ export function createGoogle(
430
435
  provider.languageModel = createChatModel;
431
436
  provider.chat = createChatModel;
432
437
  provider.generativeAI = createChatModel;
438
+ provider.evaluationModel = (modelId: GoogleModelId) =>
439
+ new EvaluationLanguageModel({
440
+ model: createChatModel(modelId),
441
+ provider: `${providerName.replace(/\.generative-ai$/, '')}.evaluation`,
442
+ });
433
443
  provider.experimental_batch = createBatch;
434
444
  provider.embedding = createEmbeddingModel;
435
445
  provider.embeddingModel = createEmbeddingModel;