-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bedrock Sonnet v2 and Vertex Gemini 2.0 flash: Cannot read properties of undefined (reading 'toolCalls') #4301
Comments
Can you provide more details on the messages & tool that you pass in? I have tried to reproduce the issue on latest dev; the following works for me though: import { vertex } from '@ai-sdk/google-vertex';
import { CoreMessage, streamText, tool } from 'ai';
import 'dotenv/config';
import * as readline from 'node:readline/promises';
import { z } from 'zod';
const terminal = readline.createInterface({
input: process.stdin,
output: process.stdout,
});
const messages: CoreMessage[] = [];
async function main() {
while (true) {
const userInput = await terminal.question('You: ');
messages.push({ role: 'user', content: userInput });
const result = streamText({
model: vertex('gemini-2.0-flash-exp'),
tools: {
weather: tool({
description: 'Get the weather in a location',
parameters: z.object({
location: z
.string()
.describe('The location to get the weather for'),
}),
execute: async ({ location }) => ({
location,
temperature: 72 + Math.floor(Math.random() * 21) - 10,
}),
}),
},
maxSteps: 5,
messages,
});
process.stdout.write('\nAssistant: ');
for await (const delta of result.textStream) {
process.stdout.write(delta);
}
process.stdout.write('\n\n');
messages.push(...(await result.response).messages);
}
}
main().catch(console.error); |
Also, can you send me the lines around line 4639 from the file mentioned in the stack trace for flush @Nishchit14 -- if I look on npm the lines don't match up: |
I isolated a potential cause. When an error happens that causes the stream to be aborted / no steps to be recorded, this will currently trigger the error that you are seeing. Can you also see if there are any errors in the fullStream response property? |
@lgrammel I agree, The issue happens when the error occurred from ai provider's api request. If it is handy then can you please share the |
@Nishchit14 I think I have a potential fix, but the fix indicates that you also face an another error. Here are the docs: https://sdk.vercel.ai/docs/reference/ai-sdk-core/stream-text#returns (see fullStream in there) |
Im sending super simple messages: [ { role: 'user', content: 'test' } ] When i use: Everything works great, but when i change the string into On frontend side const {error} = useChat()
// error returns "An error occurred" on backend side im getting |
I'm releasing |
Description
When i try to use
anthropic.claude-3-5-sonnet-20241022-v2:0
on amazon-bedrock, andgemini-2.0-flash-exp
on Vertex im getting this error:[500] Cannot read properties of undefined (reading 'toolCalls')
Code example
AI provider
"ai": "4.0.27", "@ai-sdk/amazon-bedrock": "1.0.6", "@ai-sdk/anthropic": "1.0.6", "@ai-sdk/google": "1.0.12", "@ai-sdk/google-vertex": "2.0.13", "@ai-sdk/openai": "1.0.13", "@ai-sdk/vue": "1.0.7",
Additional context
No response
The text was updated successfully, but these errors were encountered: