ai icon indicating copy to clipboard operation
ai copied to clipboard

Error: failed to pipe response (SyntaxError: Unexpected end of JSON input) for experimental_onToolCall

Open nabilfatih opened this issue 2 years ago • 1 comments

Description

So i want to force AI to call get_document function. But i always get error:

Error: failed to pipe response
    at pipeToNodeResponse (/Users/nabilfatih/Code/fibonacciku-v2/node_modules/next/dist/server/pipe-readable.js:111:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async DevServer.runEdgeFunction (/Users/nabilfatih/Code/fibonacciku-v2/node_modules/next/dist/server/next-server.js:1221:13)
    at async NextNodeServer.handleCatchallRenderRequest (/Users/nabilfatih/Code/fibonacciku-v2/node_modules/next/dist/server/next-server.js:242:37)
    at async DevServer.handleRequestImpl (/Users/nabilfatih/Code/fibonacciku-v2/node_modules/next/dist/server/base-server.js:805:17) {
  [cause]: SyntaxError: Unexpected end of JSON input
      at JSON.parse (<anonymous>)
      at Object.flush (webpack-internal:///(rsc)/./node_modules/ai/dist/index.mjs:781:42)

But, when i do not force the AI, tool_choice: "auto" .. it is working fine. I think there is something wrong with the experimental_onToolCallfunction.

Code example

const response = await openai.chat.completions.create({
      model,
      stream: true,
      messages: finalMessage,
      temperature: 0.5,
      tools,
      tool_choice: { type: "function", function: { name: "get_document" } },
      user: userId,
    });

    const data = new experimental_StreamData();
    const stream = OpenAIStream(response, {
      experimental_onToolCall: async (
        call: ToolCallPayload,
        appendToolCallMessage
      ) => {
    console.log(tool) // This is not being called, so I assume the error is from experimental_onToolCall

Additional context

Please enlighten me if this error is supposed not to happen, cause because of this error, I need to go back to old function call (not to use tool call). Note: function call is Deprecated.

nabilfatih avatar Jan 05 '24 21:01 nabilfatih

do you fix now? i have same problem

GetFalse avatar Mar 22 '24 14:03 GetFalse

Please check out our new tool calling with AI SDK Core and useChat: https://sdk.vercel.ai/docs/ai-sdk-ui/chatbot-with-tool-calling#example-server-side-tool-execution-with-roundtrips

lgrammel avatar May 24 '24 15:05 lgrammel