feat(voice): rotate NPC hint variants per turn
This commit was merged in pull request #169.
This commit is contained in:
@@ -203,11 +203,14 @@ def load_scenario_hints(scenario: str = "zacus_v3"):
|
|||||||
STEP_SCENE, SCENE_HINTS, INITIAL_STEP = load_scenario_hints(settings.scenario)
|
STEP_SCENE, SCENE_HINTS, INITIAL_STEP = load_scenario_hints(settings.scenario)
|
||||||
|
|
||||||
|
|
||||||
def _scenario_hint(step_id: str, level: int) -> str:
|
def _scenario_hint(step_id: str, level: int, turn: int = 0) -> str:
|
||||||
"""A hint string for the current step at `level` (1 subtle … 3 near-explicit)."""
|
"""A hint string for the current step at `level` (1 subtle … 3 near-explicit).
|
||||||
|
|
||||||
|
Rotates by `turn` through the level's variants so a multi-turn call doesn't
|
||||||
|
repeat the same phrasing."""
|
||||||
scene = STEP_SCENE.get(step_id or "", "")
|
scene = STEP_SCENE.get(step_id or "", "")
|
||||||
pool = SCENE_HINTS.get(scene, {}).get(max(1, min(3, level)), [])
|
pool = SCENE_HINTS.get(scene, {}).get(max(1, min(3, level)), [])
|
||||||
return pool[0] if pool else ""
|
return pool[turn % len(pool)] if pool else ""
|
||||||
|
|
||||||
|
|
||||||
# NOTE: in-process dict — single uvicorn worker only; multi-worker would need shared store (Redis).
|
# NOTE: in-process dict — single uvicorn worker only; multi-worker would need shared store (Redis).
|
||||||
@@ -2202,7 +2205,7 @@ async def voice_reply(
|
|||||||
step = getattr(request.app.state, "current_step", INITIAL_STEP)
|
step = getattr(request.app.state, "current_step", INITIAL_STEP)
|
||||||
user_turns = sum(1 for m in history if m.get("role") == "user")
|
user_turns = sum(1 for m in history if m.get("role") == "user")
|
||||||
level = max(1, min(3, 1 + (user_turns - 1) // 2))
|
level = max(1, min(3, 1 + (user_turns - 1) // 2))
|
||||||
hint = _scenario_hint(step, level)
|
hint = _scenario_hint(step, level, turn=user_turns)
|
||||||
sys_persona = persona
|
sys_persona = persona
|
||||||
if hint:
|
if hint:
|
||||||
sys_persona = (persona + f"\n\nÉNIGME EN COURS (étape {step}, indice niveau "
|
sys_persona = (persona + f"\n\nÉNIGME EN COURS (étape {step}, indice niveau "
|
||||||
|
|||||||
Reference in New Issue
Block a user