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