Git Product home page Git Product logo

Comments (4)

ozzyonfire avatar ozzyonfire commented on June 6, 2024

I think the issue here is that you are trying to parse the accumulated text, but since the text is coming in as chunks, it is not a valid JSON object yet. So the error you are getting is expected.

You can view how the package parses a streamed response by checkout out this file: https://github.com/vercel/ai/blob/main/packages/core/shared/process-chat-stream.ts

from ai.

jameschetwood avatar jameschetwood commented on June 6, 2024

I think the issue here is that you are trying to parse the accumulated text, but since the text is coming in as chunks, it is not a valid JSON object yet. So the error you are getting is expected.

You can view how the package parses a streamed response by checkout out this file: https://github.com/vercel/ai/blob/main/packages/core/shared/process-chat-stream.ts

I don't think that's it. If I use a tool like Postman to hit the API (so it's not my code parsing it) I can see the JSON is invalid.

from ai.

baptisteArno avatar baptisteArno commented on June 6, 2024

I have the exact same issue but it's only happening on production when deploying on Vercel. 😨

I'm super confused and I don't know how I can debug that...

ai package is up to date.

Here is the invalid JSON it returns:


{"tool_calls":[ {"id": "call_Io6uRXyMRhniyd71oBvAXuG4", "type": "function", "function": {"name": "getWeather", "arguments": "{\n"city": "London"\n}"}}]}

from ai.

AaronFriel avatar AaronFriel commented on June 6, 2024

Give the fn-stream library a try. It includes a streaming, incremental JSON parser that returns nodes of the response.

from ai.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.