I have this python code:
@app.route('/chatstm', methods=['POST'])
async def chatstm():
if 'user_id' not in session:
return jsonify({'error': 'Unauthorized'}), 401
# Obtenha os parâmetros da requisição
message = request.json.get('message')
pdf_pc_id = request.json.get('pdf_pc_id')
pdf_id = request.json.get('pdf_id')
conversation_id = request.json.get('conversation_id')
# Construir o objeto de chat
chat = build_chatstm({
"pdf_pc_id": pdf_pc_id,
"conversation_id": conversation_id,
"pdf_id": pdf_id
})
async def generate():
# Iterar sobre os eventos assíncronos do chat
async for event in chat.astream_events(
{"input": message},
config={"configurable": {"conversation_id": conversation_id}},
version="v2"
):
if event["event"] == "on_chat_model_stream":
yield f"{repr(event['data']['chunk'].content)}"
return Response(stream_with_context(generate()), content_type='text/event-stream')
and it always returns me this error:
TypeError: ‘function’ object is not iterable
I need to stream this data, but the only function available with the characteristics I need is a async one. I’ve looked in the entire internet, tried iterate the iterator, and so on.. Nothing works
Can someone help me to fix it ?
New contributor
Eric Luque is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.