Fix openai streaming decoding error when using provider webSearch tool#5938
Conversation
…call without action
🦋 Changeset detectedLatest commit: 213c49f The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
A follow-up issue #5939 |
|
@tensor2077 - thank you for the detailed pull request. It doesn't feel quite right to implement this fix in the The good thing is that in Effect v4, our OpenAPI generator will be much more robust, so we can actually generate the streaming output types, which should alleviate the need for these patches. |
Type
Description
When sending a stream request,
OpenAiClient.streamRequestdecodes each SSEevent.dataintoResponseStreamEvent(OpenAiClient.ts:1803).However, in real streams,
ResponseOutputItemAddedEventcan emit aweb_search_callitem before it’s fully populated: theactionfield is not present yet (it only shows up later inresponse.output_item.done). This can cause an early decode failure whileOpenAiLanguageModel.makeStreamResponseis processing the tool-call stream parts.effect/packages/ai/openai/src/OpenAiClient.ts
Lines 402 to 421 in 65e9e35
Proposed Fix
I currently work around this by relaxing the schema to accept
web_search_callwithoutactioninResponseOutputItemAddedEvent, so it can accept an in-progress web_search_call item without action. (status="in_progress").what do you think is the most appropriate way to model/handle this situations? @IMax153
Reproduce
You can reproduce this by enabling the
web_searchtool and asking the model to perform a search in streaming mode.