Skip to content

Commit 0721970

Browse files
[ML-48691] Adding http_request to serving to call /external-function
Signed-off-by: Sunish Sheth <[email protected]>
1 parent 6d6923e commit 0721970

File tree

2 files changed

+182
-1
lines changed

2 files changed

+182
-1
lines changed

databricks/sdk/mixins/open_ai_client.py

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
from databricks.sdk.service.serving import ServingEndpointsAPI
1+
import json as js
2+
from typing import Dict, Optional
3+
4+
from databricks.sdk.service.serving import (ExternalFunctionRequestMethod,
5+
ExternalFunctionResponse,
6+
ServingEndpointsAPI)
27

38

49
class ServingEndpointsExt(ServingEndpointsAPI):
@@ -50,3 +55,47 @@ def get_langchain_chat_open_ai_client(self, model):
5055
openai_api_base=self._api._cfg.host + "/serving-endpoints",
5156
api_key="no-token", # Passing in a placeholder to pass validations, this will not be used
5257
http_client=self._get_authorized_http_client())
58+
59+
def http_request(self,
60+
conn: str,
61+
method: ExternalFunctionRequestMethod,
62+
path: str,
63+
*,
64+
headers: Optional[Dict[str, str]] = None,
65+
json: Optional[Dict[str, str]] = None,
66+
params: Optional[Dict[str, str]] = None) -> ExternalFunctionResponse:
67+
"""Make external services call using the credentials stored in UC Connection.
68+
69+
:param conn: str
70+
The connection name to use. This is required to identify the external connection.
71+
:param method: :class:`ExternalFunctionRequestMethod`
72+
The HTTP method to use (e.g., 'GET', 'POST'). This is required.
73+
:param path: str
74+
The relative path for the API endpoint. This is required.
75+
:param headers: Dict[str,str] (optional)
76+
Additional headers for the request. If not provided, only auth headers from connections would be
77+
passed.
78+
:param json: Dict[str,str] (optional)
79+
JSON payload for the request.
80+
:param params: Dict[str,str] (optional)
81+
Query parameters for the request.
82+
83+
:returns: :class:`ExternalFunctionResponse`
84+
"""
85+
body = {}
86+
if conn is not None:
87+
body["conn"] = conn
88+
if headers is not None:
89+
body["headers"] = js.dumps(headers)
90+
if json is not None:
91+
body["json"] = js.dumps(json)
92+
if method is not None:
93+
body["method"] = method.value
94+
if params is not None:
95+
body["params"] = js.dumps(params)
96+
if path is not None:
97+
body["path"] = path
98+
headers = {"Accept": "application/json", "Content-Type": "application/json", }
99+
100+
res = self._api.do("POST", "/external-function", body=body, headers=headers)
101+
return ExternalFunctionResponse.from_dict(res)

databricks/sdk/service/serving.py

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

0 commit comments

Comments
 (0)