Skip to content

Commit

Permalink
chore: Re-organise project structure
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Oct 9, 2024
1 parent 05cbe24 commit 66c5ad4
Show file tree
Hide file tree
Showing 79 changed files with 252 additions and 250 deletions.
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ USER appuser
COPY --from=build /venv /venv
ENV PATH=/venv/bin:$PATH

COPY --chown=appuser:appuser . /app
COPY --chown=appuser:appuser /app /app/

WORKDIR /app

CMD ["bash", "-c", "gunicorn main:api --bind 0.0.0.0:8080 --proxy-protocol --workers 4 --worker-class uvicorn.workers.UvicornWorker"]
CMD ["bash", "-c", "gunicorn app.main:api --bind 0.0.0.0:8080 --proxy-protocol --workers 4 --worker-class uvicorn.workers.UvicornWorker"]
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,15 @@ tunnel:
devtunnel host $(tunnel_name)

dev:
VERSION=$(version_full) PUBLIC_DOMAIN=$(tunnel_url) python3 -m gunicorn main:api \
VERSION=$(version_full) PUBLIC_DOMAIN=$(tunnel_url) python3 -m gunicorn app.main:api \
--access-logfile - \
--bind 0.0.0.0:8080 \
--proxy-protocol \
--reload \
--reload-extra-file .env \
--reload-extra-file config.yaml \
--workers 2 \
--worker-class uvicorn.workers.UvicornWorker
--worker-class uvicorn.workers.UvicornWorker \
--workers 2

build:
$(docker) build \
Expand Down Expand Up @@ -145,11 +145,11 @@ deploy-bicep:
'openaiLocation=$(openai_location)' \
'promptContentFilter=$(prompt_content_filter)' \
'searchLocation=$(search_location)' \
--template-file bicep/main.bicep \
--template-file cicd/bicep/main.bicep \
--name $(name_sanitized)

deploy-post:
@$(MAKE) copy-resources \
@$(MAKE) copy-public \
name=$(blob_storage_public_name)

@$(MAKE) twilio-register \
Expand Down Expand Up @@ -180,16 +180,16 @@ twilio-register:
twilio phone-numbers:update $(twilio_phone_number) \
--sms-url $(endpoint)/twilio/sms

copy-resources:
@echo "📦 Copying resources to Azure storage account..."
copy-public:
@echo "📦 Copying public resources..."
az storage blob upload-batch \
--account-name $(name_sanitized) \
--auth-mode login \
--destination '$$web' \
--no-progress \
--output none \
--overwrite \
--source resources
--source public

watch-call:
@echo "👀 Watching status of $(phone_number)..."
Expand Down
File renamed without changes.
22 changes: 11 additions & 11 deletions helpers/call_events.py → app/helpers/call_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
from azure.core.exceptions import ClientAuthenticationError, HttpResponseError
from pydantic import ValidationError

