Skip to content

Commit 84bf4f4

Browse files
[Fix] Fixing http_request open_ai_client mixin
1 parent 4bcfb0a commit 84bf4f4

File tree

2 files changed

+59
-51
lines changed

2 files changed

+59
-51
lines changed

databricks/sdk/mixins/open_ai_client.py

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import json as js
2+
from requests import Response
23
from typing import Dict, Optional
34

45
from databricks.sdk.service.serving import (ExternalFunctionRequestHttpMethod,
5-
ExternalFunctionResponse,
66
ServingEndpointsAPI)
77

8-
98
class ServingEndpointsExt(ServingEndpointsAPI):
109

1110
# Using the HTTP Client to pass in the databricks authorization
@@ -63,7 +62,7 @@ def http_request(self,
6362
*,
6463
headers: Optional[Dict[str, str]] = None,
6564
json: Optional[Dict[str, str]] = None,
66-
params: Optional[Dict[str, str]] = None) -> ExternalFunctionResponse:
65+
params: Optional[Dict[str, str]] = None) -> Response:
6766
"""Make external services call using the credentials stored in UC Connection.
6867
**NOTE:** Experimental: This API may change or be removed in a future release without warning.
6968
:param conn: str
@@ -79,13 +78,28 @@ def http_request(self,
7978
JSON payload for the request.
8079
:param params: Dict[str,str] (optional)
8180
Query parameters for the request.
82-
:returns: :class:`ExternalFunctionResponse`
81+
:returns: :class:`Response`
8382
"""
83+
response = Response()
84+
response.status_code = 200
85+
server_response = super().http_request(connection_name=conn,
86+
method=method,
87+
path=path,
88+
headers=js.dumps(headers) if headers is not None else None,
89+
json=js.dumps(json) if json is not None else None,
90+
params=js.dumps(params) if params is not None else None
91+
)
92+
93+
# Read the content from the HttpRequestResponse object
94+
if hasattr(server_response, "contents") and hasattr(server_response.contents, "read"):
95+
raw_content = server_response.contents.read() # Read the bytes
96+
else:
97+
raise ValueError("Invalid response from the server.")
98+
99+
# Set the raw content
100+
if isinstance(raw_content, bytes):
101+
response._content = raw_content
102+
else:
103+
raise ValueError("Contents must be bytes.")
84104

85-
return super.http_request(connection_name=conn,
86-
method=method,
87-
path=path,
88-
headers=js.dumps(headers),
89-
json=js.dumps(json),
90-
params=js.dumps(params),
91-
)
105+
return response

databricks/sdk/service/serving.py

Lines changed: 34 additions & 40 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)