Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!
Python
feat: Deploy to Azure
Clémence Lesné859da0dbdba2
diff --git a/Makefile b/Makefileindex 7022108..4345533 100644--- a/Makefile+++ b/Makefile@@ -86,6 +86,34 @@ stop:@echo "Stopping container..."$(docker) stop claim-ai+deploy:+ @echo "🛠️ Deploying to Azure..."+ az deployment sub create \+ --location westeurope \+ --parameters config='$(shell cat config.yaml | yq -o json)' \+ --template-file bicep/main.bicep \+ --name $(name)++ $(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') \+ 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')"+ $(MAKE) logs name=$(name)++destroy:+ az deployment sub delete --name $(name)++logs:+ az containerapp logs show \+ --follow \+ --format text \+ --name claim-ai \+ --resource-group $(name) \+ --tail 100+eventgrid-register:@echo "⚙️ Deleting previous event grid subscription..."az eventgrid event-subscription delete --name $(name) || truediff --git a/README.md b/README.mdindex 457230f..776eceb 100644--- a/README.md+++ b/README.md@@ -6,6 +6,8 @@ AI-powered call center solution with Azure and OpenAI GPT.[](https://github.com/clemlesne/claim-ai-phone-bot/releases)[](https://github.com/clemlesne/claim-ai-phone-bot/blob/main/LICENSE)+[](https://portal.azure.com/#create/Microsoft.Template/uri/https%3A%2F%2Fraw.githubusercontent.com%2Fclemlesne%2Fclaim-ai-phone-bot%2Fmain%2Fbicep%2Fmain.bicep)+## OverviewA French demo is avaialble on YouTube. Do not hesitate to watch the demo in x1.5 speed to get a quick overview of the project.@@ -125,6 +127,8 @@ Place a file called `config.yaml` in the root of the project with the followingapi:root_path: "/"+database: {}+monitoring:logging:app_level: INFOdiff --git a/bicep/app.bicep b/bicep/app.bicepnew file mode 100644index 0000000..b80b506--- /dev/null+++ b/bicep/app.bicep@@ -0,0 +1,254 @@+param config string+param imageVersion string+param instance string = deployment().name+param location string = resourceGroup().location+param openaiLocation string+param tags object++var prefix = instance+var appUrl = 'https://claim-ai.${acaEnv.properties.defaultDomain}'++output appUrl string = appUrl+output communicationId string = communication.id++resource logAnalyticsWorkspace 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {+ name: prefix+ location: location+ tags: tags+ properties: {+ retentionInDays: 30+ sku: {+ name: 'PerGB2018'+ }+ }+}++resource acaEnv 'Microsoft.App/managedEnvironments@2023-05-01' = {+ name: prefix+ location: location+ tags: tags+ properties: {+ appLogsConfiguration: {+ destination: 'log-analytics'+ logAnalyticsConfiguration: {+ customerId: logAnalyticsWorkspace.properties.customerId+ sharedKey: logAnalyticsWorkspace.listKeys().primarySharedKey+ }+ }+ workloadProfiles: [+ {+ // Consumption workload profile name must be 'Consumption'+ name: 'Consumption'+ workloadProfileType: 'Consumption'+ }+ ]+ }+}++resource containerApp 'Microsoft.App/containerApps@2023-05-01' = {+ name: 'claim-ai'+ location: location+ tags: tags+ identity: {+ type: 'SystemAssigned'+ }+ properties: {+ configuration: {+ activeRevisionsMode: 'Single'+ ingress: {+ external: true+ targetPort: 8080+ }+ }+ environmentId: acaEnv.id+ template: {+ scale: {+ maxReplicas: 1+ }+ containers: [+ {+ image: 'ghcr.io/clemlesne/claim-ai-phone-bot:${imageVersion}'+ name: 'claim-ai'+ env: [+ {+ name: 'CONFIG_JSON'+ value: config+ }+ {+ name: 'EVENTS_DOMAIN'+ value: appUrl+ }+ {+ name: 'SQLITE_PATH'+ value: '/app/data/.default.sqlite'+ }+ ]+ resources: {+ cpu: 1+ memory: '2Gi'+ }+ probes: [+ {+ type: 'Liveness'+ httpGet: {+ path: '/health/liveness'+ port: 8080+ }+ }+ ]+ }+ ]+ }+ }+}++resource storageAccount 'Microsoft.Storage/storageAccounts@2023-01-01' = {+ name: replace(prefix, '-', '')+ location: location+ tags: tags+ sku: {+ name: 'Standard_ZRS'+ }+ kind: 'StorageV2'+}++resource blobService 'Microsoft.Storage/storageAccounts/blobServices@2023-01-01' = {+ parent: storageAccount+ name: 'default'+}++resource blobContainer 'Microsoft.Storage/storageAccounts/blobServices/containers@2023-01-01' = {+ parent: blobService+ name: '$web'+}++resource roleCommunicationContributor 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {+ name: 'b24988ac-6180-42a0-ab88-20f7382dd24c'+}++resource appContributeCommunication 'Microsoft.Authorization/roleAssignments@2022-04-01' = {+ name: guid(subscription().id, deployment().name, 'appContributeCommunication')+ scope: communication+ properties: {+ principalId: containerApp.identity.principalId+ principalType: 'ServicePrincipal'+ roleDefinitionId: roleCommunicationContributor.id+ }+}++resource communication 'Microsoft.Communication/CommunicationServices@2023-06-01-preview' existing = {+ name: prefix+}++resource eventgridTopic 'Microsoft.EventGrid/systemTopics@2023-12-15-preview' = {+ name: prefix+ location: 'global'+ tags: tags+ properties: {+ source: communication.id+ topicType: 'Microsoft.Communication.CommunicationServices'+ }+}++resource roleOpenaiContributor 'Microsoft.Authorization/roleDefinitions@2018-01-01-preview' existing = {+ name: 'a001fd3d-188f-4b5d-821b-7da978bf7442'+}++resource appAccessOpenai 'Microsoft.Authorization/roleAssignments@2022-04-01' = {+ name: guid(subscription().id, deployment().name, 'appAccessOpenai')+ scope: cognitiveOpenai+ properties: {+ principalId: containerApp.identity.principalId+ principalType: 'ServicePrincipal'+ roleDefinitionId: roleOpenaiContributor.id+ }+}++resource cognitiveOpenai 'Microsoft.CognitiveServices/accounts@2023-10-01-preview' = {+ name: '${prefix}-openai'+ location: openaiLocation+ tags: tags+ sku: {+ name: 'S0'+ }+ kind: 'OpenAI'+ properties: {+ customSubDomainName: '${prefix}-openai'+ }+}++resource gpt 'Microsoft.CognitiveServices/accounts/deployments@2023-10-01-preview' = {+ parent: cognitiveOpenai+ name: 'gpt'+ sku: {+ capacity: 50+ name: 'Standard'+ }+ properties: {+ raiPolicyName: contentfilter.name+ model: {+ format: 'OpenAI'+ name: 'gpt-4'+ version: '1106-Preview'+ }+ }+}++resource contentfilter 'Microsoft.CognitiveServices/accounts/raiPolicies@2023-06-01-preview' = {+ parent: cognitiveOpenai+ name: 'gpt'+ properties: {+ basePolicyName: 'Microsoft.Default'+ mode: 'Default'+ contentFilters: [+ {+ blocking: false+ enabled: false+ name: 'hate'+ source: 'Prompt'+ }+ {+ blocking: false+ enabled: false+ name: 'sexual'+ source: 'Prompt'+ }+ {+ blocking: false+ enabled: false+ name: 'selfharm'+ source: 'Prompt'+ }+ {+ blocking: false+ enabled: false+ name: 'violence'+ source: 'Prompt'+ }+ {+ blocking: false+ enabled: false+ name: 'hate'+ source: 'Completion'+ }+ {+ blocking: false+ enabled: false+ name: 'sexual'+ source: 'Completion'+ }+ {+ blocking: false+ enabled: false+ name: 'selfharm'+ source: 'Completion'+ }+ {+ blocking: false+ enabled: false+ name: 'violence'+ source: 'Completion'+ }+ ]+ }+}diff --git a/bicep/main.bicep b/bicep/main.bicepnew file mode 100644index 0000000..4efd478--- /dev/null+++ b/bicep/main.bicep@@ -0,0 +1,36 @@+param config string+param imageVersion string = 'feat-bicep-deploy'+param instance string = deployment().name+param location string = 'westeurope'+param openaiLocation string = 'swedencentral'++targetScope = 'subscription'++output appUrl string = app.outputs.appUrl+output communicationId string = app.outputs.communicationId++var tags = {+ application: 'claim-ai'+ instance: instance+ managed_by: 'Bicep'+ sources: 'https://github.com/clemlesne/claim-ai-phone-bot'+ version: imageVersion+}++resource sub 'Microsoft.Resources/resourceGroups@2021-04-01' = {+ location: location+ name: instance+ tags: tags+}++module app 'app.bicep' = {+ name: instance+ scope: sub+ params: {+ config: config+ imageVersion: imageVersion+ location: location+ openaiLocation: openaiLocation+ tags: tags+ }+}diff --git a/helpers/config_models/database.py b/helpers/config_models/database.pynew file mode 100644index 0000000..6ad98d8--- /dev/null+++ b/helpers/config_models/database.py@@ -0,0 +1,6 @@+from pydantic import BaseModel+from os import environ+++class DatabaseModel(BaseModel):+ sqlite_path: str = environ.get("SQLITE_PATH", ".local.sqlite")diff --git a/helpers/config_models/root.py b/helpers/config_models/root.pyindex fc1acc4..4445a73 100644--- a/helpers/config_models/root.py+++ b/helpers/config_models/root.py@@ -1,6 +1,7 @@from helpers.config_models.api import ApiModelfrom helpers.config_models.cognitive_service import CognitiveServiceModelfrom helpers.config_models.communication_service import CommunicationServiceModel+from helpers.config_models.database import DatabaseModelfrom helpers.config_models.eventgrid import EventgridModelfrom helpers.config_models.monitoring import MonitoringModelfrom helpers.config_models.openai import OpenAiModel@@ -13,6 +14,7 @@ class RootModel(BaseModel):api: ApiModelcognitive_service: CognitiveServiceModelcommunication_service: CommunicationServiceModel+ database: DatabaseModeleventgrid: EventgridModelmonitoring: MonitoringModelopenai: OpenAiModeldiff --git a/main.py b/main.pyindex a87abc6..b07644f 100644--- a/main.py+++ b/main.py@@ -931,7 +931,7 @@ def callback_url(caller_id: str) -> str:def init_db():- with sqlite3.connect(".local.sqlite") as db:+ with sqlite3.connect(CONFIG.database.sqlite_path) as db:db.execute("CREATE TABLE IF NOT EXISTS calls (id VARCHAR(32) PRIMARY KEY, phone_number TEXT, data TEXT, created_at TEXT)")@@ -939,7 +939,7 @@ def init_db():def save_call(call: CallModel):- with sqlite3.connect(".local.sqlite") as db:+ with sqlite3.connect(CONFIG.database.sqlite_path) as db:db.execute("INSERT OR REPLACE INTO calls VALUES (?, ?, ?, ?)",(@@ -953,7 +953,7 @@ def save_call(call: CallModel):def get_call_by_id(call_id: UUID) -> Optional[CallModel]:- with sqlite3.connect(".local.sqlite") as db:+ with sqlite3.connect(CONFIG.database.sqlite_path) as db:cursor = db.execute("SELECT data FROM calls WHERE id = ?",(call_id.hex,),@@ -963,7 +963,7 @@ def get_call_by_id(call_id: UUID) -> Optional[CallModel]:def get_last_call_by_phone_number(phone_number: str) -> Optional[CallModel]:- with sqlite3.connect(".local.sqlite") as db:+ with sqlite3.connect(CONFIG.database.sqlite_path) as db:cursor = db.execute(f"SELECT data FROM calls WHERE phone_number = ? AND DATETIME(created_at) > DATETIME('now', '-{CONFIG.workflow.conversation_timeout_hour} hours') ORDER BY created_at DESC LIMIT 1",(phone_number,),