@@ -54,14 +54,14 @@ class InterchangeCompletionRequest(BaseModel):
5454# Create FastAPI app
5555app = FastAPI (title = "AJet Interchange Endpoint" )
5656
57+ POLL_INTERVAL_SECONDS = 0.5
5758
5859@app .get ("/health" )
5960async def health_check ():
6061 """Health check endpoint."""
6162 return {"status" : "ok" }
6263
6364
64-
6565async def coro_task_1_lookup_dict_received__send_loop (key , websocket : WebSocket , stop_event : asyncio .Event ):
6666 # Monitor for new requests
6767 try :
@@ -89,7 +89,7 @@ async def coro_task_1_lookup_dict_received__send_loop(key, websocket: WebSocket,
8989 # AgentScope sometimes fails the standard OAI schema compliance check for ChatCompletionRequest
9090 await websocket .send_bytes (pickle .dumps (new_req .model_dump_json ()))
9191 else :
92- await asyncio .sleep (0.25 )
92+ await asyncio .sleep (POLL_INTERVAL_SECONDS )
9393
9494 except WebSocketDisconnect :
9595 stop_event .set ()
@@ -258,7 +258,6 @@ async def chat_completions(request: Request, authorization: str = Header(None)):
258258
259259 # Wait for response (with periodic checks for client disconnect)
260260 max_wait_time = 1800 # 30 minutes timeout
261- check_interval = 0.25 # Check every 250ms
262261 elapsed_time = 0
263262
264263 try :
@@ -268,8 +267,8 @@ async def chat_completions(request: Request, authorization: str = Header(None)):
268267 and timeline_uuid in ajet_remote_handler_completed [key ]:
269268 openai_response = ajet_remote_handler_completed [key ][timeline_uuid ]
270269 return openai_response
271- await asyncio .sleep (check_interval )
272- elapsed_time += check_interval
270+ await asyncio .sleep (POLL_INTERVAL_SECONDS )
271+ elapsed_time += POLL_INTERVAL_SECONDS
273272
274273 # Timeout reached
275274 raise HTTPException (status_code = 504 , detail = "Request timeout" )
@@ -323,10 +322,10 @@ async def monitor_debug_state(experiment_dir):
323322 f .write (pformat (debug_info , width = 120 , indent = 2 ))
324323 f .write ('\n ' )
325324
326- await asyncio .sleep (2 )
325+ await asyncio .sleep (4 )
327326 except Exception as e :
328327 logger .error (f"Error in monitor_debug_state: { e } " )
329- await asyncio .sleep (2 )
328+ await asyncio .sleep (4 )
330329
331330
332331def ensure_dat_interchange_server_cache_clear ():
@@ -373,14 +372,18 @@ def start(self, experiment_dir) -> int:
373372 def run_server ():
374373 async def serve_with_monitor ():
375374 # Start the monitor task
376- monitor_task = asyncio .create_task (monitor_debug_state (experiment_dir ))
375+ asyncio .create_task (monitor_debug_state (experiment_dir ))
377376
378377 # Start the server
379378 config = uvicorn .Config (
380379 app = app ,
381380 host = "0.0.0.0" ,
382381 port = self .port ,
383- log_level = "error"
382+ log_level = "error" ,
383+ ws_max_queue = 1024 ,
384+ ws_ping_interval = 60 ,
385+ ws_ping_timeout = 60 ,
386+ ws_per_message_deflate = True ,
384387 )
385388 server = uvicorn .Server (config )
386389 await server .serve ()
0 commit comments