in backend.py [0:0]
def start_chat_completion(self, messages, temperature, stop_event):
prompt = next((msg["content"] for msg in messages if msg["role"] == "user"), "")
self.model.temperature = temperature
output_queue = queue.Queue()
def run_agent():
try:
for step in self.agent.run(prompt, stream=True):
if stop_event.is_set():
output_queue.put(("CANCELED", None))
break
self._step_callback(step, output_queue)
except Exception as e:
output_queue.put(("ERROR", (str(e), traceback.format_exc())))
finally:
if not stop_event.is_set():
output_queue.put(("DONE", None))
thread = threading.Thread(target=run_agent, daemon=True)
thread.start()
return output_queue