Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

ux: Don't play first loading sound and make first answer quicker

Clémence Lesné2be8e374fd24
diff --git a/helpers/call_llm.py b/helpers/call_llm.py
index 6a8416a..6699282 100644
--- a/helpers/call_llm.py
+++ b/helpers/call_llm.py
@@ -54,15 +54,24 @@ async def load_llm_chat( # noqa: PLR0912, PLR0915
"""
logger.info("Loading LLM chat")
- should_play_sound = True
+ play_loading_sound = True
async def _tts_callback(text: str, style: MessageStyleEnum) -> None:
"""
Send back the TTS to the user.
"""
- nonlocal should_play_sound
+ nonlocal play_loading_sound
+
+ # Disable loading sound when LLM starts to speak
+ if play_loading_sound:
+ # First, clear remaining loading sound
+ await handle_clear_queue(
+ call=call,
+ client=client,
+ )
+ # Then, disable loading sound
+ play_loading_sound = False
- should_play_sound = False
await asyncio.gather(
handle_recognize_text(
call=call,
@@ -111,12 +120,6 @@ async def load_llm_chat( # noqa: PLR0912, PLR0915
asyncio.sleep(await answer_hard_timeout_sec())
)
- await handle_media(
- call=call,
- client=client,
- sound_url=CONFIG.prompts.sounds.loading(),
- ) # Play loading sound a first time
-
def _clear_tasks() -> None:
chat_task.cancel()
hard_timeout_task.cancel()
@@ -161,13 +164,13 @@ async def load_llm_chat( # noqa: PLR0912, PLR0915
_clear_tasks()
break
- if should_play_sound: # Catch timeout if async loading is not started
+ if play_loading_sound: # Catch timeout if async loading is not started
if (
soft_timeout_task.done() and not soft_timeout_triggered
): # Speak when soft timeout is reached
logger.warning(
"Soft timeout of %ss reached",
- CONFIG.conversation.answer_soft_timeout_sec,
+ await answer_soft_timeout_sec(),
)
soft_timeout_triggered = True
# Never store the error message in the call history, it has caused hallucinations in the LLM