|
@@ -11,13 +11,10 @@ class BaseBackwardsInvocation:
|
|
|
if isinstance(response, Generator):
|
|
|
try:
|
|
|
for chunk in response:
|
|
|
- if isinstance(chunk, BaseModel):
|
|
|
+ if isinstance(chunk, BaseModel | dict):
|
|
|
yield BaseBackwardsInvocationResponse(data=chunk).model_dump_json().encode() + b"\n\n"
|
|
|
-
|
|
|
elif isinstance(chunk, str):
|
|
|
yield f"event: {chunk}\n\n".encode()
|
|
|
- else:
|
|
|
- yield json.dumps(chunk).encode() + b"\n\n"
|
|
|
except Exception as e:
|
|
|
error_message = BaseBackwardsInvocationResponse(error=str(e)).model_dump_json()
|
|
|
yield f"{error_message}\n\n".encode()
|
|
@@ -28,7 +25,7 @@ class BaseBackwardsInvocation:
|
|
|
yield json.dumps(response).encode() + b"\n\n"
|
|
|
|
|
|
|
|
|
-T = TypeVar("T", bound=BaseModel | dict | str | bool | int)
|
|
|
+T = TypeVar("T", bound=dict | str | bool | int | BaseModel)
|
|
|
|
|
|
|
|
|
class BaseBackwardsInvocationResponse(BaseModel, Generic[T]):
|