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

quality: Code quality

Clémence Lesnéecbccc05de08
diff --git a/Makefile b/Makefile
index 8830f7d..3926058 100644
--- a/Makefile
+++ b/Makefile
@@ -34,21 +34,19 @@ install:
@echo "➡️ Installing Twilio CLI..."
twilio --version || brew tap twilio/brew && brew install twilio
- @echo "➡️ Installing Python app dependencies..."
- python3 -m pip install -r requirements.txt
-
- @echo "➡️ Installing Python dev dependencies..."
- python3 -m pip install -r requirements-dev.txt
+ @for f in $$(find . -name "requirements*.txt"); do \
+ echo "➡️ Installing Python dependencies in $$f..."; \
+ python3 -m pip install -r $$f; \
+ done
upgrade:
@echo "➡️ Upgrading pip..."
python3 -m pip install --upgrade pip
- @echo "➡️ Upgrading Python app dependencies..."
- python3 -m pur -r requirements.txt
-
- @echo "➡️ Upgrading Python dev dependencies..."
- python3 -m pur -r requirements-dev.txt
+ @for f in $$(find . -name "requirements*.txt"); do \
+ echo "➡️ Upgrading Python dependencies in $$f..."; \
+ python3 -m pip install --upgrade -r $$f; \
+ done
@echo "➡️ Upgrading Bicep CLI..."
az bicep upgrade
diff --git a/function_app.py b/function_app.py
index 25dd3cf..02392ec 100644
--- a/function_app.py
+++ b/function_app.py
@@ -705,7 +705,7 @@ async def _use_automation_client() -> CallAutomationClient:
global _automation_client
if not isinstance(_automation_client, CallAutomationClient):
_automation_client = CallAutomationClient(
- # Azure deployment
+ # Deployment
endpoint=CONFIG.communication_services.endpoint,
# Performance
transport=await azure_transport(),
diff --git a/helpers/call_events.py b/helpers/call_events.py
index a8aa8c6..7129802 100644
--- a/helpers/call_events.py
+++ b/helpers/call_events.py
@@ -368,9 +368,7 @@ async def on_sms_received(
persona=MessagePersonaEnum.HUMAN,
)
)
- await _db.call_aset(
- call
- ) # save in DB allowing SMS answers to be more "in-sync"
+ await _db.call_aset(call) # save in DB allowing SMS answers to be more "in-sync"
if not call.in_progress:
logger.info("Call not in progress, answering with SMS")
else:
diff --git a/helpers/config_models/llm.py b/helpers/config_models/llm.py
index c50aaca..4ece3c1 100644
--- a/helpers/config_models/llm.py
+++ b/helpers/config_models/llm.py
@@ -40,7 +40,7 @@ class AzureOpenaiPlatformModel(AbstractPlatformModel):
)
self._client = AsyncAzureOpenAI(
**self._client_kwargs,
- # Azure deployment
+ # Deployment
api_version="2023-12-01-preview",
azure_deployment=self.deployment,
azure_endpoint=self.endpoint,
diff --git a/helpers/llm_tools.py b/helpers/llm_tools.py
index 949ab30..bd81e3f 100644
--- a/helpers/llm_tools.py
+++ b/helpers/llm_tools.py
@@ -12,8 +12,9 @@ from models.message import (
StyleEnum as MessageStyleEnum,
)
from models.reminder import ReminderModel
+from models.training import TrainingModel
from openai.types.chat import ChatCompletionToolParam
-from pydantic import ValidationError
+from pydantic import TypeAdapter, ValidationError
from typing import Awaitable, Callable, Annotated, Literal
from typing_extensions import TypedDict
import asyncio
@@ -336,8 +337,7 @@ class LlmPlugins:
trainings = sorted(set(training for task in tasks for training in task or []))
# Format results
res = "# Search results"
- for training in trainings:
- res += f"\n- {training.title}: {training.content}"
+ res += f"\n{TypeAdapter(list[TrainingModel]).dump_json(trainings).decode()}"
return res
async def notify_emergencies(
diff --git a/helpers/llm_worker.py b/helpers/llm_worker.py
index d37e10d..197060c 100644
--- a/helpers/llm_worker.py
+++ b/helpers/llm_worker.py
@@ -555,7 +555,7 @@ async def _use_contentsafety() -> ContentSafetyClient:
global _contentsafety_client
if not isinstance(_contentsafety_client, ContentSafetyClient):
_contentsafety_client = ContentSafetyClient(
- # Azure deployment
+ # Deployment
endpoint=CONFIG.content_safety.endpoint,
# Performance
transport=await azure_transport(),
diff --git a/helpers/translation.py b/helpers/translation.py
index 34f2c5a..27b88ce 100644
--- a/helpers/translation.py
+++ b/helpers/translation.py
@@ -68,7 +68,7 @@ async def _use_client() -> TextTranslationClient:
_client = TextTranslationClient(
# Performance
transport=await azure_transport(),
- # Azure deployment
+ # Deployment
endpoint=CONFIG.ai_translation.endpoint,
# Authentication
credential=AzureKeyCredential(
diff --git a/host.json b/host.json
index 2c2391f..c835365 100644
--- a/host.json
+++ b/host.json
@@ -2,7 +2,7 @@
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
- "version": "[4.0.0, 5.0.0)"
+ "version": "[4.*, 5.0.0)"
},
"functionTimeout": "00:03:00",
"logging": {
diff --git a/persistence/ai_search.py b/persistence/ai_search.py
index 95478e9..6193cbe 100644
--- a/persistence/ai_search.py
+++ b/persistence/ai_search.py
@@ -142,7 +142,7 @@ class AiSearchSearch(ISearch):
async def _use_client(self) -> SearchClient:
if not self._client:
self._client = SearchClient(
- # Azure deployment
+ # Deployment
endpoint=self._config.endpoint,
index_name=self._config.index,
# Performance
diff --git a/persistence/communication_services.py b/persistence/communication_services.py
index e834236..f864d72 100644
--- a/persistence/communication_services.py
+++ b/persistence/communication_services.py
@@ -57,7 +57,7 @@ class CommunicationServicesSms(ISms):
async def _use_client(self) -> SmsClient:
if not self._client:
self._client = SmsClient(
- # Azure deployment
+ # Deployment
endpoint=self._config.endpoint,
# Performance
transport=await azure_transport(),
diff --git a/persistence/cosmos_db.py b/persistence/cosmos_db.py
index b9f2d4c..6bfd1da 100644
--- a/persistence/cosmos_db.py
+++ b/persistence/cosmos_db.py
@@ -277,7 +277,7 @@ class CosmosDbStore(IStore):
retry_total=3,
# Performance
transport=await azure_transport(),
- # Azure deployment
+ # Deployment
url=self._config.endpoint,
# Authentication
credential=self._config.access_key.get_secret_value(),
diff --git a/persistence/redis.py b/persistence/redis.py
index cd6f3d3..c6ed82e 100644
--- a/persistence/redis.py
+++ b/persistence/redis.py
@@ -32,9 +32,9 @@ class RedisCache(ICache):
retry_on_error=[BusyLoadingError, ConnectionError],
retry_on_timeout=True,
retry=_retry,
- socket_connect_timeout=1, # Timeout for connection, we want it to fail fast, that's cache
- socket_timeout=10, # Timeout for queries
- # Azure deployment
+ socket_connect_timeout=1, # 1 second, timeout for connection, we want it to fail fast, that's cache
+ socket_timeout=10, # 10 seconds, timeout for queries
+ # Deployment
host=config.host,
port=config.port,
ssl=config.ssl,
diff --git a/requirements.txt b/requirements.txt
index 7d9a1a4..bb10c31 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
-aiohttp==3.9.5 # Required for azure-search-documents, azure-ai-contentsafety, azure-cosmos
+aiohttp==3.9.5 # Required for all Azure SDKs
aiosqlite==0.20.0
azure-ai-contentsafety==1.0.0
azure-ai-translation-text==1.0.0
diff --git a/tests/conftest.py b/tests/conftest.py
index ead5b41..a4defe2 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -108,7 +108,7 @@ class DeepEvalAzureOpenAI(GPTModel):
"seed": 42,
},
"temperature": 0,
- # Azure deployment
+ # Deployment
"api_version": "2023-12-01-preview",
"azure_deployment": platform.deployment,
"azure_endpoint": platform.endpoint,