Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,9 @@ def _get_metadata_from_response(self, response: ChatCompletionResponse | Complet
}
# Check if usage exists and has a value, then add it to the metadata
if hasattr(response, "usage") and response.usage is not None:
metadata["usage"] = (
CompletionUsage(
prompt_tokens=response.usage.prompt_tokens,
completion_tokens=response.usage.completion_tokens,
),
metadata["usage"] = CompletionUsage(
prompt_tokens=response.usage.prompt_tokens,
completion_tokens=response.usage.completion_tokens,
)
Comment on lines 253 to 257
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This bug fix changes the shape of metadata["usage"] (tuple -> CompletionUsage), but there is no regression test asserting the type/attributes of metadata["usage"] on returned ChatMessageContent / streaming chunks. Add a unit test that verifies response.metadata["usage"] is a CompletionUsage instance and that prompt_tokens/completion_tokens are accessible to prevent the tuple-wrapping bug from reappearing.

Copilot uses AI. Check for mistakes.

return metadata
Expand Down
Loading