Repository navigation
fix(groq): register and correctly route compound systems #32470
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
Closed
Closed
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
Some comments aren't visible on the classic Files Changed page.
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
92 changes: 92 additions & 0 deletions
92
tests/test_litellm/llms/groq/chat/test_groq_chat_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,92 @@ | ||
| import json | ||
| from pathlib import Path | ||
| from unittest.mock import patch | ||
|
|
||
| import httpx | ||
| import pytest | ||
|
|
||
| import litellm | ||
| from litellm.llms.custom_httpx.http_handler import HTTPHandler | ||
| from litellm.llms.groq.chat.transformation import GroqChatConfig | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "model, expected", | ||
| [ | ||
| ("compound", "groq/compound"), | ||
| ("compound-mini", "groq/compound-mini"), | ||
| ("llama-3.3-70b-versatile", "llama-3.3-70b-versatile"), | ||
| ("openai/gpt-oss-120b", "openai/gpt-oss-120b"), | ||
| ], | ||
| ) | ||
| def test_get_groq_model_name(model, expected): | ||
| assert GroqChatConfig._get_groq_model_name(model) == expected | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("model", ["groq/compound", "groq/compound-mini"]) | ||
| def test_compound_models_in_backup_cost_map(model): | ||
| """ | ||
| Regression test for https://github.com/BerriAI/litellm/issues/32467 | ||
|
|
||
| The Groq compound systems must be registered so they route through the groq | ||
| provider and expose metadata. | ||
| """ | ||
| json_path = Path(__file__).parents[5] / "litellm" / "model_prices_and_context_window_backup.json" | ||
| with open(json_path) as f: | ||
| model_cost = json.load(f) | ||
|
|
||
| info = model_cost.get(model) | ||
| assert info is not None, f"{model} missing from backup JSON" | ||
| assert info["litellm_provider"] == "groq" | ||
| assert info["mode"] == "chat" | ||
| assert info["max_input_tokens"] == 131072 | ||
| assert info["max_output_tokens"] == 8192 | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "requested_model, expected_api_model", | ||
| [ | ||
| ("groq/compound", "groq/compound"), | ||
| ("groq/compound-mini", "groq/compound-mini"), | ||
| ("groq/llama-3.3-70b-versatile", "llama-3.3-70b-versatile"), | ||
| ], | ||
| ) | ||
| def test_compound_model_name_sent_to_groq(requested_model, expected_api_model): | ||
| """ | ||
| Regression test for https://github.com/BerriAI/litellm/issues/32467 | ||
|
|
||
| Groq exposes the compound systems with the "groq/" prefix as part of the | ||
| actual model id, so LiteLLM must send "groq/compound(-mini)" instead of the | ||
| prefix-stripped "compound(-mini)", which Groq rejects with model_not_found. | ||
| """ | ||
| client = HTTPHandler() | ||
| fake_response = httpx.Response( | ||
| status_code=200, | ||
| json={ | ||
| "id": "chatcmpl-1", | ||
| "object": "chat.completion", | ||
| "created": 1, | ||
| "model": expected_api_model, | ||
| "service_tier": "auto", | ||
| "choices": [ | ||
| { | ||
| "index": 0, | ||
| "message": {"role": "assistant", "content": "hi"}, | ||
| "finish_reason": "stop", | ||
| } | ||
| ], | ||
| "usage": {"prompt_tokens": 1, "completion_tokens": 1, "total_tokens": 2}, | ||
| }, | ||
| request=httpx.Request("POST", "https://api.groq.com/openai/v1/chat/completions"), | ||
| ) | ||
|
|
||
| with patch.object(client, "post", return_value=fake_response) as mock_post: | ||
| litellm.completion( | ||
| model=requested_model, | ||
| messages=[{"role": "user", "content": "hi"}], | ||
| api_key="fake-key", | ||
| client=client, | ||
| ) | ||
|
|
||
| sent_body = json.loads(mock_post.call_args.kwargs["data"]) | ||
| assert sent_body["model"] == expected_api_model |
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.
GROQ_COMPOUND_MODELSis a hardcoded frozenset in the codebase. The team's explicit rule is to put model-specific flags inmodel_prices_and_context_window.jsonand read them viaget_model_info, so that adding a new model (e.g. a futuregroq/compound-pro) works without a LiteLLM code update. The JSON entries for these models are already added in this PR, so a custom field like"requires_groq_prefix": truecould be added there and checked vialitellm.get_model_info(f"groq/{model}")in_get_groq_model_name. The current approach means any new Groq compound variant requires both a JSON entry and a code change to stay correct.Rule Used: What: Do not hardcode model-specific flags in the ... (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!