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.pyindex 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, UTCfrom fastapi.encoders import jsonable_encoderfrom functools import cached_propertyfrom 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+0100phone_number=phone_number,))diff --git a/main.py b/main.pyindex 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 = Noneif 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 LLMcontent = 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 = contentelif name == IndentAction.NEW_CLAIM.value:@@ -1074,25 +1072,30 @@ async def llm_chat(updated = Falsefor 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 = contentupdated = Truebreakif 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 = contentmodels.append(model)diff --git a/models/claim.py b/models/claim.pyindex 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 fieldsextra_details: Optional[str] = None- incident_date_time: Optional[str] = None+ incident_date_time: Optional[datetime] = Noneincident_description: Optional[str] = Noneincident_location: Optional[str] = Noneinjuries_description: Optional[str] = Nonediff --git a/models/reminder.py b/models/reminder.pyindex 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 fieldsdescription: str- due_date_time: str+ due_date_time: datetimeowner: Optional[str] = None # Optional for backwards compatibilitytitle: strdiff --git a/public_website/history.html.jinja b/public_website/history.html.jinjaindex 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.jinjaindex 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 }} <span class="text-neutral-600 dark:text-neutral-400">({{ reminder.due_date_time }})</span>+ {{ reminder.owner | title }} <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'}]%}