This commit is contained in:
mikemikimike 2026-10-07 16:53:16 -04:00 • committed by GitHub
commit 4dbf81b690
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 30 additions and 2 deletions

View file

@ -1367,8 +1367,9 @@ class CustomStreamWrapper:
LlmProviders.AZURE_AI.value,
]:
if isinstance(chunk, BaseModel) and hasattr(chunk, "model"):
# for azure, we need to pass the model from the original chunk
self.model = getattr(chunk, "model", self.model)
chunk_model: Final = getattr(chunk, "model", None)
if chunk_model is not None:
self.model = chunk_model
response_obj = self.handle_openai_chat_completion_chunk(chunk)
if response_obj is None:
return _ProviderChunkEarlyReturn(None)

View file

@ -3321,6 +3321,33 @@ def test_chunk_creator_drops_empty_finish_chunk(
assert initialized_custom_stream_wrapper.received_finish_reason == "stop"
@pytest.mark.parametrize(
("chunk_model", "expected_model"),
[(None, "azure/request-model"), ("azure/chunk-model", "azure/chunk-model")],
)
def test_azure_chunk_model_preserves_or_updates_request_model(chunk_model: str | None, expected_model: str):
wrapper: Final = CustomStreamWrapper(
completion_stream=None,
model="azure/request-model",
logging_obj=MagicMock(),
custom_llm_provider="azure",
)
chunk: Final = ModelResponseStream(
model=chunk_model,
choices=[
StreamingChoices(
finish_reason=None,
index=0,
delta=Delta(content="hello", role="assistant"),
)
],
)
wrapper.chunk_creator(chunk=chunk)
assert wrapper.model == expected_model
def test_chunk_creator_stops_iteration_on_trailing_chunk(
initialized_custom_stream_wrapper: CustomStreamWrapper,
):