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: Fine-tune LLM prompts

Clémence Lesné055d7d4201a9
diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.py
index 39f89e8..2c18e2e 100644
--- a/helpers/config_models/prompts.py
+++ b/helpers/config_models/prompts.py
@@ -103,7 +103,7 @@ class LlmModel(BaseModel):
{reminders}
# Response format
- style=[style] [content]
+ style=[style] content
## Example 1
Call objective: Help the customer with their accident. Customer will be calling from a car, with the SOS button.
@@ -260,7 +260,7 @@ class LlmModel(BaseModel):
{reminders}
# Response format
- [source text]\\n
+ text\\n
*[extract from text]: "citation from claim, reminders, or messages"
## Example 1
@@ -281,7 +281,7 @@ class LlmModel(BaseModel):
"""
next_system_tpl: str = """
# Objective
- Choose the next action from the company sales team perspective. The Answer is a JSON object with the action to take and the justification for this action.
+ Choose the next action from the company sales team perspective. The answer is the action to take and the justification for this action.
# Rules
- Answers in English, even if the customer speaks another language
@@ -305,7 +305,7 @@ class LlmModel(BaseModel):
# Conversation history
{messages}
- # Response format
+ # Response format in JSON
{{
"action": "[action]",
"justification": "[justification]"
diff --git a/helpers/llm_tools.py b/helpers/llm_tools.py
index 609ec0a..2cd6376 100644
--- a/helpers/llm_tools.py
+++ b/helpers/llm_tools.py
@@ -61,9 +61,9 @@ class LlmPlugins:
- Requires an explicit verbal validation from the customer
- Never use this action directly after a recall
- # Examples
- - 'Goodbye, see you tomorrow'
- - 'I want to hangup'
+ # Usage examples
+ - All participants are satisfied and agree to end the call
+ - Customer said 'bye bye'
"""
await handle_recognize_text(
call=self.call,
@@ -102,6 +102,10 @@ class LlmPlugins:
# Rules
- Approval from the customer must be explicitely given (e.g. 'I want to create a new claim')
- This should be used only when the subject is totally different
+
+ # Usage examples
+ - Customer wants explicitely to create a new claim
+ - Talking about a totally different subject
"""
await self.tts_callback(customer_response, self.style)
# Launch post-call intelligence for the current call
@@ -168,6 +172,11 @@ class LlmPlugins:
- A reminder should be as specific as possible
- If a reminder already exists, it will be updated with the new values
- The due date should be in the future
+
+ # Usage examples
+ - Ask precisions to an expert or the backoffice
+ - Call back for a follow-up
+ - Wait for customer to send a document
"""
await self.tts_callback(customer_response, self.style)
@@ -230,7 +239,7 @@ class LlmPlugins:
- For dates, use YYYY-MM-DD HH:MM format (e.g. 2024-02-01 18:58)
- For phone numbers, use E164 format (e.g. +33612345678)
- # Response format
+ # Data format
[{'field': '[field]', 'value': '[value]'}]
# Examples
@@ -249,6 +258,12 @@ class LlmPlugins:
# Rules
- For values, it is OK to approximate dates if the customer is not precise (e.g., "last night" -> today 04h, "I'm stuck on the highway" -> now)
- It is best to update multiple fields at once
+
+ # Usage examples
+ - Change the incident date
+ - Correct the name of the customer
+ - Store details about the conversation
+ - Update the claim with a new phone number
"""
await self.tts_callback(customer_response, self.style)
# Update all claim fields
@@ -281,9 +296,10 @@ class LlmPlugins:
- Requires an explicit verbal validation from the customer
- Never use this action directly after a recall
- # Examples
- - 'I want to talk to a human'
- - 'I want to talk to a real person'
+ # Usage examples
+ - Customer wants to talk to a human
+ - No more information available and customer insists
+ - Not satisfied with the answers
"""
await handle_recognize_text(
call=self.call,
@@ -325,6 +341,11 @@ class LlmPlugins:
# Searchable topics
contract, law, regulation, article, procedure, guide
+
+ # Usage examples
+ - Find the article about the new law
+ - Know the procedure to declare a stolen luxury watch
+ - Understand the requirements to ask for a cyber attack insurance
"""
await self.tts_callback(customer_response, self.style)
# Execute in parallel
@@ -393,10 +414,10 @@ class LlmPlugins:
# Rules
- Use it only if the situation is critical and requires immediate intervention
- # Examples
- - 'A child is lying on the ground and is not moving'
- - 'I am stuck in a car in fire'
- - 'My neighbor is having a heart attack'
+ # Usage examples
+ - A child is lying on the ground and is not moving
+ - A neighbor is having a heart attack
+ - Someons is stuck in a car accident
"""
await self.tts_callback(customer_response, self.style)
# TODO: Implement notification to emergency services for production usage
@@ -481,9 +502,11 @@ class LlmPlugins:
2. Return a confirmation message
# Usage examples
- - Customer has trouble understanding the voice
- - Customer wants to speed up or slow down the voice
+ - Speed up or slow down the voice
+ - Trouble understanding the voice because it is too fast or too slow
"""
+ # Clamp speed between min and max
+ speed = max(0.75, min(speed, 1.25))
# Update voice
initial_speed = self.call.initiate.prosody_rate
self.call.initiate.prosody_rate = speed
diff --git a/tests/llm.py b/tests/llm.py
index 6fc4c26..86d0305 100644
--- a/tests/llm.py
+++ b/tests/llm.py
@@ -98,7 +98,7 @@ class ClaimRelevancyMetric(BaseMetric):
Real: {real or "N/A"}
# Response format
- [score, a float between 0.0 and 1.0]
+ score, float between 0.0 and 1.0
## Example 1
Name: age
diff --git a/tests/search.py b/tests/search.py
index ef9fc06..f737456 100644
--- a/tests/search.py
+++ b/tests/search.py
@@ -75,7 +75,7 @@ class RagRelevancyMetric(BaseMetric):
{document}
# Response format
- [score, a float between 0.0 and 1.0]
+ score, float between 0.0 and 1.0
## Example 1
Message: I love bananas