Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
refacto: Standardize enum class names
Clémence Lesné9868ec68dc0a
diff --git a/function_app.py b/function_app.pyindex 0a0453d..3e94c85 100644--- a/function_app.py+++ b/function_app.py@@ -41,7 +41,7 @@ from helpers.http import azure_transportfrom helpers.call_utils import ContextEnum as CallContextEnumfrom htmlmin.minify import html_minifyfrom http import HTTPStatus-from models.readiness import ReadinessModel, ReadinessCheckModel, ReadinessStatus+from models.readiness import ReadinessModel, ReadinessCheckModel, ReadinessEnumfrom opentelemetry.semconv.trace import SpanAttributesfrom os import getenvfrom pydantic import TypeAdapter, ValidationError@@ -101,11 +101,11 @@ async def health_readiness_get(req: func.HttpRequest) -> func.HttpResponse:_cache.areadiness(), _db.areadiness(), _search.areadiness(), _sms.areadiness())readiness = ReadinessModel(- status=ReadinessStatus.OK,+ status=ReadinessEnum.OK,checks=[ReadinessCheckModel(id="cache", status=cache_check),ReadinessCheckModel(id="index", status=db_check),- ReadinessCheckModel(id="startup", status=ReadinessStatus.OK),+ ReadinessCheckModel(id="startup", status=ReadinessEnum.OK),ReadinessCheckModel(id="store", status=search_check),ReadinessCheckModel(id="stream", status=sms_check),],@@ -113,8 +113,8 @@ async def health_readiness_get(req: func.HttpRequest) -> func.HttpResponse:# If one of the checks fails, the whole readiness failsstatus_code = HTTPStatus.OKfor check in readiness.checks:- if check.status != ReadinessStatus.OK:- readiness.status = ReadinessStatus.FAIL+ if check.status != ReadinessEnum.OK:+ readiness.status = ReadinessEnum.FAILstatus_code = HTTPStatus.SERVICE_UNAVAILABLEbreakreturn func.HttpResponse(diff --git a/persistence/ai_search.py b/persistence/ai_search.pyindex d774523..af52a3a 100644--- a/persistence/ai_search.py+++ b/persistence/ai_search.py@@ -17,7 +17,7 @@ from azure.search.documents.models import (from helpers.http import azure_transportfrom helpers.config_models.ai_search import AiSearchModelfrom helpers.logging import logger-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom models.training import TrainingModelfrom persistence.icache import ICachefrom persistence.isearch import ISearch@@ -44,19 +44,19 @@ class AiSearchSearch(ISearch):)self._config = config- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the AI Search service."""try:async with await self._use_client() as client:await client.get_document_count()- return ReadinessStatus.OK+ return ReadinessEnum.OKexcept HttpResponseError as e:logger.error(f"Error requesting AI Search, {e}")except ServiceRequestError as e:logger.error(f"Error connecting to AI Search, {e}")- return ReadinessStatus.FAIL+ return ReadinessEnum.FAIL@retry(reraise=True,diff --git a/persistence/communication_services.py b/persistence/communication_services.pyindex f864d72..bb67c7c 100644--- a/persistence/communication_services.py+++ b/persistence/communication_services.py@@ -5,7 +5,7 @@ from helpers.http import azure_transportfrom helpers.config_models.communication_services import CommunicationServicesModelfrom helpers.logging import loggerfrom helpers.pydantic_types.phone_numbers import PhoneNumber-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom persistence.isms import ISmsfrom typing import Optional@@ -18,12 +18,12 @@ class CommunicationServicesSms(ISms):logger.info(f"Using Communication Services from number {config.phone_number}")self._config = config- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the Communication Services SMS service."""# TODO: How to check the readiness of the SMS service? We could send a SMS for each test, but that would be damm expensive.- return ReadinessStatus.OK+ return ReadinessEnum.OKasync def asend(self, content: str, phone_number: PhoneNumber) -> bool:logger.info(f"Sending SMS to {phone_number}")diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.pyindex 47b8185..d772950 100644--- a/persistence/cosmos_db.py+++ b/persistence/cosmos_db.py@@ -7,7 +7,7 @@ from helpers.config_models.database import CosmosDbModelfrom helpers.http import azure_transportfrom helpers.logging import loggerfrom models.call import CallStateModel-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom persistence.icache import ICachefrom persistence.istore import IStorefrom pydantic import ValidationError@@ -25,7 +25,7 @@ class CosmosDbStore(IStore):logger.info(f"Using Cosmos DB {config.database}/{config.container}")self._config = config- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the Cosmos DB service.@@ -43,7 +43,7 @@ class CosmosDbStore(IStore):try:# Test the item does not existif await self._item_exists(test_id, test_partition):- return ReadinessStatus.FAIL+ return ReadinessEnum.FAILasync with self._use_client() as db:# Create a new itemawait db.upsert_item(body=test_dict)@@ -58,13 +58,13 @@ class CosmosDbStore(IStore):await db.delete_item(item=test_id, partition_key=test_partition)# Test the item does not existif await self._item_exists(test_id, test_partition):- return ReadinessStatus.FAIL- return ReadinessStatus.OK+ return ReadinessEnum.FAIL+ return ReadinessEnum.OKexcept AssertionError:logger.error("Readiness test failed", exc_info=True)except CosmosHttpResponseError as e:logger.error(f"Error requesting CosmosDB, {e}")- return ReadinessStatus.FAIL+ return ReadinessEnum.FAILasync def _item_exists(self, test_id: str, partition_key: str) -> bool:exist = Falsediff --git a/persistence/icache.py b/persistence/icache.pyindex 97872f2..e4d1c85 100644--- a/persistence/icache.py+++ b/persistence/icache.py@@ -1,12 +1,12 @@from abc import ABC, abstractmethod-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom typing import Optional, Unionclass ICache(ABC):@abstractmethod- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:pass@abstractmethoddiff --git a/persistence/isearch.py b/persistence/isearch.pyindex 4745b14..097b12a 100644--- a/persistence/isearch.py+++ b/persistence/isearch.py@@ -1,5 +1,5 @@from abc import ABC, abstractmethod-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom models.training import TrainingModelfrom persistence.icache import ICachefrom typing import Optional@@ -12,7 +12,7 @@ class ISearch(ABC):self._cache = cache@abstractmethod- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:pass@abstractmethoddiff --git a/persistence/isms.py b/persistence/isms.pyindex 1cb1310..25fe769 100644--- a/persistence/isms.py+++ b/persistence/isms.py@@ -1,12 +1,12 @@from abc import ABC, abstractmethodfrom helpers.pydantic_types.phone_numbers import PhoneNumber-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumclass ISms(ABC):@abstractmethod- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:pass@abstractmethoddiff --git a/persistence/istore.py b/persistence/istore.pyindex 090f70b..8ae2e19 100644--- a/persistence/istore.py+++ b/persistence/istore.py@@ -1,6 +1,6 @@from abc import ABC, abstractmethodfrom models.call import CallStateModel-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom persistence.icache import ICachefrom typing import Optionalfrom uuid import UUID@@ -13,7 +13,7 @@ class IStore(ABC):self._cache = cache@abstractmethod- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:pass@abstractmethoddiff --git a/persistence/memory.py b/persistence/memory.pyindex 8a37af2..75e5b39 100644--- a/persistence/memory.py+++ b/persistence/memory.py@@ -1,7 +1,7 @@from collections import OrderedDictfrom helpers.config_models.cache import MemoryModelfrom helpers.logging import logger-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom persistence.icache import ICachefrom typing import Optional, Unionimport hashlib@@ -25,11 +25,11 @@ class MemoryCache(ICache):)self._config = config- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the memory cache."""- return ReadinessStatus.OK # Always ready, it's memory :)+ return ReadinessEnum.OK # Always ready, it's memory :)async def aget(self, key: str) -> Optional[bytes]:"""diff --git a/persistence/redis.py b/persistence/redis.pyindex ccea446..ec655fe 100644--- a/persistence/redis.py+++ b/persistence/redis.py@@ -1,6 +1,6 @@from helpers.config_models.cache import RedisModelfrom helpers.logging import logger-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom opentelemetry.instrumentation.redis import RedisInstrumentorfrom persistence.icache import ICachefrom redis.asyncio import Redis@@ -43,7 +43,7 @@ class RedisCache(ICache):password=config.password.get_secret_value(),) # Redis manage by itself a low level connection pool with asyncio, but be warning to not use a generator while consuming the connection, it will close it- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the Redis cache.@@ -62,12 +62,12 @@ class RedisCache(ICache):await self._client.delete(test_name)# Test the item does not existassert await self._client.get(test_name) is None- return ReadinessStatus.OK+ return ReadinessEnum.OKexcept AssertionError as e:logger.error(f"Readiness test failed, {e}")except RedisError as e:logger.error(f"Error requesting Redis, {e}")- return ReadinessStatus.FAIL+ return ReadinessEnum.FAILasync def aget(self, key: str) -> Optional[bytes]:"""diff --git a/persistence/sqlite.py b/persistence/sqlite.pyindex a2fbda4..53b97c1 100644--- a/persistence/sqlite.py+++ b/persistence/sqlite.py@@ -4,7 +4,7 @@ from helpers.config import CONFIGfrom helpers.config_models.database import SqliteModelfrom helpers.logging import loggerfrom models.call import CallStateModel-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentorfrom persistence.icache import ICachefrom persistence.istore import IStore@@ -39,7 +39,7 @@ class SqliteStore(IStore):os.makedirs(name=db_folder, exist_ok=True)self._first_run_done = True- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the SQLite database.@@ -48,10 +48,10 @@ class SqliteStore(IStore):try:async with self._use_db() as db:await db.execute("SELECT 1")- return ReadinessStatus.OK+ return ReadinessEnum.OKexcept Exception as e:logger.error(f"Error requesting SQLite, {e}")- return ReadinessStatus.FAIL+ return ReadinessEnum.FAILasync def call_aget(self, call_id: UUID) -> Optional[CallStateModel]:logger.debug(f"Loading call {call_id}")diff --git a/persistence/twilio.py b/persistence/twilio.pyindex 96a226e..1dc1be1 100644--- a/persistence/twilio.py+++ b/persistence/twilio.py@@ -2,7 +2,7 @@ from helpers.config_models.sms import TwilioModelfrom helpers.http import twilio_httpfrom helpers.logging import loggerfrom helpers.pydantic_types.phone_numbers import PhoneNumber-from models.readiness import ReadinessStatus+from models.readiness import ReadinessEnumfrom persistence.isms import ISmsfrom twilio.base.exceptions import TwilioRestExceptionfrom twilio.rest import Client@@ -17,7 +17,7 @@ class TwilioSms(ISms):logger.info(f"Using Twilio from number {config.phone_number}")self._config = config- async def areadiness(self) -> ReadinessStatus:+ async def areadiness(self) -> ReadinessEnum:"""Check the readiness of the Twilio SMS service.@@ -29,10 +29,10 @@ class TwilioSms(ISms):account = await client.api.accounts(account_sid).fetch_async()balance = account.balance.fetch()assert balance.balance and float(balance.balance) > 0- return ReadinessStatus.OK+ return ReadinessEnum.OKexcept AssertionError:logger.error("Readiness test failed", exc_info=True)- return ReadinessStatus.FAIL+ return ReadinessEnum.FAILasync def asend(self, content: str, phone_number: PhoneNumber) -> bool:logger.info(f"Sending SMS to {phone_number}")