File tree Expand file tree Collapse file tree 2 files changed +9
-3
lines changed
pydantic_ai_slim/pydantic_ai/models Expand file tree Collapse file tree 2 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -586,9 +586,12 @@ async def _process_streamed_response(
586
586
'Streamed response ended without content or tool calls'
587
587
)
588
588
589
+ # ChatCompletionChunk.model is required to be set, but Azure OpenAI omits it so we fall back to the model name set by the user.
590
+ model_name = first_chunk .model or self ._model_name
591
+
589
592
return OpenAIStreamedResponse (
590
593
model_request_parameters = model_request_parameters ,
591
- _model_name = first_chunk . model ,
594
+ _model_name = model_name ,
592
595
_model_profile = self .profile ,
593
596
_response = peekable_response ,
594
597
_timestamp = number_to_datetime (first_chunk .created ),
Original file line number Diff line number Diff line change @@ -397,8 +397,11 @@ async def test_stream_text(allow_model_requests: None):
397
397
398
398
399
399
async def test_stream_text_finish_reason (allow_model_requests : None ):
400
+ first_chunk = text_chunk ('hello ' )
401
+ # Test that we fall back to the model name set by the user if the model name is not set in the first chunk, like on Azure OpenAI.
402
+ first_chunk .model = ''
400
403
stream = [
401
- text_chunk ( 'hello ' ) ,
404
+ first_chunk ,
402
405
text_chunk ('world' ),
403
406
text_chunk ('.' , finish_reason = 'stop' ),
404
407
]
@@ -418,7 +421,7 @@ async def test_stream_text_finish_reason(allow_model_requests: None):
418
421
ModelResponse (
419
422
parts = [TextPart (content = 'hello world.' )],
420
423
usage = RequestUsage (input_tokens = 6 , output_tokens = 3 ),
421
- model_name = 'gpt-4o-123 ' ,
424
+ model_name = 'gpt-4o' ,
422
425
timestamp = IsDatetime (),
423
426
provider_name = 'openai' ,
424
427
provider_details = {'finish_reason' : 'stop' },
You can’t perform that action at this time.
0 commit comments