Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Class naming
Clémence Lesnéb1e7435b2275
diff --git a/helpers/config_models/database.py b/helpers/config_models/database.pyindex bc222df..0217f45 100644--- a/helpers/config_models/database.py+++ b/helpers/config_models/database.py@@ -4,7 +4,7 @@ from pydantic_settings import BaseSettingsfrom typing import Optional-class Mode(str, Enum):+class ModeEnum(str, Enum):COSMOS_DB = "cosmos_db"SQLITE = "sqlite"@@ -32,17 +32,17 @@ class SqliteModel(BaseSettings):class DatabaseModel(BaseSettings):cosmos_db: Optional[CosmosDbModel] = None- mode: Mode = Mode.SQLITE+ mode: ModeEnum = ModeEnum.SQLITEsqlite: Optional[SqliteModel] = None@validator("cosmos_db", always=True)def check_cosmos_db(cls, v, values, **kwargs):- if not v and values.get("mode", None) == Mode.COSMOS_DB:+ if not v and values.get("mode", None) == ModeEnum.COSMOS_DB:raise ValueError("Cosmos DB config required")return v@validator("sqlite", always=True)def check_sqlite(cls, v, values, **kwargs):- if not v and values.get("mode", None) == Mode.SQLITE:+ if not v and values.get("mode", None) == ModeEnum.SQLITE:raise ValueError("Sqlite config required")return vdiff --git a/helpers/config_models/monitoring.py b/helpers/config_models/monitoring.pyindex 27eb1fe..e2dcb84 100644--- a/helpers/config_models/monitoring.py+++ b/helpers/config_models/monitoring.py@@ -2,7 +2,7 @@ from enum import Enumfrom pydantic_settings import BaseSettings-class LoggingLevel(str, Enum):+class LoggingLevelEnum(str, Enum):# Copied from https://docs.python.org/3.12/library/logging.html#logging-levelsCRITICAL = "CRITICAL"DEBUG = "DEBUG"@@ -13,8 +13,8 @@ class LoggingLevel(str, Enum):class LoggingMonitoringModel(BaseSettings):- app_level: LoggingLevel = LoggingLevel.INFO- sys_level: LoggingLevel = LoggingLevel.WARNING+ app_level: LoggingLevelEnum = LoggingLevelEnum.INFO+ sys_level: LoggingLevelEnum = LoggingLevelEnum.WARNINGclass MonitoringModel(BaseSettings):diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.pyindex 3d38f8d..484f509 100644--- a/helpers/config_models/prompts.py+++ b/helpers/config_models/prompts.py@@ -4,12 +4,13 @@ from functools import cached_propertyfrom logging import Loggerfrom models.claim import ClaimModelfrom models.message import (- Action as MessageAction,+ ActionEnum as MessageAction,MessageModel,- Persona as MessagePersona,- Style as MessageStyle,+ PersonaEnum as MessagePersona,+ StyleEnum as MessageStyle,)from models.next import Action as NextAction+from models.next import ActionEnum as NextActionfrom models.reminder import ReminderModelfrom models.training import TrainingModelfrom pydantic import computed_field, BaseModeldiff --git a/main.py b/main.pyindex bcccca6..d1199f3 100644--- a/main.py+++ b/main.py@@ -27,11 +27,11 @@ from azure.identity import DefaultAzureCredentialfrom enum import Enumfrom fastapi import FastAPI, status, Request, HTTPException, BackgroundTasksfrom fastapi.responses import JSONResponse, HTMLResponse-from helpers.config_models.database import Mode as DatabaseMode+from helpers.config_models.database import ModeEnum as DatabaseModefrom jinja2 import Environment, FileSystemLoader, select_autoescape-from models.action import ActionModel, Indent as IndentAction+from models.action import ActionModel, IndentEnum as IndentActionfrom models.call import CallModel-from models.next import Action as NextAction+from models.next import ActionEnum as NextActionfrom models.next import NextModelfrom models.reminder import ReminderModelfrom models.synthesis import SynthesisModel@@ -53,10 +53,10 @@ import asyncioimport htmlimport refrom models.message import (- Action as MessageAction,+ ActionEnum as MessageAction,MessageModel,- Persona as MessagePersona,- Style as MessageStyle,+ PersonaEnum as MessagePersona,+ StyleEnum as MessageStyle,ToolModel as MessageToolModel,)from contextlib import asynccontextmanager@@ -133,7 +133,7 @@ MESSAGE_STYLE_R = rf"style=([a-z_]*)( .*)?"FUNC_NAME_SANITIZER_R = r"[^a-zA-Z0-9_-]"-class Context(str, Enum):+class ContextEnum(str, Enum):TRANSFER_FAILED = "transfer_failed"CONNECT_AGENT = "connect_agent"GOODBYE = "goodbye"@@ -357,7 +357,7 @@ async def communication_event_worker(await handle_play(call=call,client=client,- context=Context.GOODBYE,+ context=ContextEnum.GOODBYE,text=CONFIG.prompts.tts.goodbye(),)@@ -373,13 +373,13 @@ async def communication_event_worker(_logger.debug(f"Play completed ({call.call_id})")if (- operation_context == Context.TRANSFER_FAILED- or operation_context == Context.GOODBYE+ operation_context == ContextEnum.TRANSFER_FAILED+ or operation_context == ContextEnum.GOODBYE): # Call ended_logger.info(f"Ending call ({call.call_id})")await handle_hangup(call=call, client=client)- elif operation_context == Context.CONNECT_AGENT: # Call transfer+ elif operation_context == ContextEnum.CONNECT_AGENT: # Call transfer_logger.info(f"Initiating transfer call initiated ({call.call_id})")agent_caller = PhoneNumberIdentifier(str(CONFIG.workflow.agent_phone_number)@@ -420,7 +420,7 @@ async def communication_event_worker(await handle_play(call=call,client=client,- context=Context.TRANSFER_FAILED,+ context=ContextEnum.TRANSFER_FAILED,text=CONFIG.prompts.tts.calltransfer_failure(),)@@ -523,7 +523,7 @@ async def intelligence(await handle_play(call=call,client=client,- context=Context.CONNECT_AGENT,+ context=ContextEnum.CONNECT_AGENT,text=CONFIG.prompts.tts.end_call_to_connect_agent(),)@@ -531,7 +531,7 @@ async def intelligence(await handle_play(call=call,client=client,- context=Context.GOODBYE,+ context=ContextEnum.GOODBYE,text=CONFIG.prompts.tts.goodbye(),)diff --git a/models/action.py b/models/action.pyindex 1563cdf..788bb15 100644--- a/models/action.py+++ b/models/action.py@@ -2,7 +2,7 @@ from enum import Enumfrom pydantic import BaseModel-class Indent(str, Enum):+class IndentEnum(str, Enum):CONTINUE = "continue"END_CALL = "end_call"NEW_CLAIM = "new_claim"@@ -13,4 +13,4 @@ class Indent(str, Enum):class ActionModel(BaseModel):content: str- intent: Indent+ intent: IndentEnumdiff --git a/models/message.py b/models/message.pyindex b1c1a64..343375d 100644--- a/models/message.py+++ b/models/message.py@@ -4,7 +4,7 @@ from pydantic import BaseModel, Fieldfrom typing import List-class Style(str, Enum):+class StyleEnum(str, Enum):"""Voice styles the Azure AI Speech Service supports.@@ -18,14 +18,14 @@ class Style(str, Enum):SAD = "sad"-class Action(str, Enum):+class ActionEnum(str, Enum):CALL = "call"HANGUP = "hangup"SMS = "sms"TALK = "talk"-class Persona(str, Enum):+class PersonaEnum(str, Enum):ASSISTANT = "assistant"HUMAN = "human"TOOL = "tool"@@ -42,8 +42,8 @@ class MessageModel(BaseModel):# Immutable fieldscreated_at: datetime = Field(default_factory=datetime.utcnow, frozen=True)# Editable fields- action: Action = Action.TALK+ action: ActionEnum = ActionEnum.TALKcontent: str- persona: Persona- style: Style = Style.NONE+ persona: PersonaEnum+ style: StyleEnum = StyleEnum.NONEtool_calls: List[ToolModel] = []diff --git a/models/next.py b/models/next.pyindex d305f1d..cc0e2e9 100644--- a/models/next.py+++ b/models/next.py@@ -2,7 +2,7 @@ from enum import Enumfrom pydantic import BaseModel-class Action(str, Enum):+class ActionEnum(str, Enum):CASE_CLOSED = "case_closed"COMMERCIAL_OFFER = "commercial_offer"CUSTOMER_WILL_SEND_INFO = "customer_will_send_info"@@ -12,5 +12,5 @@ class Action(str, Enum):class NextModel(BaseModel):- action: Action+ action: ActionEnumjustification: str