Skip to content

Commit

Permalink
fix packaging and imports and introduce tests with pytest.
Browse files Browse the repository at this point in the history
still issues with celery worker.
  • Loading branch information
larinam committed Aug 14, 2023
1 parent 98a97f3 commit 85f9ae5
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 57 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ jobs:
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
cd application
pytest
python -m pytest
4 changes: 2 additions & 2 deletions application/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ FROM python:3.10-slim-bullseye
COPY --from=builder /usr/local/ /usr/local/

WORKDIR /app
COPY . /app
COPY . /app/application
ENV FLASK_APP=app.py
ENV FLASK_DEBUG=true

EXPOSE 7091

CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "wsgi:app"]
CMD ["gunicorn", "-w", "2", "--timeout", "120", "--bind", "0.0.0.0:7091", "application.wsgi:app"]
14 changes: 8 additions & 6 deletions application/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,20 @@
dotenv.load_dotenv()

# load the prompts
with open("prompts/combine_prompt.txt", "r") as f:
current_dir = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(current_dir, "prompts", "combine_prompt.txt"), "r") as f:
template = f.read()

with open("prompts/combine_prompt_hist.txt", "r") as f:
with open(os.path.join(current_dir, "prompts", "combine_prompt_hist.txt"), "r") as f:
template_hist = f.read()

with open("prompts/question_prompt.txt", "r") as f:
with open(os.path.join(current_dir, "prompts", "question_prompt.txt"), "r") as f:
template_quest = f.read()

with open("prompts/chat_combine_prompt.txt", "r") as f:
with open(os.path.join(current_dir, "prompts", "chat_combine_prompt.txt"), "r") as f:
chat_combine_template = f.read()

with open("prompts/chat_reduce_prompt.txt", "r") as f:
with open(os.path.join(current_dir, "prompts", "chat_reduce_prompt.txt"), "r") as f:
chat_reduce_template = f.read()

api_key_set = settings.API_KEY is not None
Expand All @@ -92,7 +93,7 @@
app.config["CELERY_RESULT_BACKEND"] = settings.CELERY_RESULT_BACKEND
app.config["MONGO_URI"] = settings.MONGO_URI
celery = Celery()
celery.config_from_object("celeryconfig")
celery.config_from_object("application.celeryconfig")
mongo = MongoClient(app.config["MONGO_URI"])
db = mongo["docsgpt"]
vectors_collection = db["vectors"]
Expand Down Expand Up @@ -129,6 +130,7 @@ def get_vectorstore(data):
vectorstore = ""
else:
vectorstore = ""
vectorstore = os.path.join("application", vectorstore)
return vectorstore


Expand Down
Empty file removed application/tests/__init__.py
Empty file.
37 changes: 0 additions & 37 deletions application/tests/test_app.py

This file was deleted.

8 changes: 3 additions & 5 deletions docker-compose-azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:

backend:
build: ./application
working_dir: /application
environment:
- API_KEY=$OPENAI_API_KEY
- EMBEDDINGS_KEY=$OPENAI_API_KEY
Expand All @@ -28,16 +27,15 @@ services:
ports:
- "7091:7091"
volumes:
- ./application/indexes:/application/indexes
- ./application/inputs:/application/inputs
- ./application/vectors:/application/vectors
- ./application/indexes:/app/application/indexes
- ./application/inputs:/app/application/inputs
- ./application/vectors:/app/application/vectors
depends_on:
- redis
- mongo

worker:
build: ./application
working_dir: /application
command: celery -A application.app.celery worker -l INFO
environment:
- API_KEY=$OPENAI_API_KEY
Expand Down
8 changes: 3 additions & 5 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ services:

backend:
build: ./application
working_dir: /application
environment:
- API_KEY=$OPENAI_API_KEY
- EMBEDDINGS_KEY=$OPENAI_API_KEY
Expand All @@ -23,16 +22,15 @@ services:
ports:
- "7091:7091"
volumes:
- ./application/indexes:/application/indexes
- ./application/inputs:/application/inputs
- ./application/vectors:/application/vectors
- ./application/indexes:/app/application/indexes
- ./application/inputs:/app/application/inputs
- ./application/vectors:/app/application/vectors
depends_on:
- redis
- mongo

worker:
build: ./application
working_dir: /application
command: celery -A application.app.celery worker -l INFO
environment:
- API_KEY=$OPENAI_API_KEY
Expand Down
28 changes: 28 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from application.app import get_vectorstore
import os


# Test cases for get_vectorstore function
def test_no_active_docs():
data = {}
assert get_vectorstore(data) == os.path.join("application", "")


def test_local_default_active_docs():
data = {"active_docs": "local/default"}
assert get_vectorstore(data) == os.path.join("application", "")


def test_local_non_default_active_docs():
data = {"active_docs": "local/something"}
assert get_vectorstore(data) == os.path.join("application", "indexes/local/something")


def test_default_active_docs():
data = {"active_docs": "default"}
assert get_vectorstore(data) == os.path.join("application", "")


def test_complex_active_docs():
data = {"active_docs": "local/other/path"}
assert get_vectorstore(data) == os.path.join("application", "indexes/local/other/path")

0 comments on commit 85f9ae5

Please sign in to comment.