mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
test(budget): cover tool-call and provider-field message shapes in projected cost
This commit is contained in:
parent
11addf2de0
commit
e66267ae38
1 changed files with 42 additions and 0 deletions
|
|
@ -49,3 +49,45 @@ def test_projected_cost_none_and_missing_content(manager: BudgetManager):
|
|||
>= 0
|
||||
)
|
||||
assert manager.projected_cost(model="gpt-4o-mini", messages=[{"role": "user"}], user="u") >= 0
|
||||
|
||||
|
||||
def test_projected_cost_tool_calls_with_null_content(manager: BudgetManager):
|
||||
# The expensive shape: assistant turn carrying tool calls and no text.
|
||||
cost = manager.projected_cost(
|
||||
model="gpt-4o-mini",
|
||||
messages=[
|
||||
{"role": "user", "content": "what is the weather?"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": None,
|
||||
"tool_calls": [
|
||||
{
|
||||
"id": "call_1",
|
||||
"type": "function",
|
||||
"function": {"name": "get_weather", "arguments": '{"city": "Paris"}'},
|
||||
}
|
||||
],
|
||||
},
|
||||
],
|
||||
user="u",
|
||||
)
|
||||
assert cost > 0
|
||||
|
||||
|
||||
def test_projected_cost_provider_specific_fields(manager: BudgetManager):
|
||||
# Provider extras (name, cache_control, reasoning_content) must not break counting.
|
||||
cost = manager.projected_cost(
|
||||
model="gpt-4o-mini",
|
||||
messages=[
|
||||
{"role": "user", "content": "hi", "name": "soroush"},
|
||||
{
|
||||
"role": "assistant",
|
||||
"content": [
|
||||
{"type": "text", "text": "hello", "cache_control": {"type": "ephemeral"}},
|
||||
],
|
||||
"reasoning_content": "thinking...",
|
||||
},
|
||||
],
|
||||
user="u",
|
||||
)
|
||||
assert cost > 0
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue