mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-20 12:29:17 +08:00
fix: convert backwards invocation into BaseBackwardsResponse
This commit is contained in:
parent
97a3727962
commit
8b30099672
@ -162,7 +162,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|||||||
|
|
||||||
def single_iteration_generate(
|
def single_iteration_generate(
|
||||||
self, app_model: App, workflow: Workflow, node_id: str, user: Account | EndUser, args: dict, stream: bool = True
|
self, app_model: App, workflow: Workflow, node_id: str, user: Account | EndUser, args: dict, stream: bool = True
|
||||||
) -> dict[str, Any] | Generator[str, Any, None]:
|
) -> dict[str, Any] | Generator[str | dict[str, Any], Any, None]:
|
||||||
"""
|
"""
|
||||||
Generate App response.
|
Generate App response.
|
||||||
|
|
||||||
@ -218,7 +218,7 @@ class AdvancedChatAppGenerator(MessageBasedAppGenerator):
|
|||||||
application_generate_entity: AdvancedChatAppGenerateEntity,
|
application_generate_entity: AdvancedChatAppGenerateEntity,
|
||||||
conversation: Optional[Conversation] = None,
|
conversation: Optional[Conversation] = None,
|
||||||
stream: bool = True,
|
stream: bool = True,
|
||||||
) -> dict[str, Any] | Generator[str, Any, None]:
|
) -> dict[str, Any] | Generator[str | dict[str, Any], Any, None]:
|
||||||
"""
|
"""
|
||||||
Generate App response.
|
Generate App response.
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import json
|
|
||||||
from collections.abc import Generator
|
from collections.abc import Generator
|
||||||
from typing import Generic, Optional, TypeVar
|
from typing import Generic, Optional, TypeVar
|
||||||
|
|
||||||
@ -19,10 +18,7 @@ class BaseBackwardsInvocation:
|
|||||||
error_message = BaseBackwardsInvocationResponse(error=str(e)).model_dump_json()
|
error_message = BaseBackwardsInvocationResponse(error=str(e)).model_dump_json()
|
||||||
yield f"{error_message}\n\n".encode()
|
yield f"{error_message}\n\n".encode()
|
||||||
else:
|
else:
|
||||||
if isinstance(response, BaseModel):
|
yield BaseBackwardsInvocationResponse(data=response).model_dump_json().encode() + b"\n\n"
|
||||||
yield response.model_dump_json().encode() + b"\n\n"
|
|
||||||
else:
|
|
||||||
yield json.dumps(response).encode() + b"\n\n"
|
|
||||||
|
|
||||||
|
|
||||||
T = TypeVar("T", bound=dict | str | bool | int | BaseModel)
|
T = TypeVar("T", bound=dict | str | bool | int | BaseModel)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user