from helpers.call_llm import load_llm_chat
from helpers.call_utils import (
from app.helpers.call_llm import load_llm_chat
from app.helpers.call_utils import (
ContextEnum as CallContextEnum,
handle_clear_queue,
handle_hangup,
Expand All @@ -23,22 +23,22 @@
handle_recognize_text,
handle_transfer,
)
from helpers.config import CONFIG
from helpers.features import recording_enabled, voice_recognition_retry_max
from helpers.llm_worker import completion_sync
from helpers.logging import logger
from helpers.monitoring import CallAttributes, span_attribute, tracer
from models.call import CallStateModel
from models.message import (
from app.helpers.config import CONFIG
from app.helpers.features import recording_enabled, voice_recognition_retry_max
from app.helpers.llm_worker import completion_sync
from app.helpers.logging import logger
from app.helpers.monitoring import CallAttributes, span_attribute, tracer
from app.models.call import CallStateModel
from app.models.message import (
ActionEnum as MessageActionEnum,
MessageModel,
PersonaEnum as MessagePersonaEnum,
StyleEnum as MessageStyleEnum,
extract_message_style,
remove_message_action,
)
from models.next import NextModel
from models.synthesis import SynthesisModel
from app.models.next import NextModel
from app.models.synthesis import SynthesisModel

_sms = CONFIG.sms.instance()
_db = CONFIG.database.instance()
Expand Down
18 changes: 9 additions & 9 deletions helpers/call_llm.py → app/helpers/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
from azure.communication.callautomation.aio import CallAutomationClient
from openai import APIError

from helpers.call_utils import (
from app.helpers.call_utils import (
handle_clear_queue,
handle_media,
handle_recognize_text,
tts_sentence_split,
)
from helpers.config import CONFIG
from helpers.features import answer_hard_timeout_sec, answer_soft_timeout_sec
from helpers.llm_tools import LlmPlugins
from helpers.llm_worker import (
from app.helpers.config import CONFIG
from app.helpers.features import answer_hard_timeout_sec, answer_soft_timeout_sec
from app.helpers.llm_tools import LlmPlugins
from app.helpers.llm_worker import (
MaximumTokensReachedError,
SafetyCheckError,
completion_stream,
)
from helpers.logging import logger
from helpers.monitoring import tracer
from models.call import CallStateModel
from models.message import (
from app.helpers.logging import logger
from app.helpers.monitoring import tracer
from app.models.call import CallStateModel
from app.models.message import (
ActionEnum as MessageAction,
MessageModel,
PersonaEnum as MessagePersonaEnum,
Expand Down
10 changes: 5 additions & 5 deletions helpers/call_utils.py → app/helpers/call_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
)
from azure.core.exceptions import HttpResponseError, ResourceNotFoundError

from helpers.config import CONFIG
from helpers.features import phone_silence_timeout_sec
from helpers.logging import logger
from models.call import CallStateModel
from models.message import (
from app.helpers.config import CONFIG
from app.helpers.features import phone_silence_timeout_sec
from app.helpers.logging import logger
from app.models.call import CallStateModel
from app.models.message import (
MessageModel,
PersonaEnum as MessagePersonaEnum,
StyleEnum as MessageStyleEnum,
Expand Down
2 changes: 1 addition & 1 deletion helpers/config.py → app/helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from dotenv import find_dotenv
from pydantic import ValidationError

from helpers.config_models.root import RootModel
from app.helpers.config_models.root import RootModel


class ConfigNotFound(Exception):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel, Field

from persistence.isearch import ISearch
from app.persistence.isearch import ISearch


class AiSearchModel(BaseModel, frozen=True):
Expand All @@ -15,8 +15,8 @@ class AiSearchModel(BaseModel, frozen=True):

@cache
def instance(self) -> ISearch:
from helpers.config import CONFIG
from persistence.ai_search import (
from app.helpers.config import CONFIG
from app.persistence.ai_search import (
AiSearchSearch,
)

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel, Field, SecretStr, ValidationInfo, field_validator

from persistence.icache import ICache
from app.persistence.icache import ICache


class ModeEnum(str, Enum):
Expand All @@ -16,7 +16,7 @@ class MemoryModel(BaseModel, frozen=True):

@cache
def instance(self) -> ICache:
from persistence.memory import (
from app.persistence.memory import (
MemoryCache,
)

Expand All @@ -32,7 +32,7 @@ class RedisModel(BaseModel, frozen=True):

@cache
def instance(self) -> ICache:
from persistence.redis import (
from app.persistence.redis import (
RedisCache,
)

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, SecretStr

from helpers.pydantic_types.phone_numbers import PhoneNumber
from app.helpers.pydantic_types.phone_numbers import PhoneNumber


class CommunicationServicesModel(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
from pydantic import BaseModel, ConfigDict, EmailStr, Field, create_model
from pydantic.fields import FieldInfo

from helpers.pydantic_types.phone_numbers import PhoneNumber
from models.claim import ClaimFieldModel, ClaimTypeEnum
from app.helpers.pydantic_types.phone_numbers import PhoneNumber
from app.models.claim import ClaimFieldModel, ClaimTypeEnum


class LanguageEntryModel(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel, ValidationInfo, field_validator

from persistence.istore import IStore
from app.persistence.istore import IStore


class ModeEnum(str, Enum):
Expand All @@ -18,8 +18,8 @@ class CosmosDbModel(BaseModel, frozen=True):

@cache
def instance(self) -> IStore:
from helpers.config import CONFIG
from persistence.cosmos_db import (
from app.helpers.config import CONFIG
from app.persistence.cosmos_db import (
CosmosDbStore,
)

Expand All @@ -41,8 +41,8 @@ def full_path(self) -> str:

@cache
def instance(self) -> IStore:
from helpers.config import CONFIG
from persistence.sqlite import (
from app.helpers.config import CONFIG
from app.persistence.sqlite import (
SqliteStore,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from openai import AsyncAzureOpenAI, AsyncOpenAI
from pydantic import BaseModel, Field, SecretStr, ValidationInfo, field_validator

from helpers.identity import token
from app.helpers.identity import token


class ModeEnum(str, Enum):
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
from openai.types.chat import ChatCompletionSystemMessageParam
from pydantic import BaseModel, TypeAdapter

from models.call import CallStateModel
from models.message import MessageModel
from models.next import NextModel
from models.reminder import ReminderModel
from models.synthesis import SynthesisModel
from models.training import TrainingModel
from app.models.call import CallStateModel
from app.models.message import MessageModel
from app.models.next import NextModel
from app.models.reminder import ReminderModel
from app.models.synthesis import SynthesisModel
from app.models.training import TrainingModel


class SoundModel(BaseModel):
loading_tpl: str = "{public_url}/loading.wav"
ready_tpl: str = "{public_url}/ready.wav"

def loading(self) -> str:
from helpers.config import CONFIG
from app.helpers.config import CONFIG

return self.loading_tpl.format(
public_url=CONFIG.resources.public_url,
)

def ready(self) -> str:
from helpers.config import CONFIG
from app.helpers.config import CONFIG

return self.ready_tpl.format(
public_url=CONFIG.resources.public_url,
Expand Down Expand Up @@ -319,7 +319,7 @@ class LlmModel(BaseModel):
"""

def default_system(self, call: CallStateModel) -> str:
from helpers.config import CONFIG
from app.helpers.config import CONFIG

return self._format(
self.default_system_tpl.format(
Expand All @@ -336,7 +336,7 @@ def default_system(self, call: CallStateModel) -> str:
def chat_system(
self, call: CallStateModel, trainings: list[TrainingModel]
) -> list[ChatCompletionSystemMessageParam]:
from models.message import (
from app.models.message import (
ActionEnum as MessageActionEnum,
StyleEnum as MessageStyleEnum,
)
Expand Down Expand Up @@ -485,7 +485,7 @@ def _messages(

@cached_property
def logger(self) -> Logger:
from helpers.logging import logger
from app.helpers.logging import logger

return logger

Expand Down Expand Up @@ -542,7 +542,7 @@ async def timeout_silence(self, call: CallStateModel) -> str:
return await self._translate(self.timeout_silence_tpl, call)

async def welcome_back(self, call: CallStateModel) -> str:
from helpers.features import callback_timeout_hour
from app.helpers.features import callback_timeout_hour

return await self._translate(
self.welcome_back_tpl,
Expand Down Expand Up @@ -580,7 +580,7 @@ async def _translate(self, prompt_tpl: str, call: CallStateModel, **kwargs) -> s
If the translation fails, the initial prompt is returned.
"""
from helpers.translation import (
from app.helpers.translation import (
translate_text,
)

Expand All @@ -597,7 +597,7 @@ async def _translate(self, prompt_tpl: str, call: CallStateModel, **kwargs) -> s

@cached_property
def logger(self) -> Logger:
from helpers.logging import logger
from app.helpers.logging import logger

return logger

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class QueueModel(BaseModel, frozen=True):

@cache
def call(self):
from persistence.azure_queue_storage import AzureQueueStorage
from app.persistence.azure_queue_storage import AzureQueueStorage

return AzureQueueStorage(
account_url=self.account_url,
Expand All @@ -21,7 +21,7 @@ def call(self):

@cache
def post(self):
from persistence.azure_queue_storage import AzureQueueStorage
from app.persistence.azure_queue_storage import AzureQueueStorage

return AzureQueueStorage(
account_url=self.account_url,
Expand All @@ -30,7 +30,7 @@ def post(self):

@cache
def sms(self):
from persistence.azure_queue_storage import AzureQueueStorage
from app.persistence.azure_queue_storage import AzureQueueStorage

return AzureQueueStorage(
account_url=self.account_url,
Expand All @@ -39,7 +39,7 @@ def sms(self):

@cache
def training(self):
from persistence.azure_queue_storage import AzureQueueStorage
from app.persistence.azure_queue_storage import AzureQueueStorage

return AzureQueueStorage(
account_url=self.account_url,
Expand Down
File renamed without changes.
Loading

0 comments on commit 66c5ad4

Please sign in to comment.