Spaces:
Running
Running
fix: add retry/trycatch logic
Browse files- src/agent/runner.py +2 -1
- src/audio/audio_generator.py +5 -2
src/agent/runner.py
CHANGED
@@ -5,6 +5,7 @@ from dataclasses import asdict
|
|
5 |
from typing import Dict, Optional
|
6 |
import uuid
|
7 |
|
|
|
8 |
from agent.image_agent import generate_image_prompt
|
9 |
from agent.tools import generate_scene_image
|
10 |
|
@@ -36,7 +37,7 @@ async def process_step(
|
|
36 |
assert choice_text, "choice_text is required"
|
37 |
graph_state.choice_text = choice_text
|
38 |
|
39 |
-
final_state = await llm_game_graph.ainvoke(asdict(graph_state))
|
40 |
|
41 |
user_state: UserState = await get_user_state(user_hash)
|
42 |
response: Dict = {}
|
|
|
5 |
from typing import Dict, Optional
|
6 |
import uuid
|
7 |
|
8 |
+
from agent.utils import with_retries
|
9 |
from agent.image_agent import generate_image_prompt
|
10 |
from agent.tools import generate_scene_image
|
11 |
|
|
|
37 |
assert choice_text, "choice_text is required"
|
38 |
graph_state.choice_text = choice_text
|
39 |
|
40 |
+
final_state = with_retries(await llm_game_graph.ainvoke(asdict(graph_state)))
|
41 |
|
42 |
user_state: UserState = await get_user_state(user_hash)
|
43 |
response: Dict = {}
|
src/audio/audio_generator.py
CHANGED
@@ -94,8 +94,11 @@ async def cleanup_music_session(user_hash: str):
|
|
94 |
if user_hash in sessions:
|
95 |
logger.info(f"Cleaning up music session for user hash {user_hash}")
|
96 |
session = sessions[user_hash]["session"]
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
99 |
del sessions[user_hash]
|
100 |
|
101 |
|
|
|
94 |
if user_hash in sessions:
|
95 |
logger.info(f"Cleaning up music session for user hash {user_hash}")
|
96 |
session = sessions[user_hash]["session"]
|
97 |
+
try:
|
98 |
+
await asyncio.wait_for(session.stop(), settings.request_timeout)
|
99 |
+
await asyncio.wait_for(session.close(), settings.request_timeout)
|
100 |
+
except Exception as e:
|
101 |
+
logger.error(f"Error stopping music session for user hash {user_hash}: {e}")
|
102 |
del sessions[user_hash]
|
103 |
|
104 |
|