Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Jan 20, 2024
1 parent dde9ff2 commit 29a4188
Showing 1 changed file with 14 additions and 22 deletions.
36 changes: 14 additions & 22 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -37,7 +36,7 @@
)
from models.claim import ClaimModel
from openai import AsyncAzureOpenAI
from uuid import UUID, uuid4
from uuid import UUID
import json


Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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",
Expand All @@ -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(
Expand Down

0 comments on commit 29a4188

Please sign in to comment.