-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Closed
Labels
Azurefor issues relating to the Azure OpenAI servicefor issues relating to the Azure OpenAI servicebugSomething isn't workingSomething isn't working
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
I have a fastapi endpoint which streams a response from Azure OpenAI:
@router.post("/message")
def message(sessionID: str = Form(...), messages: str = Form(...), selectedModel: str = Form(...), file: UploadFile = Form(None)):
message_list = json.loads(messages)
return StreamingResponse(stream_chat(message_list, sessionID, selectedModel))
def stream_chat(messages: list[ChatCompletionMessageParam], session_id: str, selected_model: str) -> Generator[StreamingResponseChunk, None, None]:
print('entered stream_chat')
completion_stream = azure_openai_client.chat.completions.create(
model=selected_model,
messages=messages,
stream=True,
timeout=45,
**DEFAULT_MODEL_CONFIG
)
print('completion_stream created!')
#. . .
On occasion, azure_openai_client.chat.completions.create
will infinitely stall, and cause every subsequent request to infinitely stall as well. Once the error occurs, every request reaches 'entered stream_chat'
but not 'completion_stream created!'
, until I reset the FastAPI instance. No exceptions are raised, even after hitting the 45 second timeout. I haven't been able to recreate the bug consistently either. What on earth is going on?
For reference, here are the debug logs when the error starts:
DEBUG:openai._base_client:Sending HTTP Request: POST https://[my-deployment]/openai/deployments/gpt-4o/chat/completions?api-version=2024-08-01-preview
DEBUG:httpcore.http11:receive_response_body.failed exception=GeneratorExit()
DEBUG:httpcore.http11:response_closed.started
DEBUG:httpcore.http11:response_closed.complete
To Reproduce
I am unsure how to reproduce consistently, it seems to happen at random, fairly rarely.
Code snippets
OS
macOS
Python version
Python v3.11.4
Library version
openai v1.75.0
Metadata
Metadata
Assignees
Labels
Azurefor issues relating to the Azure OpenAI servicefor issues relating to the Azure OpenAI servicebugSomething isn't workingSomething isn't working