Repository navigation
feat(providers): add Pareto Inference as OpenAI-compatible provider #42789
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
dylanduyvu
wants to merge
1
commit into
BerriAI:main
Choose a base branch
from
dylanduyvu:feat/add-pareto-provider
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
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
114 changes: 114 additions & 0 deletions
114
tests/test_litellm/llms/openai_like/test_pareto_provider.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,114 @@ | ||
| import json | ||
| from pathlib import Path | ||
| from typing import Final | ||
|
|
||
| import pytest | ||
| import respx | ||
|
|
||
| import litellm | ||
| from litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider | ||
| from litellm.llms.openai_like.json_loader import JSONProviderRegistry, SimpleProviderConfig | ||
|
|
||
| MODEL: Final = "z-ai/glm-5.3-flash" | ||
| REPO_ROOT: Final = Path(__file__).parents[4] | ||
| COST_MAPS: Final = ( | ||
| REPO_ROOT / "model_prices_and_context_window.json", | ||
| REPO_ROOT / "litellm" / "model_prices_and_context_window_backup.json", | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def pareto() -> SimpleProviderConfig: | ||
| config: Final = JSONProviderRegistry.get("pareto") | ||
| assert config is not None | ||
| return config | ||
|
|
||
|
|
||
| def test_prefixed_model_resolves_to_pareto_and_keeps_the_vendor_namespace( | ||
| pareto: SimpleProviderConfig, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| monkeypatch.delenv("PARETO_API_BASE", raising=False) | ||
|
|
||
| model, provider, _, api_base = get_llm_provider(model=f"pareto/{MODEL}") | ||
|
|
||
| assert provider == litellm.LlmProviders.PARETO.value | ||
| assert model == MODEL | ||
| assert api_base == pareto.base_url | ||
|
|
||
|
|
||
| def test_api_key_and_base_are_read_from_pareto_env_vars(monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.delenv("OPENAI_API_KEY", raising=False) | ||
| monkeypatch.setenv("PARETO_API_KEY", "sk-pareto-env") | ||
| monkeypatch.setenv("PARETO_API_BASE", "https://pareto.internal.example/v1") | ||
|
|
||
| _, provider, api_key, api_base = get_llm_provider(model=f"pareto/{MODEL}") | ||
|
|
||
| assert provider == "pareto" | ||
| assert api_key == "sk-pareto-env" | ||
| assert api_base == "https://pareto.internal.example/v1" | ||
|
|
||
|
|
||
| def test_default_api_base_autodetects_pareto(pareto: SimpleProviderConfig, monkeypatch: pytest.MonkeyPatch) -> None: | ||
| monkeypatch.setenv("PARETO_API_KEY", "sk-pareto-env") | ||
|
|
||
| model, provider, api_key, _ = get_llm_provider(model=MODEL, api_base=pareto.base_url) | ||
|
|
||
| assert provider == "pareto" | ||
| assert model == MODEL | ||
| assert api_key == "sk-pareto-env" | ||
|
|
||
|
|
||
| @respx.mock | ||
| def test_completion_posts_to_pareto_chat_completions_with_bearer_key( | ||
| pareto: SimpleProviderConfig, monkeypatch: pytest.MonkeyPatch | ||
| ) -> None: | ||
| monkeypatch.delenv("PARETO_API_BASE", raising=False) | ||
| monkeypatch.setenv("PARETO_API_KEY", "sk-pareto-env") | ||
| route: Final = respx.post(f"{pareto.base_url}/chat/completions").respond( | ||
| json={ | ||
| "id": "chatcmpl-pareto", | ||
| "object": "chat.completion", | ||
| "created": 1, | ||
| "model": MODEL, | ||
| "choices": [{"index": 0, "message": {"role": "assistant", "content": "hi"}, "finish_reason": "stop"}], | ||
| "usage": {"prompt_tokens": 5, "completion_tokens": 1, "total_tokens": 6}, | ||
| } | ||
| ) | ||
|
|
||
| response: Final = litellm.completion( | ||
| model=f"pareto/{MODEL}", | ||
| messages=[{"role": "user", "content": "hello"}], | ||
| ) | ||
|
|
||
| assert route.call_count == 1 | ||
| request: Final = route.calls.last.request | ||
| assert request.headers["authorization"] == "Bearer sk-pareto-env" | ||
| assert json.loads(request.content)["model"] == MODEL | ||
| assert response.choices[0].message.content == "hi" | ||
| assert response.usage.total_tokens == 6 | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def local_model_cost_map(monkeypatch: pytest.MonkeyPatch): | ||
| """Resolve pricing against the in-repo cost map, not the remote one fetched at import.""" | ||
| monkeypatch.setenv("LITELLM_LOCAL_MODEL_COST_MAP", "True") | ||
| monkeypatch.setattr(litellm, "model_cost", litellm.get_model_cost_map(url="")) | ||
| litellm.get_model_info.cache_clear() | ||
| yield | ||
| litellm.get_model_info.cache_clear() | ||
|
|
||
|
|
||
| def test_cost_maps_carry_the_same_pareto_entry() -> None: | ||
| main, backup = (json.loads(path.read_text())[f"pareto/{MODEL}"] for path in COST_MAPS) | ||
|
|
||
| assert main == backup | ||
| assert main["litellm_provider"] == "pareto" | ||
|
|
||
|
|
||
| def test_published_per_token_prices_are_used_for_cost(local_model_cost_map: None) -> None: | ||
| prompt_cost, completion_cost = litellm.cost_per_token( | ||
| model=f"pareto/{MODEL}", prompt_tokens=1_000_000, completion_tokens=1_000_000 | ||
| ) | ||
|
|
||
| assert prompt_cost == pytest.approx(0.03) | ||
| assert completion_cost == pytest.approx(0.10) |
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.
Adding Pareto to
openai_compatible_providersalso adds it toOPENAI_AUDIO_TRANSCRIPTION_PROVIDERS. As a result,transcription(model="pareto/...")selects the OpenAI transcription transport and sends a request to Pareto's/audio/transcriptionsendpoint, even though the new capability map declares audio transcription unsupported. This should be gated by the declared capability or otherwise excluded so unsupported calls are rejected locally instead of being sent upstream.Knowledge Base Used: Provider adapters and capabilities