Add remote calls
This commit is contained in:
parent
a63b0ad5e7
commit
e16db17db0
1 changed files with 217 additions and 2 deletions
25
src/great_ai/great_ai/remote/call_remote_great_ai_async.py
Normal file
25
src/great_ai/great_ai/remote/call_remote_great_ai_async.py
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
from typing import Any, Mapping, Optional
|
||||
|
||||
from ..views import Trace
|
||||
from .http_client import HttpClient
|
||||
from .remote_call_error import RemoteCallError
|
||||
|
||||
http: Optional[HttpClient] = None
|
||||
|
||||
|
||||
async def call_remote_great_ai_async(
|
||||
base_uri: str, data: Mapping[str, Any], retry_count: int = 4
|
||||
) -> Trace:
|
||||
global http
|
||||
if http is None:
|
||||
http = HttpClient()
|
||||
|
||||
url = f"{base_uri}/predict/"
|
||||
response = await http.post(
|
||||
url=url, data=data, retry_count=retry_count, expected_status=200
|
||||
)
|
||||
|
||||
try:
|
||||
return Trace.parse_obj(response)
|
||||
except Exception:
|
||||
raise RemoteCallError("Could not parse response")
|
||||
Loading…
Reference in a new issue