betalgo / openai

OpenAI .NET sdk - Azure OpenAI, ChatGPT, Whisper, and DALL-E
https://betalgo.github.io/openai/
MIT License
2.85k stars 513 forks source link

Ignore lines that start with : ping #472

Closed gavi closed 5 months ago

gavi commented 6 months ago

When testing the client with streaming chat, I noticed the JSON parser crashes for lines that start at with ": ping", I believe its because the api sends chunks with event: ping which needs to be ignored

kayhantolga commented 5 months ago

I I didn't notice such a thing before. Do you think this is new behavior? Do you have any sample code or prompt?

gavi commented 5 months ago

I was using the client with text-generation-webui openai plugin and noticed the crash. Then I checked the official python implementation from openai and saw the ping messages in their src/test_streaming.py Edit:

Just to add the spec: https://html.spec.whatwg.org/multipage/server-sent-events.html#event-stream-interpretation

kayhantolga commented 5 months ago

I have made some updates. I thought that maybe someone might find this data useful, so I kept it as optional.

Could you test my implementation to see if it helps? I couldn't test it because I don't have any prompts to trigger pings. I would greatly appreciate it if you could share one with me.