You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When I use OpenAI's Structured Output with a Pydantic object, the litellm.completion endpoint works completely fine. But when I try to stream it with the below given code, the endpoint streams empty objects. I have used Azure OpenAI in my implementation.
Code to replicate:
defgenerate_structured_output_litellm(prompt):
try:
response=completion(
model="azure/"+AZURE_DEPLOYMENT["deployment"],
api_key=AZURE_DEPLOYMENT["api_key"],
api_version=AZURE_DEPLOYMENT["api_version"],
api_base=AZURE_DEPLOYMENT["endpoint"],
messages=[
{"role": "system", "content": "You are a helpful assistant who responds in json structured responses."},
{"role": "user", "content": prompt},
],
temperature=0.7,
response_format=AnyPydanticModel,
stream=True
)
foreventinresponse:
print(event)
exceptExceptionase:
print(f"Error generating structured output: {e}")
returnNone
In the above code if I remove the line stream=True then it works fine in delivering the structured response. I have added the console logs (where I am logging the event chunk) below in the section "Relevant log output". Just to point out the bug, the content field is remaining None.
The reason for this bug could be because of the way OpenAI is currently supporting streaming of Structured Output. Here is a reference code (original doc) which OpenAI provides for streaming:
# truncated imports and initial setupwithclient.beta.chat.completions.stream(
model="gpt-4o",
messages=[
{"role": "system", "content": "Extract entities from the input text"},
{
"role": "user",
"content": "The quick brown fox jumps over the lazy dog with piercing blue eyes",
},
],
response_format=EntitiesModel,
) asstream:
foreventinstream:
ifevent.type=="content.delta":
ifevent.parsedisnotNone:
# Print the parsed data as JSONprint("content.delta parsed:", event.parsed)
elifevent.type=="content.done":
print("content.done")
elifevent.type=="error":
print("Error in stream:", event.error)
final_completion=stream.get_final_completion()
print("Final completion:", final_completion)
The above implementation using OpenAI's SDK streams the following chunk objects in response.
I would request the LiteLLM folks to please resolve this issue soon. If I am missing something or this is solvable using some other existing approach, please guide.
What happened?
When I use OpenAI's Structured Output with a Pydantic object, the
litellm.completion
endpoint works completely fine. But when I try to stream it with the below given code, the endpoint streams empty objects. I have used Azure OpenAI in my implementation.Code to replicate:
In the above code if I remove the line
stream=True
then it works fine in delivering the structured response. I have added the console logs (where I am logging the event chunk) below in the section "Relevant log output". Just to point out the bug, the content field is remaining None.The reason for this bug could be because of the way OpenAI is currently supporting streaming of Structured Output. Here is a reference code (original doc) which OpenAI provides for streaming:
The above implementation using OpenAI's SDK streams the following chunk objects in response.
I would request the LiteLLM folks to please resolve this issue soon. If I am missing something or this is solvable using some other existing approach, please guide.
Relevant log output
Are you a ML Ops Team?
Yes
What LiteLLM version are you on ?
v1.55.9
Twitter / LinkedIn details
No response
The text was updated successfully, but these errors were encountered: