Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

test: update tests

Krrish Dholakia8273630e084d
diff --git a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
index ff454968d9c..ae44198af11 100644
--- a/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
+++ b/tests/test_litellm/llms/anthropic/chat/test_anthropic_chat_transformation.py
@@ -51,57 +51,56 @@ def test_calculate_usage():
"output_tokens": 550,
}
usage = config.calculate_usage(usage_object=usage_object, reasoning_content=None)
- assert usage.prompt_tokens == 3
+ assert usage.prompt_tokens == 12307
assert usage.completion_tokens == 550
- assert usage.total_tokens == 3 + 550
+ assert usage.total_tokens == 12307 + 550
assert usage.prompt_tokens_details.cached_tokens == 0
+ assert usage.prompt_tokens_details.cache_creation_tokens == 12304
assert usage._cache_creation_input_tokens == 12304
assert usage._cache_read_input_tokens == 0
[email protected]("usage_object,expected_usage", [
- [
- {
- "cache_creation_input_tokens": None,
- "cache_read_input_tokens": None,
- "input_tokens": None,
- "output_tokens": 43,
- "server_tool_use": None
- },
- {
- "prompt_tokens": 0,
- "completion_tokens": 43,
- "total_tokens": 43,
- "_cache_creation_input_tokens": 0,
- "_cache_read_input_tokens": 0
- }
- ],
+
+ "usage_object,expected_usage",
[
- {
- "cache_creation_input_tokens": 100,
- "cache_read_input_tokens": 200,
- "input_tokens": 1,
- "output_tokens": None,
- "server_tool_use": None
- },
- {
- "prompt_tokens": 1 + 200,
- "completion_tokens": 0,
- "total_tokens": 1 + 200,
- "_cache_creation_input_tokens": 100,
- "_cache_read_input_tokens": 200,
- }
+ [
+ {
+ "cache_creation_input_tokens": None,
+ "cache_read_input_tokens": None,
+ "input_tokens": None,
+ "output_tokens": 43,
+ "server_tool_use": None,
+ },
+ {
+ "prompt_tokens": 0,
+ "completion_tokens": 43,
+ "total_tokens": 43,
+ "_cache_creation_input_tokens": 0,
+ "_cache_read_input_tokens": 0,
+ },
+ ],
+ [
+ {
+ "cache_creation_input_tokens": 100,
+ "cache_read_input_tokens": 200,
+ "input_tokens": 1,
+ "output_tokens": None,
+ "server_tool_use": None,
+ },
+ {
+ "prompt_tokens": 1 + 200 + 100,
+ "completion_tokens": 0,
+ "total_tokens": 1 + 200 + 100,
+ "_cache_creation_input_tokens": 100,
+ "_cache_read_input_tokens": 200,
+ },
+ ],
+ [
+ {"server_tool_use": {"web_search_requests": 10}},
+ {"server_tool_use": ServerToolUse(web_search_requests=10)},
+ ],
],
- [
- {
- "server_tool_use": {
- "web_search_requests": 10
- }
- },
- {
- "server_tool_use": ServerToolUse(web_search_requests=10)
- }
- ]
-])
+)
def test_calculate_usage_nulls(usage_object, expected_usage):
"""
Correctly deal with null values in usage object
@@ -115,16 +114,11 @@ def test_calculate_usage_nulls(usage_object, expected_usage):
assert hasattr(usage, k)
assert getattr(usage, k) == v
[email protected]("usage_object", [
- {
- "server_tool_use": {
- "web_search_requests": None
- }
- },
- {
- "server_tool_use": None
- }
-])
+
+ "usage_object",
+ [{"server_tool_use": {"web_search_requests": None}}, {"server_tool_use": None}],
+)
def test_calculate_usage_server_tool_null(usage_object):
"""
Correctly deal with null values in usage object
@@ -132,10 +126,11 @@ def test_calculate_usage_server_tool_null(usage_object):
Fixes https://github.com/BerriAI/litellm/issues/11920
"""
config = AnthropicConfig()
-
+
usage = config.calculate_usage(usage_object=usage_object, reasoning_content=None)
assert not hasattr(usage, "server_tool_use")
+
def test_extract_response_content_with_citations():
config = AnthropicConfig()