fix pre commit hook bug
This commit is contained in:
parent
77df9772fe
commit
41308f3aca
20
app.py
20
app.py
@ -1,5 +1,7 @@
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
import threading
|
||||||
import uuid
|
import uuid
|
||||||
|
import webbrowser
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
@ -10,6 +12,7 @@ from fastapi.staticfiles import StaticFiles
|
|||||||
from fastapi.templating import Jinja2Templates
|
from fastapi.templating import Jinja2Templates
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
|
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
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)
|
task = task_manager.tasks.get(task_id)
|
||||||
if task:
|
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:
|
while True:
|
||||||
try:
|
try:
|
||||||
@ -190,7 +195,13 @@ async def task_events(task_id: str):
|
|||||||
elif event["type"] == "step":
|
elif event["type"] == "step":
|
||||||
task = task_manager.tasks.get(task_id)
|
task = task_manager.tasks.get(task_id)
|
||||||
if task:
|
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"
|
yield f"event: {event['type']}\ndata: {formatted_event}\n\n"
|
||||||
elif event["type"] in ["think", "tool", "act", "run"]:
|
elif event["type"] in ["think", "tool", "act", "run"]:
|
||||||
yield f"event: {event['type']}\ndata: {formatted_event}\n\n"
|
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__":
|
if __name__ == "__main__":
|
||||||
|
threading.Timer(3, open_local_browser).start()
|
||||||
import uvicorn
|
import uvicorn
|
||||||
|
|
||||||
uvicorn.run(app, host="localhost", port=5172)
|
uvicorn.run(app, host="localhost", port=5172)
|
Loading…
x
Reference in New Issue
Block a user