Repository navigation
feat(model_prices): add deepseek-v3 to model price maps (#43660) #43753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
VimalN2005
wants to merge
1
commit into
BerriAI:main
Choose a base branch
from
VimalN2005:feat/add-deepseek-v3-model-prices
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| """ | ||
| Tests for deepseek-v3 model prices and context window configuration. | ||
|
|
||
| Closes https://github.com/BerriAI/litellm/issues/43660 | ||
| """ | ||
|
|
||
| import json | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| import litellm | ||
| from litellm import completion_cost | ||
| from litellm.types.utils import Choices, Message, ModelResponse, Usage | ||
| from litellm.utils import get_model_info | ||
|
|
||
| REPO_ROOT = Path(__file__).parents[2] | ||
| MAIN_PATH = REPO_ROOT / "model_prices_and_context_window.json" | ||
| BACKUP_PATH = REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json" | ||
|
|
||
| EXPECTED_CONFIG = { | ||
| "litellm_provider": "deepseek", | ||
| "mode": "chat", | ||
| "input_cost_per_token": 2.7e-07, | ||
| "output_cost_per_token": 1.1e-06, | ||
| "cache_read_input_token_cost": 7e-08, | ||
|
VimalN2005 marked this conversation as resolved.
|
||
| "max_input_tokens": 65536, | ||
| "max_output_tokens": 8192, | ||
| "supports_function_calling": True, | ||
| "supports_tool_choice": True, | ||
| "supports_assistant_prefill": True, | ||
| "supports_prompt_caching": True, | ||
| } | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def local_model_cost_map(monkeypatch): | ||
| original_model_cost = litellm.model_cost | ||
| monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") | ||
| litellm.model_cost = litellm.get_model_cost_map(url="") | ||
| litellm.get_model_info.cache_clear() | ||
| try: | ||
| yield | ||
| finally: | ||
| litellm.model_cost = original_model_cost | ||
| litellm.get_model_info.cache_clear() | ||
|
|
||
|
|
||
| def test_deepseek_v3_in_cost_map(): | ||
| with open(MAIN_PATH, encoding="utf-8") as f: | ||
| model_cost = json.load(f) | ||
|
|
||
| for key in ("deepseek-v3", "deepseek/deepseek-v3"): | ||
| info = model_cost.get(key) | ||
| assert info is not None, f"{key} missing from model_prices_and_context_window.json" | ||
| for field, expected_val in EXPECTED_CONFIG.items(): | ||
| assert info.get(field) == expected_val, f"Mismatch for {field} in {key}" | ||
|
|
||
|
|
||
| def test_deepseek_v3_in_backup_cost_map(): | ||
| with open(BACKUP_PATH, encoding="utf-8") as f: | ||
| model_cost = json.load(f) | ||
|
|
||
| for key in ("deepseek-v3", "deepseek/deepseek-v3"): | ||
| info = model_cost.get(key) | ||
| assert info is not None, f"{key} missing from backup JSON" | ||
| for field, expected_val in EXPECTED_CONFIG.items(): | ||
| assert info.get(field) == expected_val, f"Mismatch for {field} in {key}" | ||
|
|
||
|
|
||
| def test_deepseek_v3_get_model_info(): | ||
| info = get_model_info(model="deepseek-v3") | ||
| assert info is not None | ||
| assert info["litellm_provider"] == "deepseek" | ||
| assert info["input_cost_per_token"] == pytest.approx(2.7e-07) | ||
| assert info["output_cost_per_token"] == pytest.approx(1.1e-06) | ||
| assert info["cache_read_input_token_cost"] == pytest.approx(7e-08) | ||
| assert info["max_input_tokens"] == 65536 | ||
| assert info["max_output_tokens"] == 8192 | ||
|
|
||
|
|
||
| def test_deepseek_v3_completion_cost(): | ||
| response = ModelResponse( | ||
| model="deepseek-v3", | ||
| choices=[Choices(index=0, message=Message(role="assistant", content="test"))], | ||
| usage=Usage( | ||
| prompt_tokens=1_000_000, | ||
| completion_tokens=1_000_000, | ||
| total_tokens=2_000_000, | ||
|
VimalN2005 marked this conversation as resolved.
|
||
| ), | ||
| ) | ||
|
|
||
| cost_bare = completion_cost( | ||
| completion_response=response, | ||
| model="deepseek-v3", | ||
| custom_llm_provider="deepseek", | ||
| ) | ||
| assert cost_bare == pytest.approx(1.37, abs=1e-9) | ||
|
|
||
| response_prefixed = ModelResponse( | ||
| model="deepseek/deepseek-v3", | ||
| choices=[Choices(index=0, message=Message(role="assistant", content="test"))], | ||
| usage=Usage( | ||
| prompt_tokens=1_000_000, | ||
| completion_tokens=1_000_000, | ||
| total_tokens=2_000_000, | ||
| ), | ||
| ) | ||
| cost_prefixed = completion_cost( | ||
| completion_response=response_prefixed, | ||
| model="deepseek/deepseek-v3", | ||
| ) | ||
| assert cost_prefixed == pytest.approx(1.37, abs=1e-9) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.