From 41308f3acac33b4315325f165b1e0b5221e99cd0 Mon Sep 17 00:00:00 2001 From: rxdaozhang <896836861@qq.com> Date: Tue, 11 Mar 2025 02:18:40 +0800 Subject: [PATCH] fix pre commit hook bug --- app.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/app.py b/app.py index 5adb62e..cebca55 100644 --- a/app.py +++ b/app.py @@ -1,5 +1,7 @@ import asyncio +import threading import uuid +import webbrowser from datetime import datetime from json import dumps @@ -10,6 +12,7 @@ from fastapi.staticfiles import StaticFiles from fastapi.templating import Jinja2Templates from pydantic import BaseModel + app = FastAPI() app.mount("/static", StaticFiles(directory="static"), name="static") @@ -172,7 +175,9 @@ async def task_events(task_id: str): task = task_manager.tasks.get(task_id) if task: - yield f"event: status\ndata: {dumps({'type': 'status','status': task.status,'steps': task.steps})}\n\n" + message = {"type": "status", "status": task.status, "steps": task.steps} + json_message = dumps(message) + yield f"event: status\ndata: {json_message}\n\n" while True: try: @@ -190,7 +195,13 @@ async def task_events(task_id: str): elif event["type"] == "step": task = task_manager.tasks.get(task_id) if task: - yield f"event: status\ndata: {dumps({ 'type': 'status','status': task.status,'steps': task.steps })}\n\n" + message = { + "type": "status", + "status": task.status, + "steps": task.steps, + } + json_message = dumps(message) + yield f"event: status\ndata: {json_message}\n\n" yield f"event: {event['type']}\ndata: {formatted_event}\n\n" elif event["type"] in ["think", "tool", "act", "run"]: yield f"event: {event['type']}\ndata: {formatted_event}\n\n" @@ -241,7 +252,12 @@ async def generic_exception_handler(request: Request, exc: Exception): ) +def open_local_browser(): + webbrowser.open_new_tab("http://localhost:5172") + + if __name__ == "__main__": + threading.Timer(3, open_local_browser).start() import uvicorn - uvicorn.run(app, host="localhost", port=5172) + uvicorn.run(app, host="localhost", port=5172) \ No newline at end of file