This commit is contained in:
Andras Schmelczer 2022-07-01 21:10:38 +02:00
parent 6a50f87abe
commit 076f676f4f
3 changed files with 20 additions and 9 deletions

View file

@ -112,7 +112,9 @@ class GreatAI(Generic[T]):
), ),
) )
instance = GreatAI[T](func, version=version, return_raw_result=return_raw_result) instance = GreatAI[T](
func, version=version, return_raw_result=return_raw_result
)
if not disable_rest_api: if not disable_rest_api:
instance._bootstrap_rest_api( instance._bootstrap_rest_api(

View file

@ -1,5 +1,5 @@
import asyncio import asyncio
from typing import Any, Mapping, Optional, TypeVar from typing import Any, Mapping, Optional, Type, TypeVar
from pydantic import BaseModel from pydantic import BaseModel
@ -9,9 +9,14 @@ from .call_remote_great_ai_async import call_remote_great_ai_async
logger = get_logger("call_remote_great_ai") logger = get_logger("call_remote_great_ai")
T = TypeVar("T", BaseModel) T = TypeVar("T", bound=BaseModel)
def call_remote_great_ai( def call_remote_great_ai(
base_uri: str, data: Mapping[str, Any], retry_count: int = 4, model_class:Optional[Type[T]]=None base_uri: str,
data: Mapping[str, Any],
retry_count: int = 4,
model_class: Optional[Type[T]] = None,
) -> Trace[T]: ) -> Trace[T]:
try: try:
asyncio.get_running_loop() asyncio.get_running_loop()

View file

@ -8,10 +8,14 @@ from .remote_call_error import RemoteCallError
http: Optional[HttpClient] = None http: Optional[HttpClient] = None
T = TypeVar("T", BaseModel) T = TypeVar("T", bound=BaseModel)
async def call_remote_great_ai_async( async def call_remote_great_ai_async(
base_uri: str, data: Mapping[str, Any], retry_count: int = 4, model_class:Optional[Type[T]]=None base_uri: str,
data: Mapping[str, Any],
retry_count: int = 4,
model_class: Optional[Type[T]] = None,
) -> Trace[T]: ) -> Trace[T]:
global http global http
if http is None: if http is None:
@ -27,7 +31,7 @@ async def call_remote_great_ai_async(
try: try:
if model_class is not None: if model_class is not None:
response['output'] = model_class.parse_obj(response['output']) response["output"] = model_class.parse_obj(response["output"])
return Trace.parse_obj(response) return Trace.parse_obj(response)
except Exception: except Exception:
raise RemoteCallError("Could not parse response") raise RemoteCallError("Could not parse response")