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: Enhance date management

Clémence Lesnéb77b3936bde0
diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.py
index 14a4167..0f61b01 100644
--- a/helpers/config_models/prompts.py
+++ b/helpers/config_models/prompts.py
@@ -1,4 +1,4 @@
-from datetime import datetime
+from datetime import datetime, UTC
from fastapi.encoders import jsonable_encoder
from functools import cached_property
from logging import Logger
@@ -85,7 +85,6 @@ class LlmModel(BaseSettings, env_prefix="prompts_llm_"):
- Is allowed to make assumptions, as the customer will correct them if they are wrong
- Is polite, helpful, and professional
- Keep the sentences short and simple
- - Phone numbers are always in the format E164 (e.g. +33612345678, +18449197576)
- Rephrase the customer's questions as statements and answer them
- Use additional context as a reference to answer the customer's questions related to insurance or contract details
- Use additional context to enhance the conversation with useful details
@@ -283,7 +282,9 @@ class LlmModel(BaseSettings, env_prefix="prompts_llm_"):
bot_company=CONFIG.workflow.bot_company,
bot_name=CONFIG.workflow.bot_name,
bot_phone_number=CONFIG.communication_service.phone_number,
- date=datetime.now().isoformat(),
+ date=datetime.now(UTC)
+ .astimezone()
+ .strftime("%Y-%m-%d %H:%M %Z%z"), # Example 2024-02-01 18:58 CET+0100
phone_number=phone_number,
)
)
diff --git a/main.py b/main.py
index 0c4f173..15651b8 100644
--- a/main.py
+++ b/main.py
@@ -838,7 +838,7 @@ async def llm_chat(
"type": "string",
},
"value": {
- "description": "The claim field value to update.",
+ "description": "The claim field value to update. 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).",
"type": "string",
},
f"{customer_response_prop}": {
@@ -1007,7 +1007,6 @@ async def llm_chat(
full_content += local_content + " "
await user_callback(local_content)
- content = None
if not parameters["field"] in ClaimModel.editable_fields():
content = f'Failed to update a non-editable field "{parameters['field']}".'
else:
@@ -1016,10 +1015,9 @@ async def llm_chat(
copy = call.claim.model_dump()
copy[parameters["field"]] = parameters["value"]
call.claim = ClaimModel.model_validate(copy)
- except ValidationError as e:
+ content = f'Updated claim field "{parameters['field']}" with value "{parameters['value']}".'
+ except ValidationError as e: # Catch error to inform LLM
content = f'Failed to edit field "{parameters["field"]}": {e.json()}'
- if not content:
- content = f'Updated claim field "{parameters['field']}" with value "{parameters['value']}".'
model.content = content
elif name == IndentAction.NEW_CLAIM.value:
@@ -1074,25 +1072,30 @@ async def llm_chat(
updated = False
for reminder in call.reminders:
if reminder.title == parameters["title"]:
- reminder.description = parameters["description"]
- reminder.due_date_time = parameters["due_date_time"]
- reminder.owner = parameters["owner"]
- model.content = (
- f'Reminder "{parameters['title']}" updated.'
- )
+ try:
+ reminder.description = parameters["description"]
+ reminder.due_date_time = parameters["due_date_time"]
+ reminder.owner = parameters["owner"]
+ content = f'Reminder "{parameters['title']}" updated.'
+ except ValidationError as e: # Catch error to inform LLM
+ content = f'Failed to edit reminder "{parameters["title"]}": {e.json()}'
+ model.content = content
updated = True
break
if not updated:
- call.reminders.append(
- ReminderModel(
+ try:
+ reminder = ReminderModel(
description=parameters["description"],
due_date_time=parameters["due_date_time"],
title=parameters["title"],
owner=parameters["owner"],
)
- )
- model.content = f'Reminder "{parameters['title']}" created.'
+ call.reminders.append(reminder)
+ content = f'Reminder "{parameters['title']}" created.'
+ except ValidationError as e: # Catch error to inform LLM
+ content = f'Failed to create reminder "{parameters["title"]}": {e.json()}'
+ model.content = content
models.append(model)
diff --git a/models/claim.py b/models/claim.py
index 2f8b36d..a415e06 100644
--- a/models/claim.py
+++ b/models/claim.py
@@ -26,7 +26,7 @@ class ClaimModel(BaseModel):
created_at: datetime = Field(default_factory=datetime.utcnow, frozen=True)
# Editable fields
extra_details: Optional[str] = None
- incident_date_time: Optional[str] = None
+ incident_date_time: Optional[datetime] = None
incident_description: Optional[str] = None
incident_location: Optional[str] = None
injuries_description: Optional[str] = None
diff --git a/models/reminder.py b/models/reminder.py
index 658def9..ec81111 100644
--- a/models/reminder.py
+++ b/models/reminder.py
@@ -8,6 +8,6 @@ class ReminderModel(BaseModel):
created_at: datetime = Field(default_factory=datetime.utcnow, frozen=True)
# Editable fields
description: str
- due_date_time: str
+ due_date_time: datetime
owner: Optional[str] = None # Optional for backwards compatibility
title: str
diff --git a/public_website/history.html.jinja b/public_website/history.html.jinja
index 2033021..f70f556 100644
--- a/public_website/history.html.jinja
+++ b/public_website/history.html.jinja
@@ -11,7 +11,7 @@ Historique des appels pour {{ phone_number }}
<h2 class="text-lg">📞 Historique des appels pour {{ phone_number }}</h2>
{% for call in calls %}
<div>
- <a class="hover:underline" href="/report/{{ call.phone_number | quote_plus }}/{{ call.call_id | quote_plus }}"><span class="font-mono">#{{ call.claim.claim_id }}</span> ({{ call.created_at.strftime('%d %b %Y %H:%M') }})</a>
+ <a class="hover:underline" href="/report/{{ call.phone_number | quote_plus }}/{{ call.call_id | quote_plus }}"><span class="font-mono">#{{ call.claim.claim_id }}</span> ({{ call.created_at.strftime('%d %b %Y, %H:%M') }})</a>
</div>
{% else %}
<p class="text-neutral-600 dark:text-neutral-400">Aucun appel pour l'instant.</p>
diff --git a/public_website/report.html.jinja b/public_website/report.html.jinja
index 72488bc..79992bc 100644
--- a/public_website/report.html.jinja
+++ b/public_website/report.html.jinja
@@ -74,7 +74,7 @@ Déclaration de sinistre {{ call.claim.claim_id }}
</span>
</div>
<div class="text-neutral-600 dark:text-neutral-400">
- {{ message.created_at.strftime('%d %b %Y %H:%M') }}
+ {{ message.created_at.strftime('%d %b %Y, %H:%M') }}
</div>
</div>
{% if message.content %}
@@ -103,7 +103,7 @@ Déclaration de sinistre {{ call.claim.claim_id }}
{% for reminder in call.reminders | sort(attribute='due_date_time') %}
<div>
<div class="text-xs">
- {{ reminder.owner | title }}&nbsp;<span class="text-neutral-600 dark:text-neutral-400">({{ reminder.due_date_time }})</span>
+ {{ reminder.owner | title }}&nbsp;<span class="text-neutral-600 dark:text-neutral-400">({{ reminder.due_date_time.strftime('%d %b %Y, %H:%M') }})</span>
</div>
<p class="text-neutral-600 dark:text-neutral-400">{{ reminder.title | capitalize }}</p>
</div>
@@ -147,23 +147,23 @@ Déclaration de sinistre {{ call.claim.claim_id }}
set details = [
{
'title': 'Date',
- 'value': call.claim.incident_date_time
+ 'value': call.claim.incident_date_time.strftime('%d %b %Y, %H:%M') if call.claim.incident_date_time else 'N/A'
},
{
'title': 'Localisation',
- 'value': call.claim.incident_location
+ 'value': call.claim.incident_location or 'N/A'
},
{
'title': 'Police',
- 'value': call.claim.policy_number
+ 'value': call.claim.policy_number or 'N/A'
},
{
'title': 'Contact',
- 'value': call.claim.policyholder_email | lower ~ ', ' ~ call.claim.policyholder_phone
+ 'value': ((call.claim.policyholder_email | lower) or 'N/A') ~ ', ' ~ (call.claim.policyholder_phone or 'N/A')
},
{
'title': 'Téléphone utilisé',
- 'value': call.phone_number
+ 'value': call.phone_number or 'N/A'
}
]
%}