|
1 | 1 | import json as js |
2 | 2 | from typing import Dict, Optional |
3 | 3 |
|
| 4 | +from dataclasses import dataclass |
4 | 5 | from databricks.sdk.service.serving import (ExternalFunctionRequestHttpMethod, |
5 | | - ExternalFunctionResponse, |
| 6 | + ExternalFunctionResponse as ExternalFunctionResponseAPI, |
6 | 7 | ServingEndpointsAPI) |
7 | 8 |
|
8 | 9 |
|
| 10 | +@dataclass |
| 11 | +class ExternalFunctionResponse(ExternalFunctionResponseAPI): |
| 12 | + text: Dict[str, any] = None |
| 13 | + """The content of the response""" |
| 14 | + |
| 15 | + @classmethod |
| 16 | + def from_dict(cls, d: Dict[str, any]) -> 'ExternalFunctionResponse': |
| 17 | + """Deserializes the ExternalFunctionResponse from a dictionary.""" |
| 18 | + return cls(status_code=200, text=d) |
| 19 | + |
| 20 | + |
9 | 21 | class ServingEndpointsExt(ServingEndpointsAPI): |
10 | 22 |
|
11 | 23 | # Using the HTTP Client to pass in the databricks authorization |
@@ -82,10 +94,14 @@ def http_request(self, |
82 | 94 | :returns: :class:`ExternalFunctionResponse` |
83 | 95 | """ |
84 | 96 |
|
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 | | - ) |
| 97 | + body = {} |
| 98 | + if conn is not None: body['connection_name'] = conn |
| 99 | + if headers is not None: body['headers'] = js.dumps(headers) |
| 100 | + if json is not None: body['json'] = js.dumps(json) |
| 101 | + if method is not None: body['method'] = method.value |
| 102 | + if params is not None: body['params'] = js.dumps(params) |
| 103 | + if path is not None: body['path'] = path |
| 104 | + headers = {'Accept': 'application/json', 'Content-Type': 'application/json', } |
| 105 | + |
| 106 | + res = self._api.do('POST', '/api/2.0/external-function', body=body, headers=headers) |
| 107 | + return ExternalFunctionResponse.from_dict(res) |
0 commit comments