diff --git a/main.py b/main.py index c0ada932..9287c4b3 100644 --- a/main.py +++ b/main.py @@ -16,7 +16,6 @@ from datetime import datetime from enum import Enum from fastapi import FastAPI, status, Request, HTTPException, BackgroundTasks -from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse, HTMLResponse from helpers.config import CONFIG from helpers.logging import build_logger @@ -37,7 +36,7 @@ ) from models.claim import ClaimModel from openai import AsyncAzureOpenAI -from uuid import UUID, uuid4 +from uuid import UUID import json @@ -46,13 +45,12 @@ ROOT_PATH = CONFIG.api.root_path AZ_CREDENTIAL = DefaultAzureCredential() -_logger.info(f'Using root path "{ROOT_PATH}"') - jinja = Environment( autoescape=select_autoescape(), enable_async=True, loader=FileSystemLoader("public_website"), ) +_logger.info(f"Using OpenAI GPT model {CONFIG.openai.gpt_model}") oai_gpt = AsyncAzureOpenAI( api_version="2023-12-01-preview", azure_deployment=CONFIG.openai.gpt_deployment, @@ -67,8 +65,8 @@ else None ), ) -eventgrid_subscription_name = f"tmp-{uuid4()}" source_caller = PhoneNumberIdentifier(CONFIG.communication_service.phone_number) +_logger.info(f"Using phone number {source_caller}") # Cannot place calls with RBAC, need to use access key (see: https://learn.microsoft.com/en-us/azure/communication-services/concepts/authentication#authentication-options) call_automation_client = CallAutomationClient( endpoint=CONFIG.communication_service.endpoint, @@ -79,22 +77,13 @@ sms_client = SmsClient( credential=AZ_CREDENTIAL, endpoint=CONFIG.communication_service.endpoint ) +_logger.info(f"Using database {CONFIG.database.mode}") db = ( SqliteStore(CONFIG.database.sqlite) if CONFIG.database.mode == DatabaseMode.SQLITE else CosmosStore(CONFIG.database.cosmos_db) ) - -CALL_EVENT_URL = f'{CONFIG.api.events_domain.strip("/")}/call/event' -CALL_INBOUND_URL = f'{CONFIG.api.events_domain.strip("/")}/call/inbound' - - -class Context(str, Enum): - TRANSFER_FAILED = "transfer_failed" - CONNECT_AGENT = "connect_agent" - GOODBYE = "goodbye" - - +_logger.info(f'Using root path "{ROOT_PATH}"') api = FastAPI( contact={ "url": "https://github.com/clemlesne/claim-ai-phone-bot", @@ -109,12 +98,15 @@ class Context(str, Enum): version=CONFIG.api.version, ) -api.add_middleware( - CORSMiddleware, - allow_headers=["*"], - allow_methods=["*"], - allow_origins=["*"], -) + +CALL_EVENT_URL = f'{CONFIG.api.events_domain.strip("/")}/call/event' +CALL_INBOUND_URL = f'{CONFIG.api.events_domain.strip("/")}/call/inbound' + + +class Context(str, Enum): + TRANSFER_FAILED = "transfer_failed" + CONNECT_AGENT = "connect_agent" + GOODBYE = "goodbye" @api.get(