You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to use streamText with a plain tools object where the parameters on each tool valid JSON schema. This works fine when I use the openai sdk (with a tools array), but I get the following error before the request is even made:
TypeError: Cannot read properties of undefined (reading 'typeName')
Code example
import{openai}from'@ai-sdk/openai';import{streamText}from'ai';constresponse=awaitstreamText({model: openai('gpt-4o'),prompt: 'This is a prompt',tools: {my_tool: {description: 'A tool that does something',parameters: {param1: {type: 'string',description: 'A parameter that does something'}}}}});
Additional context
No response
The text was updated successfully, but these errors were encountered:
Hi - sorry you're running into issues! This error is because the SDK uses Zod for the parameters schema.
Try this:
import{openai}from'@ai-sdk/openai';import{streamText}from'ai';import{z}from"zod";constresponse=awaitstreamText({model: openai('gpt-4o'),prompt: 'This is a prompt',tools: {my_tool: {description: 'A tool that does something',parameters: z.object({param1: z.string().describe('A parameter that does something')}),}}}});
Is there anyway to do this without zod? Or would this project be open to supporting JSON Schemas?
I'm mainly interested in this because my tool schemas are JSON Schemas and stored as JSON strings, which I've been using with the openai sdk and the previous stream helpers with ai.
lgrammel
changed the title
TypeError: Cannot read properties of undefined (reading 'typeName')
feat: define tool parameters with JSON schema instead of Zod
May 17, 2024
Description
I'm trying to use
streamText
with a plaintools
object where theparameters
on each tool valid JSON schema. This works fine when I use the openai sdk (with atools
array), but I get the following error before the request is even made:TypeError: Cannot read properties of undefined (reading 'typeName')
Code example
Additional context
No response
The text was updated successfully, but these errors were encountered: