Skip to content

Commit 6de46ab

Browse files
committed
breaking: Static prompts are stored as list
Conversations are now less boring with a simple trick.
1 parent 053aa5d commit 6de46ab

File tree

2 files changed

+71
-32
lines changed

2 files changed

+71
-32
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -681,24 +681,25 @@ sms:
681681

682682
### Customize the prompts
683683

684-
Note that prompt examples contains `{xxx}` placeholders. These placeholders are replaced by the bot with the corresponding data. For example, `{bot_name}` is internally replaced by the bot name.
685-
686-
Be sure to write all the TTS prompts in English. This language is used as a pivot language for the conversation translation.
684+
Note that prompt examples contains `{xxx}` placeholders. These placeholders are replaced by the bot with the corresponding data. For example, `{bot_name}` is internally replaced by the bot name. Be sure to write all the TTS prompts in English. This language is used as a pivot language for the conversation translation. All texts are referenced as lists, so user can have a different experience each time they call, thus making the conversation more engaging.
687685

688686
```yaml
689687
# config.yaml
690688
prompts:
691689
tts:
692-
hello_tpl: |
693-
Hello, I'm {bot_name}, from {bot_company}! I'm an IT support specialist.
690+
hello_tpl:
691+
- : |
692+
Hello, I'm {bot_name}, from {bot_company}! I'm an IT support specialist.
693+
694+
Here's how I work: when I'm working, you'll hear a little music; then, at the beep, it's your turn to speak. You can speak to me naturally, I'll understand.
694695
695-
Here's how I work: when I'm working, you'll hear a little music; then, at the beep, it's your turn to speak. You can speak to me naturally, I'll understand.
696+
What's your problem?
697+
- : |
698+
Hi, I'm {bot_name} from {bot_company}. I'm here to help.
696699
697-
Examples:
698-
- "I've got a problem with my computer, it won't turn on".
699-
- "The external screen is flashing, I don't know why".
700+
You'll hear music, then a beep. Speak naturally, I'll understand.
700701
701-
What's your problem?
702+
What's the issue?
702703
llm:
703704
default_system_tpl: |
704705
Assistant is called {bot_name} and is in a call center for the company {bot_company} as an expert with 20 years of experience in IT service.

app/helpers/config_models/prompts.py

Lines changed: 60 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import random
23
from datetime import datetime
34
from functools import cached_property
45
from html import escape
@@ -492,24 +493,56 @@ def logger(self) -> Logger:
492493

493494
class TtsModel(BaseModel):
494495
tts_lang: str = "en-US"
495-
calltransfer_failure_tpl: str = "It seems I can't connect you with an agent at the moment, but the next available agent will call you back as soon as possible."
496-
connect_agent_tpl: str = "I'm sorry, I wasn't able to respond your request. Please allow me to transfer you to an agent who can assist you further. Please stay on the line and I will get back to you shortly."
497-
end_call_to_connect_agent_tpl: str = (
498-
"Of course, stay on the line. I will transfer you to an agent."
499-
)
500-
error_tpl: str = (
501-
"I'm sorry, I have encountered an error. Could you repeat your request?"
502-
)
503-
goodbye_tpl: str = "Thank you for calling, I hope I've been able to help. You can call back, I've got it all memorized. {bot_company} wishes you a wonderful day!"
504-
hello_tpl: str = """
505-
Hello, I'm {bot_name}, the virtual assistant {bot_company}! Here's how I work: while I'm processing your information, wou will hear a music. Feel free to speak to me in a natural way - I'm designed to understand your requests. During the conversation, you can also send me text messages.
506-
"""
507-
timeout_silence_tpl: str = "I'm sorry, I didn't hear anything. If you need help, let me know how I can help you."
508-
welcome_back_tpl: str = "Hello, I'm {bot_name}, from {bot_company}!"
509-
timeout_loading_tpl: str = (
510-
"It's taking me longer than expected to reply. Thank you for your patience…"
511-
)
512-
ivr_language_tpl: str = "To continue in {label}, press {index}."
496+
calltransfer_failure_tpl: list[str] = [
497+
"It seems I can't connect you with an agent at the moment, but the next available agent will call you back as soon as possible.",
498+
"I'm unable to connect you with an agent right now, but someone will get back to you shortly.",
499+
"Sorry, no agents are available. We'll call you back soon.",
500+
]
501+
connect_agent_tpl: list[str] = [
502+
"I'm sorry, I wasn't able to respond to your request. Please allow me to transfer you to an agent who can assist you further. Please stay on the line and I will get back to you shortly.",
503+
"I apologize for not being able to assist you. Let me connect you to an agent who can help. Please hold on.",
504+
"Sorry for the inconvenience. I'll transfer you to an agent now. Please hold.",
505+
]
506+
end_call_to_connect_agent_tpl: list[str] = [
507+
"Of course, stay on the line. I will transfer you to an agent.",
508+
"Sure, please hold on. I'll connect you to an agent.",
509+
"Hold on, I'll transfer you now.",
510+
]
511+
error_tpl: list[str] = [
512+
"I'm sorry, I didn't understand. Can you rephrase?",
513+
"I didn't catch that. Could you say it differently?",
514+
"Please repeat that.",
515+
]
516+
goodbye_tpl: list[str] = [
517+
"Thank you for calling, I hope I've been able to help. You can call back, I've got it all memorized. {bot_company} wishes you a wonderful day!",
518+
"It was a pleasure assisting you today. Remember, {bot_company} is always here to help. Have a fantastic day!",
519+
"Thanks for reaching out! {bot_company} appreciates you. Have a great day!",
520+
]
521+
hello_tpl: list[str] = [
522+
"Hello, I'm {bot_name}, the virtual assistant from {bot_company}! Here's how I work: while I'm processing your information, you will hear music. Feel free to speak to me in a natural way - I'm designed to understand your requests. During the conversation, you can also send me text messages.",
523+
"Hi there! I'm {bot_name} from {bot_company}. While I process your info, you'll hear some music. Just talk to me naturally, and you can also send text messages.",
524+
"Hello! I'm {bot_name} from {bot_company}. Speak naturally, and you can also text me.",
525+
]
526+
timeout_silence_tpl: list[str] = [
527+
"I'm sorry, I didn't hear anything. If you need help, let me know how I can help you.",
528+
"It seems quiet on your end. How can I assist you?",
529+
"I didn't catch that. How can I help?",
530+
]
531+
welcome_back_tpl: list[str] = [
532+
"Hello, I'm {bot_name}, from {bot_company}!",
533+
"Hi there, {bot_name} from {bot_company} here!",
534+
"Hey, it's {bot_name} from {bot_company}!",
535+
]
536+
timeout_loading_tpl: list[str] = [
537+
"It's taking me longer than expected to reply. Thank you for your patience…",
538+
"I'm working on your request. Thanks for waiting!",
539+
"Please hold on, I'm almost done.",
540+
]
541+
ivr_language_tpl: list[str] = [
542+
"To continue in {label}, press {index}.",
543+
"Press {index} for {label}.",
544+
"For {label}, press {index}.",
545+
]
513546

514547
async def calltransfer_failure(self, call: CallStateModel) -> str:
515548
return await self._translate(self.calltransfer_failure_tpl, call)
@@ -566,15 +599,20 @@ async def ivr_language(self, call: CallStateModel) -> str:
566599
)
567600
+ " "
568601
)
569-
return await self._translate(res.strip(), call)
602+
return await self._translate([res], call)
570603

571-
def _return(self, prompt_tpl: str, **kwargs) -> str:
604+
def _return(self, prompt_tpls: list[str], **kwargs) -> str:
572605
"""
573606
Remove possible indentation in a string.
574607
"""
608+
# Select a random prompt template
609+
prompt_tpl = random.choice(prompt_tpls)
610+
# Format it
575611
return dedent(prompt_tpl.format(**kwargs)).strip()
576612

577-
async def _translate(self, prompt_tpl: str, call: CallStateModel, **kwargs) -> str:
613+
async def _translate(
614+
self, prompt_tpls: list[str], call: CallStateModel, **kwargs
615+
) -> str:
578616
"""
579617
Format the prompt and translate it to the TTS language.
580618
@@ -584,7 +622,7 @@ async def _translate(self, prompt_tpl: str, call: CallStateModel, **kwargs) -> s
584622
translate_text,
585623
)
586624

587-
initial = self._return(prompt_tpl, **kwargs)
625+
initial = self._return(prompt_tpls, **kwargs)
588626
translation = None
589627
try:
590628
translation = await translate_text(

0 commit comments

Comments
 (0)