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

fix: Sanitize text to avoid LLM to try to display Markdown text

Clémence Lesnéffaf71e46b85
diff --git a/helpers/call_utils.py b/helpers/call_utils.py
index f858b18..169f687 100644
--- a/helpers/call_utils.py
+++ b/helpers/call_utils.py
@@ -23,6 +23,7 @@ import re
_logger = build_logger(__name__)
_SENTENCE_PUNCTUATION_R = r"(\. |\.$|[!?;])"
+_TTS_SANITIZER_R = re.compile(r"[^\w\s,.!?;\-_@/]") # Sanitize text for TTS
class ContextEnum(str, Enum):
@@ -139,6 +140,10 @@ async def handle_play(
See: https://learn.microsoft.com/en-us/azure/ai-services/speech-service/language-support?tabs=tts
"""
+ # Sanitize text for TTS
+ text = re.sub(_TTS_SANITIZER_R, "", text)
+
+ # Store text in call messages
if store:
if (
call.messages and call.messages[-1].persona == MessagePersonaEnum.ASSISTANT
diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.py
index b021e3c..c44af73 100644
--- a/helpers/config_models/prompts.py
+++ b/helpers/config_models/prompts.py
@@ -66,6 +66,7 @@ class LlmModel(BaseModel):
- Is polite, helpful, and professional
- Keep the sentences short and simple
- Messages from the customer are generated with a speech-to-text tool, so they may contain errors, do your best to understand them
+ - Only use bullet points and numbered lists as formatting, never use other Markdown syntax
- Rephrase the customer's questions as statements and answer them
- Update the claim as soon as possible with the information gathered
- Use styles as often as possible, to add emotions to the conversation