Skip to content

openrouter returns an error directly when using Stream mode #227

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

Open
TBXark opened this issue Feb 13, 2025 · 2 comments
Open

openrouter returns an error directly when using Stream mode #227

TBXark opened this issue Feb 13, 2025 · 2 comments

Comments

@TBXark
Copy link

TBXark commented Feb 13, 2025

Below is a part of the original body returned by openrouter.

: OPENROUTER PROCESSING

: OPENROUTER PROCESSING

data: {"id":"gen-1739458867-kUKFjpDGCEBBvK6V46PX","provider":"OpenAI","model":"openai/gpt-4o-mini","object":"chat.completion.chunk","created":1739458867,"choices":[{"index":0,"delta":{"role":"assistant","content":""},"finish_reason":null,"native_finish_reason":null,"logprobs":null}],"system_fingerprint":"fp_72ed7ab54c"}

data: {"id":"gen-1739458867-kUKFjpDGCEBBvK6V46PX","provider":"OpenAI","model":"openai/gpt-4o-mini","object":"chat.completion.chunk","created":1739458867,"choices":[{"index":0,"delta":{"role":"assistant","content":"亚"},"finish_reason":null,"native_finish_reason":null,"logprobs":null}],"system_fingerprint":"fp_72ed7ab54c"}

@RobertCraigie
Copy link
Collaborator

Sorry what do you mean?

@openaphid
Copy link

openaphid commented Feb 16, 2025

openai-go doesn't correctly parse SSE comment line with 2 newlines:

switch string(name) {
case "":
// An empty line in the for ": something" is a comment and should be ignored.
continue

When the above code continues, the lines below fire an event with empty data, which eventually causes gson parsing to fail.

for s.scn.Scan() {
txt := s.scn.Bytes()
// Dispatch event on an empty line
if len(txt) == 0 {
s.evt = Event{
Type: event,
Data: data.Bytes(),
}
return true
}

I've tried a quick fix, and it works for me.

openaphid@96b701b

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

3 participants