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/Makefileindex 84edfad..f19d7c7 100644--- a/Makefile+++ b/Makefile@@ -1,9 +1,21 @@+# Container configurationcontainer_name := ghcr.io/clemlesne/claim-ai-phone-botdocker := docker+# Versioningversion_full ?= $(shell $(MAKE) --silent version-full)version_small ?= $(shell $(MAKE) --silent version)+# DevTunnel configurationtunnel_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 resourceswatch-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; \donediff --git a/README.md b/README.mdindex 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 installationdiff --git a/bicep/app.bicep b/bicep/app.bicepindex 6d54fd7..c0c710a 100644--- a/bicep/app.bicep+++ b/bicep/app.bicep@@ -1,10 +1,15 @@param adaModel stringparam adaVersion string-param config string+param agentPhoneNumber string+param botCompany string+param botName string+param botPhoneNumber string+param botVoiceName stringparam gptModel stringparam gptVersion stringparam imageVersion stringparam location string+param moderationBlocklists arrayparam openaiLocation stringparam searchLocation stringparam tags object@@ -13,6 +18,57 @@ var prefix = deployment().namevar 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 = appUrloutput 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: locationdiff --git a/bicep/main.bicep b/bicep/main.bicepindex 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 stringparam 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 stringtargetScope = 'subscription'@@ -35,11 +38,16 @@ module app 'app.bicep' = {params: {adaModel: adaModeladaVersion: adaVersion- config: config+ agentPhoneNumber: agentPhoneNumber+ botCompany: botCompany+ botName: botName+ botPhoneNumber: botPhoneNumber+ botVoiceName: 'fr-FR-DeniseNeural'gptModel: gptModelgptVersion: gptVersionimageVersion: imageVersionlocation: location+ moderationBlocklists: []openaiLocation: openaiLocationsearchLocation: searchLocationtags: tagsdiff --git a/helpers/config_models/ai_search.py b/helpers/config_models/ai_search.pyindex ced6956..863213b 100644--- a/helpers/config_models/ai_search.py+++ b/helpers/config_models/ai_search.py@@ -2,7 +2,7 @@ from pydantic import SecretStrfrom pydantic_settings import BaseSettings-class AiSearchModel(BaseSettings, env_prefix="ai_search_"):+class AiSearchModel(BaseSettings):access_key: SecretStrendpoint: strindex: strdiff --git a/helpers/config_models/api.py b/helpers/config_models/api.pyindex 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: strroot_path: str = ""diff --git a/helpers/config_models/cognitive_service.py b/helpers/config_models/cognitive_service.pyindex 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: strdiff --git a/helpers/config_models/communication_service.py b/helpers/config_models/communication_service.pyindex 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 BaseSettingsPhoneNumber.phone_format = "E164"-class CommunicationServiceModel(BaseSettings, env_prefix="communication_service_"):+class CommunicationServiceModel(BaseSettings):access_key: SecretStrendpoint: strphone_number: PhoneNumberdiff --git a/helpers/config_models/content_safety.py b/helpers/config_models/content_safety.pyindex 13ea6ba..b90d626 100644--- a/helpers/config_models/content_safety.py+++ b/helpers/config_models/content_safety.py@@ -3,7 +3,7 @@ from pydantic import SecretStrfrom pydantic_settings import BaseSettings-class ContentSafetyModel(BaseSettings, env_prefix="content_safety_"):+class ContentSafetyModel(BaseSettings):access_key: SecretStrblocklists: List[str]endpoint: strdiff --git a/helpers/config_models/database.py b/helpers/config_models/database.pyindex 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: SecretStrcontainer: strdatabase: strendpoint: 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] = Nonemode: Mode = Mode.SQLITEsqlite: Optional[SqliteModel] = Nonediff --git a/helpers/config_models/monitoring.py b/helpers/config_models/monitoring.pyindex 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.INFOsys_level: LoggingLevel = LoggingLevel.WARNING-class MonitoringModel(BaseSettings, env_prefix="monitoring_"):+class MonitoringModel(BaseSettings):logging: LoggingMonitoringModel = (LoggingMonitoringModel()) # Object is fully defined by defaultdiff --git a/helpers/config_models/openai.py b/helpers/config_models/openai.pyindex 9d79386..5b7cd32 100644--- a/helpers/config_models/openai.py+++ b/helpers/config_models/openai.py@@ -3,7 +3,7 @@ from pydantic_settings import BaseSettingsfrom typing import Optional-class OpenAiModel(BaseSettings, env_prefix="openai_"):+class OpenAiModel(BaseSettings):api_key: Optional[SecretStr] = Noneendpoint: strgpt_deployment: strdiff --git a/helpers/config_models/prompts.py b/helpers/config_models/prompts.pyindex 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.pyindex 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: strdiff --git a/helpers/config_models/root.py b/helpers/config_models/root.pyindex 49c3910..cbdcfdf 100644--- a/helpers/config_models/root.py+++ b/helpers/config_models/root.py@@ -13,7 +13,7 @@ from pydantic import Fieldfrom pydantic_settings import BaseSettings-class RootModel(BaseSettings, env_prefix=""):+class RootModel(BaseSettings):# Immutable fieldsversion: str = Field(frozen=True)# Editable fields