Skip to content

Commit

Permalink
chore: refactor configuration (#185)
Browse files Browse the repository at this point in the history
* refactor configurations

* more refactoring
  • Loading branch information
alfredfrancis authored Jan 26, 2025
1 parent e7f6c8d commit b81df3f
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/evaluate-backend.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Evaluate
name: Evaluate Backend

on:
push:
Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/relase-backend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Release Backend

on:
push:
branches:
- master
release:
types: [published]

Expand Down
3 changes: 0 additions & 3 deletions .github/workflows/relase-frontend.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
name: Release Frontend

on:
push:
branches:
- master
release:
types: [published]

Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

11 changes: 3 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
FROM python:3.12.7-slim
FROM python:3.12-bullseye

WORKDIR /usr/src/app

# Install system dependencies
RUN apt-get update && apt-get install -y \
build-essential \
python3-dev \
&& rm -rf /var/lib/apt/lists/*
RUN pip install --upgrade pip

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . .

EXPOSE 80
Expand Down
2 changes: 1 addition & 1 deletion app/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
]

client = AsyncIOMotorClient(app_config.MONGODB_HOST)
database = client.get_database("iky-ai")
database = client.get_database(app_config.MONGODB_DATABASE)
10 changes: 4 additions & 6 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
class BaseConfig(BaseModel):
DEBUG: bool = False
Development: bool = False
MONGODB_HOST: str = "mongodb://127.0.0.1:27017/iky-ai"

# Intent Classifier model details
MONGODB_HOST: str = "mongodb://127.0.0.1:27017"
MONGODB_DATABASE: str = "ai-chatbot-framework"

MODELS_DIR: str = "model_files/"
INTENT_MODEL_NAME: str = "intent.model"
DEFAULT_FALLBACK_INTENT_NAME: str = "fallback"
DEFAULT_WELCOME_INTENT_NAME: str = "init_conversation"
USE_WORD_VECTORS: bool = True
SPACY_LANG_MODEL: str = "en_core_web_md"


Expand All @@ -31,8 +30,7 @@ class TestingConfig(BaseConfig):


class ProductionConfig(BaseConfig):
# MongoDB Database Details
MONGODB_HOST: str = "mongodb://mongodb:27017/iky-ai"
SPACY_LANG_MODEL: str = "en_core_web_lg"


config = {
Expand Down
10 changes: 4 additions & 6 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
version: '2'
name: ai-chatbot-framework-dev
services:
mongodb:
container_name: mongodb
image: mongo:4.2.20
hostname: mongodb
ports:
- "27017:27017"
volumes:
- mongodbdata:/data

Expand All @@ -17,7 +16,7 @@ services:
command: python manage.py migrate
environment:
APPLICATION_ENV: Development
APP_MONGODB_HOST: "mongodb://mongodb:27017/iky-ai"
MONGODB_HOST: mongodb://mongodb:27017
depends_on:
- mongodb

Expand All @@ -29,7 +28,7 @@ services:
command: fastapi run --host=0.0.0.0 --reload --port=8080
environment:
APPLICATION_ENV: Development
APP_MONGODB_HOST: "mongodb://mongodb:27017/iky-ai"
MONGODB_HOST: mongodb://mongodb:27017
ports:
- 8080:8080
volumes:
Expand All @@ -43,8 +42,7 @@ services:
hostname: frontend
build:
context: ./frontend
dockerfile: dev.Dockerfile

dockerfile: ./dev.Dockerfile
volumes:
- ./frontend/app:/app/app
- ./frontend/public:/app/public
Expand Down
3 changes: 3 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
version: '2'
name: ai-chatbot-framework
services:
migrate:
container_name: migrate
image: alfredfrancis/ai-chatbot-framework_backend:latest
command: python manage.py migrate
environment:
MONGODB_HOST: mongodb://mongodb:27017
APPLICATION_ENV: Production
depends_on:
- mongodb
Expand All @@ -25,6 +27,7 @@ services:
hostname: backend
restart: always
environment:
MONGODB_HOST: mongodb://mongodb:27017
APPLICATION_ENV: Production
ports:
- "8080:80"
Expand Down
2 changes: 1 addition & 1 deletion frontend/dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ RUN \

COPY app ./app
COPY public ./public
COPY next.config.js .
COPY next.config.ts .
COPY tsconfig.json .

# Next.js collects completely anonymous telemetry data about general usage. Learn more here: https://nextjs.org/telemetry
Expand Down
10 changes: 9 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import typer
import asyncio
from json import loads
import logging
import spacy
from pymongo.errors import DuplicateKeyError
from app.main import app
import logging

cli = typer.Typer()

Expand All @@ -17,6 +18,7 @@ async def async_migrate():
from app.admin.bots.store import add_bot
from app.admin.bots.store import import_bot
from app.admin.integrations.store import ensure_default_integrations
from app.config import app_config

try:
default_bot = Bot(name="default", config={"confidence_threshold": 0.85})
Expand All @@ -37,6 +39,12 @@ async def async_migrate():

await ensure_default_integrations()

# ensure spacy language models are installed
logger.info("Downloading spacy language models...")
spacy.cli.download(app_config.SPACY_LANG_MODEL)

logger.info("Migration finished.")

asyncio.run(async_migrate())


Expand Down
70 changes: 23 additions & 47 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,99 +3,75 @@ aiohttp==3.11.11
aiosignal==1.3.2
annotated-types==0.7.0
anyio==4.8.0
attrs==24.3.0
blis==1.1.0
attrs==25.1.0
blis==1.2.0
catalogue==2.0.10
certifi==2024.12.14
cfgv==3.4.0
charset-normalizer==3.4.1
click==8.1.8
cloudpathlib==0.20.0
cloudpickle==3.1.0
cloudpickle==3.1.1
confection==0.1.5
coverage==7.6.10
cymem==2.0.10
distlib==0.3.9
cymem==2.0.11
dnspython==2.7.0
en_core_web_md @ https://github.com/explosion/spacy-models/releases/download/en_core_web_md-3.8.0/en_core_web_md-3.8.0-py3-none-any.whl#sha256=5e6329fe3fecedb1d1a02c3ea2172ee0fede6cea6e4aefb6a02d832dba78a310
fastapi==0.115.6
email_validator==2.2.0
fastapi==0.115.7
fastapi-cli==0.0.7
filelock==3.16.1
frozenlist==1.5.0
h11==0.14.0
httpcore==1.0.7
httptools==0.6.4
identify==2.6.5
httpx==0.28.1
idna==3.10
iniconfig==2.0.0
Jinja2==3.1.5
joblib==1.4.2
langcodes==3.5.0
language_data==1.3.0
marisa-trie==1.2.1
markdown-it-py==3.0.0
MarkupSafe==3.0.2
mccabe==0.7.0
mdurl==0.1.2
mongoengine==0.29.1
motor==3.6.0
motor==3.6.1
multidict==6.1.0
murmurhash==1.0.11
mypy-extensions==1.0.0
nodeenv==1.9.1
numpy==2.2.1
murmurhash==1.0.12
numpy==2.2.2
packaging==24.2
pandas==2.2.3
pathspec==0.12.1
platformdirs==4.3.6
pluggy==1.5.0
pre_commit==4.0.1
preshed==3.0.9
propcache==0.2.1
pycodestyle==2.12.1
pydantic==2.10.5
pydantic==2.10.6
pydantic_core==2.27.2
pyflakes==3.2.0
Pygments==2.19.1
pymongo==4.9.2
pytest==8.0.0
pytest-asyncio==0.23.5
pytest-cov==4.1.0
pytest-mock==3.12.0
python-crfsuite==0.9.11
python-dateutil==2.9.0.post0
python-dotenv==1.0.1
python-multipart==0.0.20
pytz==2024.2
PyYAML==6.0.2
requests==2.32.3
rich==13.9.4
rich-toolkit==0.12.0
ruff==0.9.2
scikit-learn==1.6.0
scipy==1.15.0
rich-toolkit==0.13.2
scikit-learn==1.6.1
scipy==1.15.1
setuptools==75.8.0
shellingham==1.5.4
six==1.17.0
smart-open==7.1.0
sniffio==1.3.1
spacy==3.8.3
spacy==3.8.4
spacy-legacy==3.0.12
spacy-loggers==1.0.5
srsly==2.5.0
starlette==0.41.3
thinc==8.3.3
srsly==2.5.1
starlette==0.45.3
thinc==8.3.4
threadpoolctl==3.5.0
tqdm==4.67.1
typer==0.15.1
typing_extensions==4.12.2
tzdata==2024.2
urllib3==2.3.0
uvicorn==0.34.0
uvloop==0.21.0
virtualenv==20.29.1
wasabi==1.1.3
watchfiles==1.0.3
watchfiles==1.0.4
weasel==0.4.1
websockets==14.1
wrapt==1.17.0
websockets==14.2
wheel==0.45.1
wrapt==1.17.2
yarl==1.18.3

0 comments on commit b81df3f

Please sign in to comment.