Skip to content

Commit ebbdb11

Browse files
aayush-kapoorvercel-ai-sdk[bot]
authored andcommitted
Backport conflicts for PR #14352 to release-v6.0
1 parent 5d213ea commit ebbdb11

File tree

6 files changed

+203
-15
lines changed

6 files changed

+203
-15
lines changed

.changeset/six-pumas-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@ai-sdk/google": patch
3+
---
4+
5+
fix(google-vertex): don't send streamFunctionCallArguments for unary API calls and change default to false

content/providers/01-ai-sdk-providers/16-google-vertex.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ The following optional provider options are available for Google Vertex models:
350350
Optional. When set to true, function call arguments will be streamed
351351
incrementally in streaming responses. This enables `tool-input-delta` events
352352
to arrive as the model generates function call arguments, reducing perceived
353-
latency for tool calls. Defaults to `true` for Vertex AI providers. Only supported on the Vertex AI API (not the Gemini API).
353+
latency for tool calls. Defaults to `false`. Only supported on the Vertex AI API (not the Gemini API) with Gemini 3+ models.
354354

355355
Consult [Google's Documentation](https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc) for details.
356356

@@ -469,8 +469,7 @@ For Gemini 3 Pro and later models on Vertex AI, you can stream function call
469469
arguments as they are generated by setting `streamFunctionCallArguments` to
470470
`true`. This reduces perceived latency when functions need to be called, as
471471
`tool-input-delta` events arrive incrementally instead of waiting for the
472-
complete arguments. This option is `true` by default and you can opt out by
473-
setting it to false.
472+
complete arguments. This option defaults to `false`.
474473

475474
```ts
476475
import { vertex } from '@ai-sdk/google-vertex';
@@ -491,7 +490,7 @@ const result = streamText({
491490
},
492491
providerOptions: {
493492
vertex: {
494-
streamFunctionCallArguments: false,
493+
streamFunctionCallArguments: true,
495494
} satisfies GoogleLanguageModelOptions,
496495
},
497496
});

examples/ai-functions/src/stream-text/google/vertex-stream-function-call-args.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@ run(async () => {
1616
}),
1717
},
1818
},
19+
providerOptions: {
20+
vertex: {
21+
streamFunctionCallArguments: true,
22+
},
23+
},
1924
includeRawChunks: true,
2025
});
2126

packages/google/src/google-generative-ai-language-model.test.ts

Lines changed: 138 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5359,7 +5359,7 @@ describe('doStream', () => {
53595359
).toMatchInlineSnapshot(`undefined`);
53605360
});
53615361

5362-
it('should default streamFunctionCallArguments to true for Vertex provider even without provider option', async () => {
5362+
it('should default streamFunctionCallArguments to false for Vertex provider without provider option', async () => {
53635363
server.urls[TEST_URL_GEMINI_PRO].response = {
53645364
type: 'stream-chunks',
53655365
chunks: [
@@ -5405,14 +5405,10 @@ describe('doStream', () => {
54055405
],
54065406
});
54075407

5408-
expect((await server.calls[0].requestBodyJson).toolConfig)
5409-
.toMatchInlineSnapshot(`
5410-
{
5411-
"functionCallingConfig": {
5412-
"streamFunctionCallArguments": true,
5413-
},
5414-
}
5415-
`);
5408+
expect(
5409+
(await server.calls[0].requestBodyJson).toolConfig?.functionCallingConfig
5410+
?.streamFunctionCallArguments,
5411+
).toMatchInlineSnapshot(`undefined`);
54165412
});
54175413

54185414
it('should allow Vertex provider to opt out of streamFunctionCallArguments by setting it to false', async () => {
@@ -5472,6 +5468,139 @@ describe('doStream', () => {
54725468
).toBeUndefined();
54735469
});
54745470

5471+
it('should not send streamFunctionCallArguments for Vertex provider doGenerate (unary API)', async () => {
5472+
server.urls[TEST_URL_GEMINI_PRO].response = {
5473+
type: 'json-value',
5474+
body: {
5475+
candidates: [
5476+
{
5477+
content: { parts: [{ text: 'Hello' }], role: 'model' },
5478+
finishReason: 'STOP',
5479+
safetyRatings: SAFETY_RATINGS,
5480+
},
5481+
],
5482+
usageMetadata: {
5483+
promptTokenCount: 1,
5484+
candidatesTokenCount: 1,
5485+
totalTokenCount: 2,
5486+
},
5487+
},
5488+
};
5489+
5490+
const vertexModel = new GoogleGenerativeAILanguageModel('gemini-pro', {
5491+
provider: 'google.vertex.chat',
5492+
baseURL: 'https://generativelanguage.googleapis.com/v1beta',
5493+
headers: { 'x-goog-api-key': 'test-api-key' },
5494+
generateId: () => 'test-id',
5495+
});
5496+
5497+
await vertexModel.doGenerate({
5498+
prompt: TEST_PROMPT,
5499+
tools: [
5500+
{
5501+
type: 'function',
5502+
name: 'test-tool',
5503+
inputSchema: {
5504+
type: 'object',
5505+
properties: { value: { type: 'string' } },
5506+
required: ['value'],
5507+
additionalProperties: false,
5508+
$schema: 'http://json-schema.org/draft-07/schema#',
5509+
},
5510+
},
5511+
],
5512+
});
5513+
5514+
expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(`
5515+
{
5516+
"contents": [
5517+
{
5518+
"parts": [
5519+
{
5520+
"text": "Hello",
5521+
},
5522+
],
5523+
"role": "user",
5524+
},
5525+
],
5526+
"generationConfig": {},
5527+
"tools": [
5528+
{
5529+
"functionDeclarations": [
5530+
{
5531+
"description": "",
5532+
"name": "test-tool",
5533+
"parameters": {
5534+
"properties": {
5535+
"value": {
5536+
"type": "string",
5537+
},
5538+
},
5539+
"required": [
5540+
"value",
5541+
],
5542+
"type": "object",
5543+
},
5544+
},
5545+
],
5546+
},
5547+
],
5548+
}
5549+
`);
5550+
});
5551+
5552+
it('should not send streamFunctionCallArguments for Vertex provider doGenerate even when explicitly set', async () => {
5553+
server.urls[TEST_URL_GEMINI_PRO].response = {
5554+
type: 'json-value',
5555+
body: {
5556+
candidates: [
5557+
{
5558+
content: { parts: [{ text: 'Hello' }], role: 'model' },
5559+
finishReason: 'STOP',
5560+
safetyRatings: SAFETY_RATINGS,
5561+
},
5562+
],
5563+
usageMetadata: {
5564+
promptTokenCount: 1,
5565+
candidatesTokenCount: 1,
5566+
totalTokenCount: 2,
5567+
},
5568+
},
5569+
};
5570+
5571+
const vertexModel = new GoogleGenerativeAILanguageModel('gemini-pro', {
5572+
provider: 'google.vertex.chat',
5573+
baseURL: 'https://generativelanguage.googleapis.com/v1beta',
5574+
headers: { 'x-goog-api-key': 'test-api-key' },
5575+
generateId: () => 'test-id',
5576+
});
5577+
5578+
await vertexModel.doGenerate({
5579+
prompt: TEST_PROMPT,
5580+
providerOptions: {
5581+
vertex: {
5582+
streamFunctionCallArguments: true,
5583+
},
5584+
},
5585+
});
5586+
5587+
expect(await server.calls[0].requestBodyJson).toMatchInlineSnapshot(`
5588+
{
5589+
"contents": [
5590+
{
5591+
"parts": [
5592+
{
5593+
"text": "Hello",
5594+
},
5595+
],
5596+
"role": "user",
5597+
},
5598+
],
5599+
"generationConfig": {},
5600+
}
5601+
`);
5602+
});
5603+
54755604
it('should only pass valid provider options', async () => {
54765605
prepareChunksFixtureResponse('google-text');
54775606

packages/google/src/google-generative-ai-language-model.ts

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
8585
return this.config.supportedUrls?.() ?? {};
8686
}
8787

88+
<<<<<<< HEAD
8889
private async getArgs({
8990
prompt,
9091
maxOutputTokens,
@@ -101,6 +102,28 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
101102
providerOptions,
102103
}: LanguageModelV3CallOptions) {
103104
const warnings: SharedV3Warning[] = [];
105+
=======
106+
private async getArgs(
107+
{
108+
prompt,
109+
maxOutputTokens,
110+
temperature,
111+
topP,
112+
topK,
113+
frequencyPenalty,
114+
presencePenalty,
115+
stopSequences,
116+
responseFormat,
117+
seed,
118+
tools,
119+
toolChoice,
120+
reasoning,
121+
providerOptions,
122+
}: LanguageModelV4CallOptions,
123+
{ isStreaming = false }: { isStreaming?: boolean } = {},
124+
) {
125+
const warnings: SharedV4Warning[] = [];
126+
>>>>>>> 5b7e7c2a9 (fix(google-vertex): don't send streamFunctionCallArguments for vertex doGenerate (#14352))
104127

105128
const providerOptionsName = this.config.provider.includes('vertex')
106129
? 'vertex'
@@ -170,9 +193,26 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
170193
modelId: this.modelId,
171194
});
172195

196+
<<<<<<< HEAD
173197
const streamFunctionCallArguments = isVertexProvider
174198
? (googleOptions?.streamFunctionCallArguments ?? true)
175199
: undefined;
200+
=======
201+
const resolvedThinking = resolveThinkingConfig({
202+
reasoning,
203+
modelId: this.modelId,
204+
warnings,
205+
});
206+
const thinkingConfig =
207+
googleOptions?.thinkingConfig || resolvedThinking
208+
? { ...resolvedThinking, ...googleOptions?.thinkingConfig }
209+
: undefined;
210+
211+
const streamFunctionCallArguments =
212+
isStreaming && isVertexProvider
213+
? (googleOptions?.streamFunctionCallArguments ?? false)
214+
: undefined;
215+
>>>>>>> 5b7e7c2a9 (fix(google-vertex): don't send streamFunctionCallArguments for vertex doGenerate (#14352))
176216

177217
const toolConfig =
178218
googleToolConfig ||
@@ -466,9 +506,18 @@ export class GoogleGenerativeAILanguageModel implements LanguageModelV3 {
466506
}
467507

468508
async doStream(
509+
<<<<<<< HEAD
469510
options: LanguageModelV3CallOptions,
470511
): Promise<LanguageModelV3StreamResult> {
471512
const { args, warnings, providerOptionsName } = await this.getArgs(options);
513+
=======
514+
options: LanguageModelV4CallOptions,
515+
): Promise<LanguageModelV4StreamResult> {
516+
const { args, warnings, providerOptionsName } = await this.getArgs(
517+
options,
518+
{ isStreaming: true },
519+
);
520+
>>>>>>> 5b7e7c2a9 (fix(google-vertex): don't send streamFunctionCallArguments for vertex doGenerate (#14352))
472521

473522
const headers = combineHeaders(
474523
await resolve(this.config.headers),

packages/google/src/google-generative-ai-options.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,10 @@ export const googleLanguageModelOptions = lazySchema(() =>
192192
/**
193193
* Optional. When set to true, function call arguments will be streamed
194194
* incrementally via partialArgs in streaming responses. Only supported
195-
* on the Vertex AI API (not the Gemini API).
195+
* on the Vertex AI API (not the Gemini API) and only for Gemini 3+
196+
* models.
196197
*
197-
* @default true
198+
* @default false
198199
*
199200
* https://docs.cloud.google.com/vertex-ai/generative-ai/docs/multimodal/function-calling#streaming-fc
200201
*/

0 commit comments

Comments
 (0)