[Bugfix] Add Responses cache_write_tokens for API compat and CC parity (#57222)
Signed-off-by: Yifan Zong <yzong@redhat.com> Co-authored-by: Flora Feng <4florafeng@gmail.com>
This commit is contained in:
@@ -18,6 +18,9 @@ from openai.types.responses import (
|
||||
ResponseTextConfig,
|
||||
ResponseTextDeltaEvent,
|
||||
)
|
||||
from openai.types.responses import (
|
||||
ResponseUsage as OpenAIResponseUsage,
|
||||
)
|
||||
from openai.types.responses.response_format_text_json_schema_config import (
|
||||
ResponseFormatTextJSONSchemaConfig,
|
||||
)
|
||||
@@ -975,6 +978,7 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
|
||||
outputs=[completion],
|
||||
finished=True,
|
||||
num_cached_tokens=0,
|
||||
num_cache_creation_tokens=3,
|
||||
)
|
||||
context.append_output(req_output)
|
||||
|
||||
@@ -995,6 +999,9 @@ async def test_reasoning_tokens_counted_for_text_reasoning_model(monkeypatch):
|
||||
)
|
||||
|
||||
assert response.usage.output_tokens_details.reasoning_tokens == 1
|
||||
assert response.usage.input_tokens_details.cache_write_tokens == 3
|
||||
|
||||
OpenAIResponseUsage.model_validate(response.usage.model_dump(mode="json"))
|
||||
|
||||
|
||||
class TestExtractAllowedToolsFromMcpRequests:
|
||||
|
||||
@@ -682,6 +682,7 @@ def create_simple_context_output(
|
||||
prompt="Test prompt",
|
||||
prompt_token_ids=None,
|
||||
num_cached_tokens=0,
|
||||
num_cache_creation_tokens=None,
|
||||
logprobs=None,
|
||||
finished=True,
|
||||
):
|
||||
@@ -707,6 +708,7 @@ def create_simple_context_output(
|
||||
],
|
||||
finished=finished,
|
||||
num_cached_tokens=num_cached_tokens,
|
||||
num_cache_creation_tokens=num_cache_creation_tokens,
|
||||
)
|
||||
|
||||
|
||||
@@ -827,6 +829,7 @@ def test_simple_context_token_counting():
|
||||
token_ids=[10, 11],
|
||||
prompt_token_ids=[1, 2, 3, 4, 5],
|
||||
num_cached_tokens=2,
|
||||
num_cache_creation_tokens=3,
|
||||
)
|
||||
)
|
||||
context.append_output(
|
||||
@@ -835,12 +838,14 @@ def test_simple_context_token_counting():
|
||||
token_ids=[12],
|
||||
prompt_token_ids=[1, 2, 3, 4, 5],
|
||||
num_cached_tokens=2,
|
||||
num_cache_creation_tokens=3,
|
||||
)
|
||||
)
|
||||
|
||||
assert context.num_prompt_tokens == 5
|
||||
assert context.num_output_tokens == 3 # 2 + 1
|
||||
assert context.num_cached_tokens == 2
|
||||
assert context.num_cache_creation_tokens == 3
|
||||
|
||||
|
||||
def test_simple_context_final_output():
|
||||
|
||||
Reference in New Issue
Block a user