-
Notifications
You must be signed in to change notification settings - Fork 498
Fix: Consider event type in data payload when processing model response streams #387
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
Fix: Consider event type in data payload when processing model response streams #387
Conversation
bbacc68 to
629b8b6
Compare
|
@nezhyborets what do you think? |
702a361 to
0840940
Compare
Sources/OpenAI/Private/Streaming/ModelResponseEventsStreamInterpreter.swift
Show resolved
Hide resolved
|
Hi @JaredConover , I'm looking into the issue. Thanks for the provided solution, but I want to look into parser first. It's strange that it doesn't parse the type if the data is there. |
|
BTW I don't know why but it doesn't happen for me, can't reproduce |
|
Do you use some other server/provider than OpenAI, that doesn't set SSE event type? |
|
Yes exactly, the type is not set at the level of the SSE event - just in the data object. This should still work no? I didn't see anywhere in the OpenAI api spec where specifying the type in two places (ie payload data object and top level of the SSE event) is necessary |
What
Enable the parsing of
typeproperty inside of the event.data object for mapping model responses.Why
Parsing of streamed events from /responses endpoint only looks at the type property of the SSE event itself, and not at the type property inside the events data payload. As a result it is not possible to parse properly formed events.
When attempting to stream events from the /responses api using OpenAI.responses.createResponseStreaming() it seems there is a bug that prevents the events from being processed.
Despite receiving properly formatted events, ie:
ModelResponseEventsStreamInterpreter.processEvent for:
Produces error:
The "message" event type is not present in the event received and seems to come from line 207 of the
ServerSentEventsStreamParserthat sets a default event type (for the sse event) to "message" by default if there is no value in the event field of the sse event.I believe the bug is that
ModelResponseEventsStreamInterpreter.processEventrefers to this default value for the SSE event field when attempting to parse aModelResponseStreamEventTypewhen it should be using thetypeproperty inside the SSE event's data object as per the openAI spec. We can see is "response.output_text.delta" in the example above.Affected Areas
This updates how streamed model responses are parsed and processed.