Skip to content
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

Revert #1065 #1080

Merged
merged 2 commits into from
Mar 4, 2024
Merged

Revert #1065 #1080

merged 2 commits into from
Mar 4, 2024

Conversation

MaxLeiter
Copy link
Member

@MaxLeiter MaxLeiter commented Mar 4, 2024

Error calling experimental_onToolCall: [Error: Invalid function call arguments in message. [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "string",
    "path": [],
    "message": "Expected object, received string"
  }
]]

cc @IdoPesok

@MaxLeiter MaxLeiter merged commit aab5324 into main Mar 4, 2024
6 checks passed
@MaxLeiter MaxLeiter deleted the max/revert-change branch March 4, 2024 00:43
@IdoPesok
Copy link
Contributor

IdoPesok commented Mar 4, 2024

@MaxLeiter

Looking into it, is this line missing a JSON.parse() ? Because the ToolCallPayload type shows arguments as a record but seems like they never get parsed from string. My bad for not exploring this further.

arguments: tool.function.arguments,

The function call seems to be parsed:

const argumentsPayload = JSON.parse(

@IdoPesok
Copy link
Contributor

IdoPesok commented Mar 4, 2024

As per the OpenAI API docs, there should be a JSON.parse(tool.function.arguments) I actually ran into this in a different project I was working on so I did a if typeof arguments === "string" ? JSON.parse(...) : ... which should be safe. The problem is this could be a breaking change for many codebases if they have already implemented the parse themselves because then it would be a JSON.parse(JSON.parse(...)).

https://platform.openai.com/docs/guides/function-calling

@mharris717
Copy link

Same issue as Ido. Real bummer, as it means the main docs page example for flagship feature Generative AI straight up doesn’t work. The example only doesn’t crash cause it doesn’t care that flight number is passed as undefined.

@IdoPesok
Copy link
Contributor

IdoPesok commented Mar 5, 2024

In #1084 I updated it so tool calls have their arguments go through JSON.parse then through the Zod parse. This should fix everything. Tool arguments will be able to be parsed by zod, and then the args send to the render function will be properly transformed according to the zod schema (enabling .default, .transform, etc)

@nicholasraphael
Copy link

this is happening again followed the example from here exactly https://sdk.vercel.ai/docs/concepts/ai-rsc @MaxLeiter @shuding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants