1
1
import asyncio
2
+ import threading
2
3
import uuid
4
+ import webbrowser
3
5
from datetime import datetime
4
6
from json import dumps
5
7
10
12
from fastapi .templating import Jinja2Templates
11
13
from pydantic import BaseModel
12
14
15
+
13
16
app = FastAPI ()
14
17
15
18
app .mount ("/static" , StaticFiles (directory = "static" ), name = "static" )
@@ -172,7 +175,9 @@ async def event_generator():
172
175
173
176
task = task_manager .tasks .get (task_id )
174
177
if task :
175
- yield f"event: status\n data: { dumps ({'type' : 'status' ,'status' : task .status ,'steps' : task .steps })} \n \n "
178
+ message = {"type" : "status" , "status" : task .status , "steps" : task .steps }
179
+ json_message = dumps (message )
180
+ yield f"event: status\n data: { json_message } \n \n "
176
181
177
182
while True :
178
183
try :
@@ -190,7 +195,13 @@ async def event_generator():
190
195
elif event ["type" ] == "step" :
191
196
task = task_manager .tasks .get (task_id )
192
197
if task :
193
- yield f"event: status\n data: { dumps ({ 'type' : 'status' ,'status' : task .status ,'steps' : task .steps })} \n \n "
198
+ message = {
199
+ "type" : "status" ,
200
+ "status" : task .status ,
201
+ "steps" : task .steps ,
202
+ }
203
+ json_message = dumps (message )
204
+ yield f"event: status\n data: { json_message } \n \n "
194
205
yield f"event: { event ['type' ]} \n data: { formatted_event } \n \n "
195
206
elif event ["type" ] in ["think" , "tool" , "act" , "run" ]:
196
207
yield f"event: { event ['type' ]} \n data: { formatted_event } \n \n "
@@ -241,7 +252,12 @@ async def generic_exception_handler(request: Request, exc: Exception):
241
252
)
242
253
243
254
255
+ def open_local_browser ():
256
+ webbrowser .open_new_tab ("http://localhost:5172" )
257
+
258
+
244
259
if __name__ == "__main__" :
260
+ threading .Timer (3 , open_local_browser ).start ()
245
261
import uvicorn
246
262
247
- uvicorn .run (app , host = "localhost" , port = 5172 )
263
+ uvicorn .run (app , host = "localhost" , port = 5172 )
0 commit comments