-
Notifications
You must be signed in to change notification settings - Fork 5
Support OPENAI_BASE_URL routing and JSON parsing #453
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
bpulluta
wants to merge
6
commits into
main
Choose a base branch
from
litellm-dev
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
6 commits
Select commit
Hold shift + click to select a range
3b12270
Add OpenAI base URL env support and JSON parse fallback
bpulluta 85e86e0
Potential fix for pull request finding
bpulluta ab329cd
Condense _parse_first_json_payload docstring to single-line summary
Copilot 0f71695
fix indentation issue causing ruff failure
bpulluta b8bb788
Potential fix for pull request finding
bpulluta da66d3f
formatted parsing.py for ruff issue
bpulluta 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,54 @@ | ||
| """Tests for LLM configuration helpers""" | ||
|
|
||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from compass.llm.config import OpenAIConfig | ||
|
|
||
|
|
||
| def test_openai_client_kwargs_loaded_from_env(monkeypatch): | ||
| """OpenAI kwargs can be populated from OPENAI_* env vars""" | ||
| monkeypatch.setenv("OPENAI_API_KEY", "test-openai-key") | ||
| monkeypatch.setenv("OPENAI_BASE_URL", "https://litellm.example.gov") | ||
|
|
||
| config = OpenAIConfig(name="gpt-4o-mini", client_type="openai") | ||
|
|
||
| assert config.client_kwargs["api_key"] == "test-openai-key" | ||
| assert config.client_kwargs["base_url"] == "https://litellm.example.gov" | ||
|
|
||
|
|
||
| def test_openai_client_kwargs_user_values_take_precedence(monkeypatch): | ||
| """Explicit client kwargs should not be replaced by env vars""" | ||
| monkeypatch.setenv("OPENAI_API_KEY", "env-key") | ||
| monkeypatch.setenv("OPENAI_BASE_URL", "https://env.example") | ||
|
|
||
| config = OpenAIConfig( | ||
| name="gpt-4o-mini", | ||
| client_type="openai", | ||
| client_kwargs={ | ||
| "api_key": "user-key", | ||
| "base_url": "https://user.example", | ||
| }, | ||
| ) | ||
|
|
||
| assert config.client_kwargs["api_key"] == "user-key" | ||
| assert config.client_kwargs["base_url"] == "https://user.example" | ||
|
|
||
|
|
||
| def test_azure_client_kwargs_unchanged(monkeypatch): | ||
| """Azure env var mapping remains unchanged""" | ||
| monkeypatch.setenv("AZURE_OPENAI_API_KEY", "azure-key") | ||
| monkeypatch.setenv("AZURE_OPENAI_VERSION", "2024-02-15-preview") | ||
| monkeypatch.setenv("AZURE_OPENAI_ENDPOINT", "https://azure.example") | ||
|
|
||
| config = OpenAIConfig(name="gpt-4o-mini", client_type="azure") | ||
|
|
||
| assert config.client_kwargs["api_key"] == "azure-key" | ||
| assert config.client_kwargs["api_version"] == "2024-02-15-preview" | ||
| assert config.client_kwargs["azure_endpoint"] == "https://azure.example" | ||
| assert "base_url" not in config.client_kwargs | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| pytest.main(["-q", "--show-capture=all", Path(__file__), "-rapP"]) |
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.
Uh oh!
There was an error while loading. Please reload this page.