sashabaranov / go-openai

OpenAI ChatGPT, GPT-3, GPT-4, DALL·E, Whisper API wrapper for Go
Apache License 2.0
9.25k stars 1.42k forks source link

Inability to Parse API Response Data Due to Missing Space After "data:" #781

Open fruitbars opened 4 months ago

fruitbars commented 4 months ago

Describe the bug The bug occurs when the response data from the API does not include a space after the colon in the "data:" prefix. This causes the data to not be properly parsed or read by the client.

To Reproduce

  1. Make a request to the OpenAI API endpoint that returns streaming data.
  2. Ensure that the response includes a "data:" prefix without a space, like so: data:{"code":0,"message":"Success","sid":"xxx","id":"xxx","created":1719810561,"choices":[{"delta":{"role":"assistant","content":"He"},"index":0}]}.
  3. Attempt to read or parse the response data.

Expected behavior The client should be able to correctly parse and read the response data regardless of whether there is a space after the "data:" prefix.

Screenshots/Logs Unfortunately, no screenshots are available, but the logs would show that the data is not being processed as expected due to the missing space.

Environment

Additional context This issue might be related to how the client library handles the parsing of streaming data responses. It may require adjustments in the parsing logic to accommodate responses with and without a space after the "data:" prefix.