diff --git a/agent/canvas.py b/agent/canvas.py index 2acf916ab..c156c133c 100644 --- a/agent/canvas.py +++ b/agent/canvas.py @@ -283,7 +283,7 @@ class Canvas(Graph): else: self.globals[k] = None - def run(self, **kwargs): + async def run(self, **kwargs): st = time.perf_counter() self.message_id = get_uuid() created_at = int(time.time()) diff --git a/agent/component/llm.py b/agent/component/llm.py index b08e0591e..807bbc288 100644 --- a/agent/component/llm.py +++ b/agent/component/llm.py @@ -249,7 +249,7 @@ class LLM(ComponentBase): downstreams = self._canvas.get_component(self._id)["downstream"] if self._canvas.get_component(self._id) else [] ex = self.exception_handler() - if any([self._canvas.get_component_obj(cid).component_name.lower()=="message" for cid in downstreams]) and not output_structure and not (ex and ex["goto"]): + if any([self._canvas.get_component_obj(cid).component_name.lower()=="message" for cid in downstreams]) and not (ex and ex["goto"]): self.set_output("content", partial(self._stream_output, prompt, msg)) return diff --git a/agent/component/message.py b/agent/component/message.py index 555534610..ac1d2beae 100644 --- a/agent/component/message.py +++ b/agent/component/message.py @@ -17,7 +17,6 @@ import json import os import random import re -import pypandoc import logging import tempfile from functools import partial @@ -30,6 +29,7 @@ from common.connection_utils import timeout from common.misc_utils import get_uuid from common import settings + class MessageParam(ComponentParamBase): """ Define the Message component parameters. @@ -176,6 +176,10 @@ class Message(ComponentBase): return "" def _convert_content(self, content): + if not self._param.output_format: + return + + import pypandoc doc_id = get_uuid() if self._param.output_format.lower() not in {"markdown", "html", "pdf", "docx"}: diff --git a/api/apps/canvas_app.py b/api/apps/canvas_app.py index 2e90c29c0..86ffaedb1 100644 --- a/api/apps/canvas_app.py +++ b/api/apps/canvas_app.py @@ -159,10 +159,10 @@ async def run(): except Exception as e: return server_error_response(e) - def sse(): + async def sse(): nonlocal canvas, user_id try: - for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): + async for ans in canvas.run(query=query, files=files, user_id=user_id, inputs=inputs): yield "data:" + json.dumps(ans, ensure_ascii=False) + "\n\n" cvs.dsl = json.loads(str(canvas))