Add message id to OpenAI chat response update (#561)

This commit is contained in:
Tao Chen
2025-08-29 12:52:30 -07:00
committed by GitHub
Unverified
parent cc7fb43fde
commit 15f0147164
4 changed files with 12 additions and 0 deletions
@@ -580,6 +580,8 @@ async def test_get_streaming(
messages=chat_history,
):
assert msg is not None
assert msg.message_id is not None
assert msg.response_id is not None
mock_create.assert_awaited_once_with(
model=azure_openai_unit_test_env["AZURE_OPENAI_CHAT_DEPLOYMENT_NAME"],
stream=True,
@@ -683,6 +685,8 @@ async def test_azure_openai_chat_client_streaming() -> None:
async for chunk in response:
assert chunk is not None
assert isinstance(chunk, ChatResponseUpdate)
assert chunk.message_id is not None
assert chunk.response_id is not None
for content in chunk.contents:
if isinstance(content, TextContent) and content.text:
full_message += content.text
@@ -208,6 +208,8 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
contents=[UsageContent(details=self._usage_details_from_openai(chunk.usage), raw_representation=chunk)],
ai_model_id=chunk.model,
additional_properties=chunk_metadata,
response_id=chunk.id,
message_id=chunk.id,
)
contents: list[AIContents] = []
finish_reason: ChatFinishReason | None = None
@@ -227,6 +229,8 @@ class OpenAIChatClientBase(OpenAIHandler, ChatClientBase):
additional_properties=chunk_metadata,
finish_reason=finish_reason,
raw_representation=chunk,
response_id=chunk.id,
message_id=chunk.id,
)
def _usage_details_from_openai(self, usage: CompletionUsage) -> UsageDetails:
@@ -250,6 +250,8 @@ async def test_openai_chat_client_streaming() -> None:
async for chunk in response:
assert chunk is not None
assert isinstance(chunk, ChatResponseUpdate)
assert chunk.message_id is not None
assert chunk.response_id is not None
for content in chunk.contents:
if isinstance(content, TextContent) and content.text:
full_message += content.text
@@ -162,6 +162,8 @@ async def test_scmc_chat_options(
messages=chat_history,
):
assert isinstance(msg, ChatResponseUpdate)
assert msg.message_id is not None
assert msg.response_id is not None
mock_create.assert_awaited_once_with(
model=openai_unit_test_env["OPENAI_CHAT_MODEL_ID"],
stream=True,