-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat(models): support Databricks-hosted models #2464
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4d52668
feat(models): support Databricks-hosted models
naorpeled 51be212
fix(databricks): don't forward foreign provider key; tidy test imports
naorpeled 173df5a
fix(databricks): don't forward foreign api_base for databricks models
naorpeled b74e88f
fix(databricks): keep databricks guards intact under Azure mode
naorpeled d590363
test(databricks): restore global litellm.api_key to prevent state lea…
naorpeled 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| """ | ||
| Tests for Databricks provider wiring in LiteLLMAIHandler.__init__. | ||
|
|
||
| Verifies that DATABRICKS.API_KEY / DATABRICKS.API_BASE settings are exported to | ||
| the env vars LiteLLM's Databricks provider reads (DATABRICKS_API_KEY / | ||
| DATABRICKS_API_BASE), and that nothing is exported when they are unset. | ||
| """ | ||
| import os | ||
|
|
||
| import litellm | ||
| import pytest | ||
|
|
||
| import pr_agent.algo.ai_handlers.litellm_ai_handler as litellm_handler | ||
|
github-advanced-security[bot] marked this conversation as resolved.
Fixed
github-code-quality[bot] marked this conversation as resolved.
Fixed
|
||
|
|
||
| # Env vars LiteLLMAIHandler.__init__ branches on — clear them so the handler | ||
| # under test isn't influenced by (or leaking into) the runner environment. | ||
| _ISOLATED_ENV = ( | ||
| "DATABRICKS_API_KEY", | ||
| "DATABRICKS_API_BASE", | ||
| "OPENAI_API_KEY", | ||
| "AWS_USE_IMDS", | ||
| "AWS_ACCESS_KEY_ID", | ||
| "AWS_SECRET_ACCESS_KEY", | ||
| "AWS_SESSION_TOKEN", | ||
| "AWS_REGION_NAME", | ||
| ) | ||
|
|
||
|
|
||
| def _make_settings(overrides): | ||
| """Minimal settings whose top-level .get() returns the provided overrides.""" | ||
| return type("Settings", (), { | ||
| "config": type("Config", (), { | ||
| "reasoning_effort": None, | ||
| "ai_timeout": 30, | ||
| "custom_reasoning_model": False, | ||
| "max_model_tokens": 32000, | ||
| "verbosity_level": 0, | ||
| "seed": -1, | ||
| "get": lambda self, key, default=None: default, | ||
| })(), | ||
| "litellm": type("LiteLLM", (), { | ||
| "get": lambda self, key, default=None: default, | ||
| })(), | ||
| "get": lambda self, key, default=None: overrides.get(key, default), | ||
| })() | ||
|
|
||
|
|
||
| @pytest.fixture(autouse=True) | ||
| def _isolate_env(monkeypatch): | ||
| for var in _ISOLATED_ENV: | ||
| monkeypatch.delenv(var, raising=False) | ||
| # LiteLLMAIHandler.__init__ mutates the global litellm.api_key (sets the dummy | ||
| # fallback when OPENAI_API_KEY is absent, as it is here). Snapshot it so this | ||
| # file can't leak that global into order-dependent later tests. | ||
| saved_api_key = litellm.api_key | ||
| yield | ||
| litellm.api_key = saved_api_key | ||
| # Drop anything the handler wrote so it can't leak into other tests; | ||
| # monkeypatch then restores any pre-existing originals. | ||
| for var in ("DATABRICKS_API_KEY", "DATABRICKS_API_BASE"): | ||
| os.environ.pop(var, None) | ||
|
|
||
|
|
||
| def test_databricks_env_vars_exported_from_settings(monkeypatch): | ||
| overrides = { | ||
| "DATABRICKS.API_KEY": "dapi-test-123", | ||
| "DATABRICKS.API_BASE": "https://adb-1234.azuredatabricks.net/serving-endpoints", | ||
| } | ||
| monkeypatch.setattr(litellm_handler, "get_settings", lambda: _make_settings(overrides)) | ||
|
|
||
| litellm_handler.LiteLLMAIHandler() | ||
|
|
||
| assert os.environ["DATABRICKS_API_KEY"] == "dapi-test-123" | ||
| assert os.environ["DATABRICKS_API_BASE"] == "https://adb-1234.azuredatabricks.net/serving-endpoints" | ||
|
|
||
|
|
||
| def test_databricks_env_vars_absent_when_unset(monkeypatch): | ||
| monkeypatch.setattr(litellm_handler, "get_settings", lambda: _make_settings({})) | ||
|
|
||
| litellm_handler.LiteLLMAIHandler() | ||
|
|
||
| assert "DATABRICKS_API_KEY" not in os.environ | ||
| assert "DATABRICKS_API_BASE" not in os.environ | ||
|
|
||
|
|
||
| def test_databricks_api_base_optional(monkeypatch): | ||
| """API base is optional (a workspace default may be configured elsewhere).""" | ||
| overrides = {"DATABRICKS.API_KEY": "dapi-only-key"} | ||
| monkeypatch.setattr(litellm_handler, "get_settings", lambda: _make_settings(overrides)) | ||
|
|
||
| litellm_handler.LiteLLMAIHandler() | ||
|
|
||
| assert os.environ["DATABRICKS_API_KEY"] == "dapi-only-key" | ||
| assert "DATABRICKS_API_BASE" not in os.environ | ||
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.