Skip to content

Commit

Permalink
Adding http_request to serving to call external-function
Browse files Browse the repository at this point in the history
Signed-off-by: Sunish Sheth <sunishsheth2009@gmail.com>
  • Loading branch information
pietern authored and sunishsheth2009 committed Jan 13, 2025
1 parent cbae014 commit fe1de1b
Show file tree
Hide file tree
Showing 2 changed files with 429 additions and 211 deletions.
44 changes: 43 additions & 1 deletion databricks/sdk/mixins/open_ai_client.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
from databricks.sdk.service.serving import ServingEndpointsAPI
import json as js
from typing import Dict, Optional

from databricks.sdk.service.serving import (ExternalFunctionRequestHttpMethod,
ExternalFunctionResponse,
ServingEndpointsAPI)


class ServingEndpointsExt(ServingEndpointsAPI):
Expand Down Expand Up @@ -50,3 +55,40 @@ def get_langchain_chat_open_ai_client(self, model):
openai_api_base=self._api._cfg.host + "/serving-endpoints",
api_key="no-token", # Passing in a placeholder to pass validations, this will not be used
http_client=self._get_authorized_http_client())

def http_request(self,
conn: str,
method: ExternalFunctionRequestHttpMethod,
path: str,
*,
headers: Optional[Dict[str, str]] = None,
json: Optional[Dict[str, str]] = None,
params: Optional[Dict[str, str]] = None) -> ExternalFunctionResponse:
"""Make external services call using the credentials stored in UC Connection.
**NOTE:** Experimental: This API may change or be removed in a future release without warning.
:param conn: str
The connection name to use. This is required to identify the external connection.
:param method: :class:`ExternalFunctionRequestHttpMethod`
The HTTP method to use (e.g., 'GET', 'POST'). This is required.
:param path: str
The relative path for the API endpoint. This is required.
:param headers: Dict[str,str] (optional)
Additional headers for the request. If not provided, only auth headers from connections would be
passed.
:param json: Dict[str,str] (optional)
JSON payload for the request.
:param params: Dict[str,str] (optional)
Query parameters for the request.
:returns: :class:`ExternalFunctionResponse`
"""

return super.http_request(connection_name=conn,
method=method,
path=path,
headers=js.dumps(headers),
json=js.dumps(json),
params=js.dumps(params),
)
Loading

0 comments on commit fe1de1b

Please sign in to comment.