-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
fix(cost): price Vertex AI DeepSeek OCR by token usage #39414
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mateo-berri
wants to merge
2
commits into
main
Choose a base branch
from
litellm_vertex_deepseek_ocr_pricing
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
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Empty file.
67 changes: 67 additions & 0 deletions
67
tests/test_litellm/llms/vertex_ai/ocr/test_deepseek_transformation.py
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,67 @@ | ||
| from unittest.mock import MagicMock | ||
|
|
||
| import httpx | ||
| import pytest | ||
|
|
||
| from litellm.cost_calculator import completion_cost | ||
| from litellm.llms.vertex_ai.ocr.deepseek_transformation import VertexAIDeepSeekOCRConfig | ||
|
|
||
| PROMPT_TOKENS = 901 | ||
| COMPLETION_TOKENS = 212 | ||
| INPUT_COST_PER_TOKEN = 3e-07 | ||
| OUTPUT_COST_PER_TOKEN = 1.2e-06 | ||
|
|
||
|
|
||
| def _deepseek_chat_response() -> httpx.Response: | ||
| return httpx.Response( | ||
| status_code=200, | ||
| json={ | ||
| "choices": [{"message": {"role": "assistant", "content": "# OCR text"}}], | ||
| "usage": { | ||
| "prompt_tokens": PROMPT_TOKENS, | ||
| "completion_tokens": COMPLETION_TOKENS, | ||
| "total_tokens": PROMPT_TOKENS + COMPLETION_TOKENS, | ||
| }, | ||
| }, | ||
| request=httpx.Request("POST", "https://us-central1-aiplatform.googleapis.com"), | ||
| ) | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("model", ["deepseek-ocr-maas", "deepseek-ai/deepseek-ocr-maas"]) | ||
| def test_response_is_priced_from_token_usage_for_either_model_name(local_model_cost_map: None, model: str) -> None: | ||
| response = VertexAIDeepSeekOCRConfig().transform_ocr_response( | ||
| model=model, | ||
| raw_response=_deepseek_chat_response(), | ||
| logging_obj=MagicMock(), | ||
| ) | ||
|
|
||
| cost = completion_cost( | ||
| completion_response=response, | ||
| model=f"vertex_ai/{model}", | ||
| custom_llm_provider="vertex_ai", | ||
| call_type="ocr", | ||
| ) | ||
|
|
||
| assert response.model == "deepseek-ai/deepseek-ocr-maas" | ||
| assert cost == pytest.approx(PROMPT_TOKENS * INPUT_COST_PER_TOKEN + COMPLETION_TOKENS * OUTPUT_COST_PER_TOKEN) | ||
| assert cost > 0 | ||
|
|
||
|
|
||
| def test_json_content_without_pages_reports_the_canonical_model(local_model_cost_map: None) -> None: | ||
| raw_response = httpx.Response( | ||
| 200, | ||
| json={ | ||
| "choices": [{"message": {"role": "assistant", "content": '{"text": "# OCR text"}'}}], | ||
| "usage": {"prompt_tokens": PROMPT_TOKENS, "completion_tokens": COMPLETION_TOKENS}, | ||
| }, | ||
| request=httpx.Request("POST", "https://example.invalid"), | ||
| ) | ||
|
|
||
| response = VertexAIDeepSeekOCRConfig().transform_ocr_response( | ||
| model="deepseek-ocr-maas", | ||
| raw_response=raw_response, | ||
| logging_obj=MagicMock(), | ||
| ) | ||
|
|
||
| assert response.model == "deepseek-ai/deepseek-ocr-maas" | ||
| assert response.pages[0].markdown == '{"text": "# OCR text"}' | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Several newly added test declarations and assertions exceed the repository's 120-character Python line limit, including this line, line 45, and
tests/test_litellm/test_cost_calculator.py:4480; wrap them to keep formatting and lint checks passing.Context Used: CLAUDE.md (source)
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!