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

dev: Simplify the deploy process

Clémence Lesnéec1d25cd8ba1
diff --git a/Makefile b/Makefile
index 84edfad..f19d7c7 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,21 @@
+# Container configuration
container_name := ghcr.io/clemlesne/claim-ai-phone-bot
docker := docker
+# Versioning
version_full ?= $(shell $(MAKE) --silent version-full)
version_small ?= $(shell $(MAKE) --silent version)
+# DevTunnel configuration
tunnel_name := claim-ai-phone-bot-$(shell hostname | tr '[:upper:]' '[:lower:]')
tunnel_url ?= $(shell devtunnel show $(tunnel_name) | grep -o 'http[s]*://[^"]*')
+# App location
+app_location := westeurope
+openai_location := swedencentral
+search_location := northeurope
+# App configuration
+agent_phone_number ?= $(shell cat config.yaml | yq '.workflow.agent_phone_number')
+bot_company ?= $(shell cat config.yaml | yq '.workflow.bot_company')
+bot_name ?= $(shell cat config.yaml | yq '.workflow.bot_name')
+bot_phone_number ?= $(shell cat config.yaml | yq '.communication_service.phone_number')
version:
@bash ./cicd/version/version.sh -g . -c
@@ -85,7 +97,7 @@ start:
$(MAKE) eventgrid-register \
endpoint=$(tunnel_url) \
name=$(tunnel_name) \
- phone_number=$(shell cat config.yaml | yq '.communication_service.phone_number') \
+ phone_number=$(bot_phone_number) \
source="/subscriptions/2e41c463-3dfb-4760-8161-60e8cefa6d28/resourceGroups/claim-ai/providers/Microsoft.Communication/communicationServices/claim-ai"
@echo "🚀 Claim AI is running on $(tunnel_url)"
@@ -98,8 +110,14 @@ stop:
deploy:
@echo "🛠️ Deploying to Azure..."
az deployment sub create \
- --location westeurope \
- --parameters config='$(shell cat config.yaml | yq -o json)' \
+ --location $(app_location) \
+ --parameters \
+ 'agentPhoneNumber=$(agent_phone_number)' \
+ 'botCompany=$(bot_company)' \
+ 'botName=$(bot_name)' \
+ 'botPhoneNumber=$(bot_phone_number)' \
+ 'openaiLocation=$(openai_location)' \
+ 'searchLocation=$(search_location)' \
--template-file bicep/main.bicep \
--name $(name)
@@ -109,7 +127,7 @@ deploy:
$(MAKE) eventgrid-register \
endpoint=$(shell az deployment sub show --name $(name) | yq '.properties.outputs["appUrl"].value') \
name=$(name) \
- phone_number=$(shell cat config.yaml | yq '.communication_service.phone_number') \
+ phone_number=$(bot_phone_number) \
source=$(shell az deployment sub show --name $(name) | yq '.properties.outputs["communicationId"].value')
@echo "🚀 Claim AI is running on $(shell az deployment sub show --name $(name) | yq '.properties.outputs["appUrl"].value')"
@@ -132,7 +150,7 @@ eventgrid-register:
@echo "⚙️ Creating event grid subscription..."
az eventgrid event-subscription create \
- --advanced-filter data.to.PhoneNumber.Value StringBeginsWith $(phone_number) \
+ --advanced-filter data.to.PhoneNumber.Value StringBeginsWith $(bot_phone_number) \
--enable-advanced-filtering-on-arrays true \
--endpoint $(endpoint)/call/inbound \
--event-delivery-schema eventgridschema \
@@ -153,9 +171,9 @@ copy-resources:
--source resources
watch-call:
- @echo "👀 Watching status of $(phone_number)..."
+ @echo "👀 Watching status of $(bot_phone_number)..."
while true; do \
clear; \
- curl -s "$(endpoint)/call?phone_number=%2B$(phone_number)" | yq --prettyPrint '.[0] | {"phone_number": .phone_number, "claim": .claim, "reminders": .reminders}'; \
+ curl -s "$(endpoint)/call?phone_number=%2B$(bot_phone_number)" | yq --prettyPrint '.[0] | {"phone_number": .phone_number, "claim": .claim, "reminders": .reminders}'; \
sleep 3; \
done
diff --git a/README.md b/README.md
index 1d96a39..fcc1ff1 100644
--- a/README.md
+++ b/README.md
@@ -207,13 +207,6 @@ Create a local `config.yaml` file (most of the fields are filled automatically b
```yaml
# config.yaml
-api: {}
-
-database:
- cosmos_db: {}
-
-resources: {}
-
workflow:
agent_phone_number: "+33612345678"
bot_company: Contoso
@@ -221,30 +214,23 @@ workflow:
communication_service:
phone_number: "+33612345678"
- voice_name: fr-FR-DeniseNeural
-
-cognitive_service:
- endpoint: https://xxx.cognitiveservices.azure.com
-
-openai: {}
-ai_search:
- index: trainings
- semantic_configuration: default
-
-content_safety:
- blocklists: []
+prompts:
+ llm: {}
+ tts: {}
```
Steps to deploy:
-1. Create an `Communication Services` resource plus a `Phone Number`
-2. Create the local `config.yaml`
+1. Create an Communication Services resource plus a Phone Number with inbound call capability
+2. Create the local `config.yaml` file (like the example above)
3. Connect to your Azure environment (e.g. `az login`)
4. Run deployment with `make deploy name=my-instance`
5. Wait for the deployment to finish (if it fails for a `'null' not found` error, retry the command)
-6. Create the AI Search index
-7. Get the logs with `make logs name=my-instance`
+6. Link the AI multi-service account named `[my-instance]-communication` to the Communication Services resource
+7. Create a AI Search index named `trainings`
+
+Get the logs with `make logs name=my-instance`.
## Local installation
diff --git a/bicep/app.bicep b/bicep/app.bicep
index 6d54fd7..c0c710a 100644
--- a/bicep/app.bicep
+++ b/bicep/app.bicep
@@ -1,10 +1,15 @@
param adaModel string
param adaVersion string
-param config string
+param agentPhoneNumber string
+param botCompany string
+param botName string
+param botPhoneNumber string
+param botVoiceName string
param gptModel string
param gptVersion string
param imageVersion string
param location string
+param moderationBlocklists array
param openaiLocation string
param searchLocation string
param tags object
@@ -13,6 +18,57 @@ var prefix = deployment().name
var appUrl = 'https://claim-ai.${acaEnv.properties.defaultDomain}'
var gptModelFullName = toLower('${gptModel}-${gptVersion}')
var adaModelFullName = toLower('${adaModel}-${adaVersion}')
+var config = {
+ api: {
+ events_domain: appUrl
+ }
+ database: {
+ mode: 'cosmos_db'
+ cosmos_db: {
+ access_key: cosmos.listKeys().primaryMasterKey
+ container: container.name
+ database: database.name
+ endpoint: cosmos.properties.documentEndpoint
+ }
+ }
+ resources: {
+ public_url: storageAccount.properties.primaryEndpoints.web
+ }
+ workflow: {
+ agent_phone_number: agentPhoneNumber
+ bot_company: botCompany
+ bot_name: botName
+ }
+ communication_service: {
+ access_key: communication.listKeys().primaryKey
+ endpoint: communication.properties.hostName
+ phone_number: botPhoneNumber
+ voice_name: botVoiceName
+ }
+ cognitive_service: {
+ endpoint: cognitiveCommunication.properties.endpoint
+ }
+ openai: {
+ endpoint: cognitiveOpenai.properties.endpoint
+ gpt_deployment: gpt.name
+ gpt_model: gptModel
+ }
+ ai_search: {
+ access_key: search.listAdminKeys().primaryKey
+ endpoint: 'https://${search.name}.search.windows.net'
+ index: 'trainings'
+ semantic_configuration: 'default'
+ }
+ content_safety: {
+ access_key: cognitiveContentsafety.listKeys().key1
+ blocklists: moderationBlocklists
+ endpoint: cognitiveContentsafety.properties.endpoint
+ }
+ prompts: {
+ llm: loadYamlContent('../config.yaml').prompts.llm
+ tts: loadYamlContent('../config.yaml').prompts.tts
+ }
+}
output appUrl string = appUrl
output blobStoragePublicName string = storageAccount.name
@@ -76,71 +132,7 @@ resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {
env: [
{
name: 'CONFIG_JSON'
- value: config
- }
- {
- name: 'API_EVENTS_DOMAIN'
- value: appUrl
- }
- {
- name: 'DATABASE_MODE'
- value: 'cosmos_db'
- }
- {
- name: 'DATABASE_COSMOS_DB_ACCESS_KEY'
- value: cosmos.listKeys().primaryMasterKey
- }
- {
- name: 'DATABASE_COSMOS_DB_ENDPOINT'
- value: cosmos.properties.documentEndpoint
- }
- {
- name: 'DATABASE_COSMOS_DB_CONTAINER'
- value: container.name
- }
- {
- name: 'DATABASE_COSMOS_DB_DATABASE'
- value: database.name
- }
- {
- name: 'RESOURCES_PUBLIC_URL'
- value: storageAccount.properties.primaryEndpoints.web
- }
- {
- name: 'COMMUNICATION_SERVICE_ENDPOINT'
- value: communication.properties.hostName
- }
- {
- name: 'COMMUNICATION_SERVICE_ACCESS_KEY'
- value: communication.listKeys().primaryKey
- }
- {
- name: 'OPENAI_ENDPOINT'
- value: cognitiveOpenai.properties.endpoint
- }
- {
- name: 'OPENAI_GPT_DEPLOYMENT'
- value: gpt.name
- }
- {
- name: 'OPENAI_GPT_MODEL'
- value: gptModel
- }
- {
- name: 'AI_SEARCH_ENDPOINT'
- value: 'https://${search.name}.search.windows.net'
- }
- {
- name: 'AI_SEARCH_ACCESS_KEY'
- value: search.listAdminKeys().primaryKey
- }
- {
- name: 'CONTENT_SAFETY_ENDPOINT'
- value: cognitiveContentsafety.properties.endpoint
- }
- {
- name: 'CONTENT_SAFETY_ACCESS_KEY'
- value: cognitiveContentsafety.listKeys().key1
+ value: string(config)
}
]
resources: {
@@ -210,6 +202,19 @@ resource eventgridTopic 'Microsoft.EventGrid/systemTopics@2023-12-15-preview' =
}
}
+resource cognitiveCommunication 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
+ name: '${prefix}-communication'
+ location: location
+ tags: tags
+ sku: {
+ name: 'S0'
+ }
+ kind: 'CognitiveServices'
+ properties: {
+ customSubDomainName: '${prefix}-communication'
+ }
+}
+
resource cognitiveContentsafety 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {
name: '${prefix}-contentsafety'
location: location
diff --git a/bicep/main.bicep b/bicep/main.bicep
index b544887..286cde4 100644
--- a/bicep/main.bicep
+++ b/bicep/main.bicep
@@ -1,13 +1,16 @@
param adaModel string = 'text-embedding-ada-002'
param adaVersion string = '2'
-param config string
+param agentPhoneNumber string
+param botCompany string
+param botName string
+param botPhoneNumber string
param gptModel string = 'gpt-4'
param gptVersion string = '1106-Preview'
param imageVersion string = 'main'
param instance string = deployment().name
-param location string = 'westeurope'
-param openaiLocation string = 'swedencentral'
-param searchLocation string = 'northeurope'
+param location string = deployment().location
+param openaiLocation string
+param searchLocation string
targetScope = 'subscription'
@@ -35,11 +38,16 @@ module app 'app.bicep' = {
params: {
adaModel: adaModel
adaVersion: adaVersion
- config: config
+ agentPhoneNumber: agentPhoneNumber
+ botCompany: botCompany
+ botName: botName
+ botPhoneNumber: botPhoneNumber
+ botVoiceName: 'fr-FR-DeniseNeural'
gptModel: gptModel
gptVersion: gptVersion
imageVersion: imageVersion
location: location
+ moderationBlocklists: []
openaiLocation: openaiLocation
searchLocation: searchLocation
tags: tags
diff --git a/helpers/config_models/ai_search.py b/helpers/config_models/ai_search.py
index ced6956..863213b 100644
--- a/helpers/config_models/ai_search.py
+++ b/helpers/config_models/ai_search.py
@@ -2,7 +2,7 @@ from pydantic import SecretStr
from pydantic_settings import BaseSettings
-class AiSearchModel(BaseSettings, env_prefix="ai_search_"):
+class AiSearchModel(BaseSettings):
access_key: SecretStr
endpoint: str
index: str
diff --git a/helpers/config_models/api.py b/helpers/config_models/api.py
index b9f0f59..bf7dbe9 100644
--- a/helpers/config_models/api.py
+++ b/helpers/config_models/api.py
@@ -1,6 +1,6 @@
from pydantic_settings import BaseSettings
-class ApiModel(BaseSettings, env_prefix="api_"):
+class ApiModel(BaseSettings):
events_domain: str
root_path: str = ""
diff --git a/helpers/config_models/cognitive_service.py b/helpers/config_models/cognitive_service.py
index 20dc5fc..738447c 100644
--- a/helpers/config_models/cognitive_service.py
+++ b/helpers/config_models/cognitive_service.py
@@ -1,5 +1,5 @@
from pydantic_settings import BaseSettings
-class CognitiveServiceModel(BaseSettings, env_prefix="cognitive_service_"):
+class CognitiveServiceModel(BaseSettings):
endpoint: str
diff --git a/helpers/config_models/communication_service.py b/helpers/config_models/communication_service.py
index edb323b..c350c93 100644
--- a/helpers/config_models/communication_service.py
+++ b/helpers/config_models/communication_service.py
@@ -7,7 +7,7 @@ from pydantic_settings import BaseSettings
PhoneNumber.phone_format = "E164"
-class CommunicationServiceModel(BaseSettings, env_prefix="communication_service_"):
+class CommunicationServiceModel(BaseSettings):
access_key: SecretStr
endpoint: str
phone_number: PhoneNumber
diff --git a/helpers/config_models/content_safety.py b/helpers/config_models/content_safety.py
index 13ea6ba..b90d626 100644
--- a/helpers/config_models/content_safety.py
+++ b/helpers/config_models/content_safety.py
@@ -3,7 +3,7 @@ from pydantic import SecretStr
from pydantic_settings import BaseSettings
-class ContentSafetyModel(BaseSettings, env_prefix="content_safety_"):
+class ContentSafetyModel(BaseSettings):
access_key: SecretStr
blocklists: List[str]
endpoint: str
diff --git a/helpers/config_models/database.py b/helpers/config_models/database.py
index b16fb46..bc222df 100644
--- a/helpers/config_models/database.py
+++ b/helpers/config_models/database.py
@@ -9,14 +9,14 @@ class Mode(str, Enum):
SQLITE = "sqlite"
-class CosmosDbModel(BaseSettings, env_prefix="database_cosmos_db_"):
+class CosmosDbModel(BaseSettings):
access_key: SecretStr
container: str
database: str
endpoint: str
-class SqliteModel(BaseSettings, env_prefix="database_sqlite_"):
+class SqliteModel(BaseSettings):
path: str = ".local"
schema_version: int = Field(default=3, frozen=True)
table: str = "calls"
@@ -30,7 +30,7 @@ class SqliteModel(BaseSettings, env_prefix="database_sqlite_"):
return f"{self.path}-v{self.schema_version}.sqlite"
-class DatabaseModel(BaseSettings, env_prefix="database_"):
+class DatabaseModel(BaseSettings):
cosmos_db: Optional[CosmosDbModel] = None
mode: Mode = Mode.SQLITE
sqlite: Optional[SqliteModel] = None
diff --git a/helpers/config_models/monitoring.py b/helpers/config_models/monitoring.py
index c845583..27eb1fe 100644
--- a/helpers/config_models/monitoring.py
+++ b/helpers/config_models/monitoring.py
@@ -12,12 +12,12 @@ class LoggingLevel(str, Enum):
WARNING = "WARNING"
-class LoggingMonitoringModel(BaseSettings, env_prefix="monitoring_logging_"):
+class LoggingMonitoringModel(BaseSettings):
app_level: LoggingLevel = LoggingLevel.INFO
sys_level: LoggingLevel = LoggingLevel.WARNING
-class MonitoringModel(BaseSettings, env_prefix="monitoring_"):
+class MonitoringModel(BaseSettings):
logging: LoggingMonitoringModel = (
LoggingMonitoringModel()
) # Object is fully defined by default
diff --git a/helpers/config_models/openai.py b/helpers/config_models/openai.py
index 9d79386..5b7cd32 100644
--- a/helpers/config_models/openai.py
+++ b/helpers/config_models/openai.py
@@ -3,7 +3,7 @@ from pydantic_settings import BaseSettings
from typing import Optional
-class OpenAiModel(BaseSettings, env_prefix="openai_"):
+class OpenAiModel(BaseSettings):
api_key: Optional[SecretStr] = None
endpoint: str
gpt_deployment: str
diff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.py
index bc02652..0816ff0 100644
--- a/helpers/config_models/prompts.py
+++ b/helpers/config_models/prompts.py
@@ -37,7 +37,7 @@ def _pydantic_to_str(
)
-class SoundModel(BaseSettings, env_prefix="prompts_sound_"):
+class SoundModel(BaseSettings):
loading_tpl: str = "{public_url}/loading.wav"
ready_tpl: str = "{public_url}/ready.wav"
@@ -56,7 +56,7 @@ class SoundModel(BaseSettings, env_prefix="prompts_sound_"):
)
-class LlmModel(BaseSettings, env_prefix="prompts_llm_"):
+class LlmModel(BaseSettings):
"""
Introduce to Assistant who they are, what they do.
diff --git a/helpers/config_models/resources.py b/helpers/config_models/resources.py
index ccf1168..383b970 100644
--- a/helpers/config_models/resources.py
+++ b/helpers/config_models/resources.py
@@ -1,5 +1,5 @@
from pydantic_settings import BaseSettings
-class ResourcesModel(BaseSettings, env_prefix="resources_"):
+class ResourcesModel(BaseSettings):
public_url: str
diff --git a/helpers/config_models/root.py b/helpers/config_models/root.py
index 49c3910..cbdcfdf 100644
--- a/helpers/config_models/root.py
+++ b/helpers/config_models/root.py
@@ -13,7 +13,7 @@ from pydantic import Field
from pydantic_settings import BaseSettings
-class RootModel(BaseSettings, env_prefix=""):
+class RootModel(BaseSettings):
# Immutable fields
version: str = Field(frozen=True)
# Editable fields