mirror of
https://github.com/langgenius/dify.git
synced 2024-11-16 19:59:50 +08:00
fix: sse error message
This commit is contained in:
parent
5dcd25a613
commit
1837692a66
|
@ -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]):
|
||||
|
|
Loading…
Reference in New Issue
Block a user