File tree Expand file tree Collapse file tree 2 files changed +12
-0
lines changed
Expand file tree Collapse file tree 2 files changed +12
-0
lines changed Original file line number Diff line number Diff line change @@ -47,6 +47,8 @@ async def _post_with_retry(path: str, payload: dict) -> None:
4747
4848
4949async def register_with_router () -> None :
50+ """Register this agent with the router service."""
51+
5052 payload = {
5153 "name" : AGENT_NAME ,
5254 "endpoint" : AGENT_ENDPOINT ,
@@ -56,19 +58,25 @@ async def register_with_router() -> None:
5658
5759
5860async def heartbeat_loop () -> None :
61+ """Send regular heartbeat messages to the router."""
62+
5963 while True :
6064 await _post_with_retry ("/heartbeat" , {"name" : AGENT_NAME })
6165 await asyncio .sleep (HEARTBEAT_INTERVAL )
6266
6367
6468@app .on_event ("startup" )
6569async def _startup () -> None :
70+ """Start background registration and heartbeat tasks."""
71+
6672 asyncio .create_task (register_with_router ())
6773 asyncio .create_task (heartbeat_loop ())
6874
6975
7076@app .post ("/infer" )
7177async def infer (payload : ChatCompletionRequest ):
78+ """Return a trivial echo response for the given request."""
79+
7280 user_msg = payload .messages [- 1 ].content if payload .messages else ""
7381 content = f"Echo: { user_msg } "
7482 response = {
Original file line number Diff line number Diff line change 108108
109109
110110async def cache_get (key : str ) -> str | None :
111+ """Return cached value if present and not expired."""
112+
111113 entry = CACHE_STORE .get (key )
112114 if entry is None :
113115 return None
@@ -119,6 +121,8 @@ async def cache_get(key: str) -> str | None:
119121
120122
121123async def cache_set (key : str , value : str , ttl : int = CACHE_TTL ) -> None :
124+ """Store a value in the cache for ``ttl`` seconds."""
125+
122126 CACHE_STORE [key ] = (time .time () + ttl , value )
123127
124128
You can’t perform that action at this time.
0 commit comments