Идея заключается в следующем:
Код: Выделить всё
message_route = Blueprint('message_route', __name__, template_folder='templates')
@message_route.route('/message//', methods=['POST'])
async def message(key, chat_uuid):
# [...] Other endpoint logic not helpful in resolving the issue
async def event_stream():
agent_handler = agent.run(input=content['message'])
# stream_events() return an AsyncGenerator[Event, None], so async is necessary
async for ev in agent_handler.stream_events():
if isinstance(ev, MessageOutputEvent):
print(ev.message)
yield ev.message
# wait for the process to finish before continuing
response = await agent_handler
print(response)
resp = make_response(event_stream())
resp.mimetype = "text/event-stream"
resp.set_cookie(key='user_uuid', samesite="none", value="user_123")
return resp, 200
Код: Выделить всё
TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a coroutine.
Подробнее здесь: https://stackoverflow.com/questions/791 ... cgenerator