-
Notifications
You must be signed in to change notification settings - Fork 38
Add timeout and retry params to ChatDatabricks #165
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
smurching
merged 8 commits into
databricks:main
from
smurching:smurching/add-timeout-retry-chatdatabricks
Sep 3, 2025
+176
−8
Merged
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e65a3de
[WIP] Add timeout and retry params to ChatDatabricks
smurching 8a3d3bb
Switch to passing kwargs directly, dependent on Databricks Python SDK…
smurching ce97f2b
Bump min SDK version - need to finalize after SDK release
smurching 3e50b8d
Merge main
smurching b3a5224
fix lint
smurching e274a95
Fix lint
smurching 2831044
remove from dev deps
smurching 919b8c9
remove comments
smurching 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,13 +17,14 @@ dependencies = [ | |
| "unitycatalog-langchain[databricks]>=0.2.0", | ||
| "databricks-connect>=16.1.1,<16.4", | ||
| "openai>=1.97.1", | ||
| "databricks-sdk>=0.63.0", | ||
| ] | ||
|
|
||
| [project.optional-dependencies] | ||
| dev = [ | ||
| "pytest", | ||
| "typing_extensions", | ||
| "databricks-sdk>=0.34.0", | ||
| "databricks-sdk>=0.63.0", | ||
|
||
| "ruff==0.6.4", | ||
| ] | ||
|
|
||
|
|
||
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,70 @@ | ||
| """Test utilities module.""" | ||
|
|
||
| from unittest.mock import Mock, patch | ||
|
|
||
| import pytest | ||
|
|
||
| from databricks_langchain.utils import get_openai_client | ||
|
|
||
|
|
||
| def test_get_openai_client_with_timeout_and_max_retries() -> None: | ||
| """Test that get_openai_client properly passes timeout and max_retries as kwargs to the SDK.""" | ||
|
|
||
| mock_openai_client = Mock() | ||
|
|
||
| mock_workspace_client = Mock() | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.return_value = mock_openai_client | ||
|
|
||
| # Test with workspace_client, timeout, and max_retries | ||
| client = get_openai_client( | ||
| workspace_client=mock_workspace_client, | ||
| timeout=45.0, | ||
| max_retries=3 | ||
| ) | ||
|
|
||
| # Verify the OpenAI client was obtained with the correct kwargs | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.assert_called_once_with( | ||
| timeout=45.0, | ||
| max_retries=3 | ||
| ) | ||
|
|
||
| # Verify the client is returned | ||
| assert client == mock_openai_client | ||
|
|
||
|
|
||
| def test_get_openai_client_with_default_workspace_client() -> None: | ||
| """Test get_openai_client creates default WorkspaceClient when none provided.""" | ||
|
|
||
| mock_openai_client = Mock() | ||
|
|
||
| mock_workspace_client = Mock() | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.return_value = mock_openai_client | ||
|
|
||
| with patch("databricks.sdk.WorkspaceClient", return_value=mock_workspace_client): | ||
| client = get_openai_client(timeout=30.0, max_retries=2) | ||
|
|
||
| # Verify default WorkspaceClient was created and kwargs were passed | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.assert_called_once_with( | ||
| timeout=30.0, | ||
| max_retries=2 | ||
| ) | ||
|
|
||
| # Verify the client is returned | ||
| assert client == mock_openai_client | ||
|
|
||
|
|
||
| def test_get_openai_client_without_timeout_and_retries() -> None: | ||
| """Test get_openai_client doesn't pass kwargs when not provided.""" | ||
|
|
||
| mock_openai_client = Mock() | ||
|
|
||
| mock_workspace_client = Mock() | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.return_value = mock_openai_client | ||
|
|
||
| client = get_openai_client(workspace_client=mock_workspace_client) | ||
|
|
||
| # Verify the OpenAI client was obtained without kwargs | ||
| mock_workspace_client.serving_endpoints.get_open_ai_client.assert_called_once_with() | ||
|
|
||
| # Verify the client is returned | ||
| assert client == mock_openai_client |
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.
TODO: update this after SDK releases