Skip to content

Commit 6e267f5

Browse files
committed
Fix
Signed-off-by: Sid Murching <[email protected]>
1 parent 795c69f commit 6e267f5

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
lines changed

NEXT_CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
### New Features and Improvements
66

7+
* Added support for passing additional kwargs to `WorkspaceClient().serving_endpoints.get_open_ai_client()` ([#XXX](https://github.com/databricks/databricks-sdk-py/pull/XXX)). Users can now pass standard OpenAI client parameters like `timeout` and `max_retries` when creating an OpenAI client for Databricks Model Serving.
8+
79
### Bug Fixes
810

911
### Documentation

databricks/sdk/mixins/open_ai_client.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33

44
from requests import Response
55

6-
from databricks.sdk.service.serving import (ExternalFunctionRequestHttpMethod,
7-
HttpRequestResponse,
8-
ServingEndpointsAPI)
6+
from databricks.sdk.service.serving import ExternalFunctionRequestHttpMethod, HttpRequestResponse, ServingEndpointsAPI
97

108

119
class ServingEndpointsExt(ServingEndpointsAPI):
@@ -33,31 +31,31 @@ def auth_flow(self, request: httpx.Request) -> httpx.Request:
3331

3432
def get_open_ai_client(self, **kwargs):
3533
"""Create an OpenAI client configured for Databricks Model Serving.
36-
34+
3735
Returns an OpenAI client instance that is pre-configured to send requests to
3836
Databricks Model Serving endpoints. The client uses Databricks authentication
3937
to query endpoints within the workspace associated with the current WorkspaceClient
4038
instance.
41-
39+
4240
Args:
4341
**kwargs: Additional parameters to pass to the OpenAI client constructor.
4442
Common parameters include:
4543
- timeout (float): Request timeout in seconds (e.g., 30.0)
4644
- max_retries (int): Maximum number of retries for failed requests (e.g., 3)
4745
4846
Any parameter accepted by the OpenAI client constructor can be passed here.
49-
47+
5048
Returns:
5149
OpenAI: An OpenAI client instance configured for Databricks Model Serving.
52-
50+
5351
Raises:
5452
ImportError: If the OpenAI library is not installed.
55-
53+
5654
Example:
5755
>>> client = workspace_client.serving_endpoints.get_open_ai_client()
5856
>>> # With custom timeout and retries
5957
>>> client = workspace_client.serving_endpoints.get_open_ai_client(
60-
... timeout=30.0,
58+
... timeout=30.0,
6159
... max_retries=5
6260
... )
6361
"""
@@ -74,7 +72,7 @@ def get_open_ai_client(self, **kwargs):
7472
"api_key": "no-token", # Passing in a placeholder to pass validations, this will not be used
7573
"http_client": self._get_authorized_http_client(),
7674
}
77-
75+
7876
# Update with any additional parameters passed by the user
7977
client_params.update(kwargs)
8078

tests/test_open_ai_mixin.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def test_open_ai_client_with_custom_params(monkeypatch):
2525
monkeypatch.setenv("DATABRICKS_HOST", "test_host")
2626
monkeypatch.setenv("DATABRICKS_TOKEN", "test_token")
2727
w = WorkspaceClient(config=Config())
28-
28+
2929
# Test with timeout and max_retries parameters
3030
client = w.serving_endpoints.get_open_ai_client(timeout=30.0, max_retries=3)
3131

@@ -41,12 +41,10 @@ def test_open_ai_client_with_additional_kwargs(monkeypatch):
4141
monkeypatch.setenv("DATABRICKS_HOST", "test_host")
4242
monkeypatch.setenv("DATABRICKS_TOKEN", "test_token")
4343
w = WorkspaceClient(config=Config())
44-
44+
4545
# Test with additional kwargs that OpenAI client might accept
4646
client = w.serving_endpoints.get_open_ai_client(
47-
timeout=60.0,
48-
max_retries=5,
49-
default_headers={"Custom-Header": "test-value"}
47+
timeout=60.0, max_retries=5, default_headers={"Custom-Header": "test-value"}
5048
)
5149

5250
assert client.base_url == "https://test_host/serving-endpoints/"

0 commit comments

Comments
 (0)