Fix: non stream for agent

This commit is contained in:
Kevin Hu 2025-11-18 16:38:22 +08:00
parent 6f0727c96e
commit aa24474442
4 changed files with 9 additions and 5 deletions

View file

@ -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())

View file

@ -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

View file

@ -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"}:

View file

@ -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))