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

Error when using streaming chat completion #44

Open
Ali-Kalout opened this issue Apr 9, 2024 · 4 comments
Open

Error when using streaming chat completion #44

Ali-Kalout opened this issue Apr 9, 2024 · 4 comments

Comments

@Ali-Kalout
Copy link

Hi all, we sometimes get the following error, when using the chat completion feature while having the stream field as true.

Screenshot 2024-04-09 at 3 11 04 PM

@adampash
Copy link

Just to expand on this a little (I work with @Ali-Kalout :) )—it's not easy to tell what the malformed JSON looks like, but it seems possible that this PR could improve the situation.

I also noticed yesterday that OpenAI has added a JSON mode to chat completions. Adding response_format to the completion API call seems like it could help a lot here.

@adampash
Copy link

adampash commented Apr 10, 2024

If I'm not mistaken, if I just update my chat_completion params, whatever params aren't Instructor params will be passed through to the API request. Is that right? So the following should work?

    Instructor.chat_completion(
      model: @model,
      response_model: response_model,
      messages: messages,
      stream: stream,
      max_retries: @max_retries,
      # the important part below
      response_format: %{ type: "json_object"}
    )

@petrus-jvrensburg
Copy link
Contributor

I have this PR that helps with debugging: #46.
If you IO.inspect the request before it goes to the LLM, you should be able to see if the param is included in the way you'd expect.

@joechiarella
Copy link

I'm also running into this same issue. I believe its happening because of the use of Jason.decode inside of Req's into option. Req is passing blocks of raw text to the function, and those blocks of text don't always split up into parseable chunks of json. I'm unsure at this point if OpenAI is splitting these responses into multiple packets like this or if something in between is buffering the responses.

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

No branches or pull requests

4 participants