Add builtin deserialization
This commit is contained in:
parent
8692cc60ee
commit
6a50f87abe
1 changed files with 15 additions and 8 deletions
|
|
@ -1,4 +1,6 @@
|
|||
from typing import Any, Mapping, Optional
|
||||
from typing import Any, Mapping, Optional, Type, TypeVar
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..views import Trace
|
||||
from .http_client import HttpClient
|
||||
|
|
@ -6,10 +8,11 @@ from .remote_call_error import RemoteCallError
|
|||
|
||||
http: Optional[HttpClient] = None
|
||||
|
||||
T = TypeVar("T", BaseModel)
|
||||
|
||||
async def call_remote_great_ai_async(
|
||||
base_uri: str, data: Mapping[str, Any], retry_count: int = 4
|
||||
) -> Trace:
|
||||
base_uri: str, data: Mapping[str, Any], retry_count: int = 4, model_class:Optional[Type[T]]=None
|
||||
) -> Trace[T]:
|
||||
global http
|
||||
if http is None:
|
||||
http = HttpClient()
|
||||
|
|
@ -23,6 +26,8 @@ async def call_remote_great_ai_async(
|
|||
)
|
||||
|
||||
try:
|
||||
if model_class is not None:
|
||||
response['output'] = model_class.parse_obj(response['output'])
|
||||
return Trace.parse_obj(response)
|
||||
except Exception:
|
||||
raise RemoteCallError("Could not parse response")
|
||||
|
|
|
|||
Loading…
Reference in a new issue