fix: convert backwards invocation into BaseBackwardsResponse

This commit is contained in:
Yeuoly
2024-11-19 14:03:40 +08:00
parent 97a3727962
commit 8b30099672
2 changed files with 3 additions and 7 deletions

View File

@ -1,4 +1,3 @@
import json
from collections.abc import Generator
from typing import Generic, Optional, TypeVar
@ -19,10 +18,7 @@ class BaseBackwardsInvocation:
error_message = BaseBackwardsInvocationResponse(error=str(e)).model_dump_json()
yield f"{error_message}\n\n".encode()
else:
if isinstance(response, BaseModel):
yield response.model_dump_json().encode() + b"\n\n"
else:
yield json.dumps(response).encode() + b"\n\n"
yield BaseBackwardsInvocationResponse(data=response).model_dump_json().encode() + b"\n\n"
T = TypeVar("T", bound=dict | str | bool | int | BaseModel)