mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-12 23:01:41 +00:00
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:
parent
c1a4d3a704
commit
e2d147102d
2 changed files with 9 additions and 0 deletions
|
|
@ -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,
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue