|
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) |
2 | 7 |
|
3 | 8 |
|
4 | 9 | class ServingEndpointsExt(ServingEndpointsAPI): |
@@ -50,3 +55,41 @@ def get_langchain_chat_open_ai_client(self, model): |
50 | 55 | openai_api_base=self._api._cfg.host + "/serving-endpoints", |
51 | 56 | api_key="no-token", # Passing in a placeholder to pass validations, this will not be used |
52 | 57 | 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 | + **NOTE:** Experimental: This API may change or be removed in a future release without warning. |
| 70 | +
|
| 71 | + :param conn: str |
| 72 | + The connection name to use. This is required to identify the external connection. |
| 73 | + :param method: :class:`ExternalFunctionRequestMethod` |
| 74 | + The HTTP method to use (e.g., 'GET', 'POST'). This is required. |
| 75 | + :param path: str |
| 76 | + The relative path for the API endpoint. This is required. |
| 77 | + :param headers: Dict[str,str] (optional) |
| 78 | + Additional headers for the request. If not provided, only auth headers from connections would be |
| 79 | + passed. |
| 80 | + :param json: Dict[str,str] (optional) |
| 81 | + JSON payload for the request. |
| 82 | + :param params: Dict[str,str] (optional) |
| 83 | + Query parameters for the request. |
| 84 | +
|
| 85 | + :returns: :class:`ExternalFunctionResponse` |
| 86 | + """ |
| 87 | + |
| 88 | + return super.http_request( |
| 89 | + connection_name=conn, |
| 90 | + method=method, |
| 91 | + path=path, |
| 92 | + headers=headers, |
| 93 | + json=js.dumps(json), |
| 94 | + params=js.dumps(params), |
| 95 | + ) |
0 commit comments