Open CharlieDigital opened 4 months ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @jpalvarezl @trrwilson.
I have seen the same issue with responses where the "role" property is null. My team kinda needs a fix for this null dereference issue soon. Can I make a PR to let the parser ignore values that are null? @trrwilson
@CharlieDigital @JasonYeMSFT -- thanks for the report and corroboration.
I don't have any specific objection to loosening the checks for streaming payloads to permit nulls; the tricky thing is that this is not compliant with the OpenAI API specification; as you can see in the .yaml file, properties like tool_calls
and role
on ChatCompletionStreamResponseDelta
are optional, but non-nullable. Strictly speaking, "tool_calls": null
or "role": null
is not valid payload.
I'd still advocate for us being more permissive because I don't see enough relative value in being "schema cop" for nullability, but the team will need to discuss and ensure we're being consistent.
Library name and version
Azure.AI.OpenAI 1.0.0-beta.17
Describe the bug
When processing streaming JSON responses from an OpenAI compatible API endpoint, the
Azure.AI.OpenAI.StreamingChatCompletionsUpdate.StreamingDeltaData.DeserializeStreamingDeltaData
throws anInvalidOperationException
when encountering anull
-valued property:This error can occur if the provider includes
null
-valued property tokens in the response stream. For example, Together.ai's implementation.Expected behavior
When processing streaming JSON responses from an OpenAI compatible API endpoint, the
Azure.AI.OpenAI.StreamingChatCompletionsUpdate.StreamingDeltaData.DeserializeStreamingDeltaData
correctly handlesnull
values.Actual behavior
When the response has a
null
value, this causes anInvalidOperationException
to be thrown.This occurs because the code for deserialization does not account for
null
values. For example: https://github.com/Azure/azure-sdk-for-net/blob/bed3a44beecff00a5aefc88709f1155d1ba24cd4/sdk/openai/Azure.AI.OpenAI/src/Custom/ChatCompletions/StreamingChatCompletionsUpdate.Serialization.cs#L239-L245Will cause an exception because the
deltaProperty.Value
could be null if the JSON has a null value for the attribute:Reproduction Steps
This will produce the same error.
Proposed fix:
Alternatively, modify the code here to allow null values: https://github.com/Azure/azure-sdk-for-net/blob/bed3a44beecff00a5aefc88709f1155d1ba24cd4/sdk/core/Azure.Core/src/DynamicData/MutableJsonElement.cs#L1397-L1403
Environment