Fix/openrouter stream usage id 8913 (#11004)

* Add handling and verification for 'usage' field in OpenRouter chat transformations and streaming responses.

* Ensure consistent response ID by using valid ID from any chunk.

* Remove redundant comments from OpenRouter chat transformation tests and logic.

* Remove this from here as I'm opening a new pr

* Reverting space

* Remove redundant assertions from OpenRouter chat transformation test
This commit is contained in:
daarko10 2025-05-23 08:54:56 +03:00 committed by GitHub
parent c1a4d3a704
commit e2d147102d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 9 additions and 0 deletions

View file

@ -120,6 +120,7 @@ class OpenRouterChatCompletionStreamingHandler(BaseModelResponseIterator):
id=chunk["id"],
object="chat.completion.chunk",
created=chunk["created"],
usage=chunk.get("usage"),
model=chunk["model"],
choices=new_choices,
)

View file

@ -26,6 +26,11 @@ class TestOpenRouterChatCompletionStreamingHandler:
"id": "test_id",
"created": 1234567890,
"model": "test_model",
"usage": {
"prompt_tokens": 10,
"completion_tokens": 20,
"total_tokens": 30
},
"choices": [
{"delta": {"content": "test content", "reasoning": "test reasoning"}}
],
@ -39,6 +44,9 @@ class TestOpenRouterChatCompletionStreamingHandler:
assert result.object == "chat.completion.chunk"
assert result.created == 1234567890
assert result.model == "test_model"
assert result.usage.prompt_tokens == chunk["usage"]["prompt_tokens"]
assert result.usage.completion_tokens == chunk["usage"]["completion_tokens"]
assert result.usage.total_tokens == chunk["usage"]["total_tokens"]
assert len(result.choices) == 1
assert result.choices[0]["delta"]["reasoning_content"] == "test reasoning"