fix packaging and imports and introduce tests with pytest.

still issues with celery worker.
pull/300/head
Anton Larin 9 months ago
parent 98a97f34f5
commit 85f9ae5a0a

@ -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

@ -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"]

@ -68,19 +68,20 @@ if platform.system() == "Windows":
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
@ -92,7 +93,7 @@ app.config["CELERY_BROKER_URL"] = settings.CELERY_BROKER_URL
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"]
@ -129,6 +130,7 @@ def get_vectorstore(data):
vectorstore = ""
else:
vectorstore = ""
vectorstore = os.path.join("application", vectorstore)
return vectorstore

@ -1,37 +0,0 @@
from application.app import get_vectorstore
# Test cases for get_vectorstore function
def test_no_active_docs():
data = {}
assert get_vectorstore(data) == ""
def test_default_active_docs():
data = {"active_docs": "default"}
assert get_vectorstore(data) == ""
def test_local_default_active_docs():
data = {"active_docs": "local/default"}
assert get_vectorstore(data) == ""
def test_local_custom_active_docs():
data = {"active_docs": "local/custom_index"}
assert get_vectorstore(data) == "indexes/local/custom_index"
def test_remote_active_docs():
data = {"active_docs": "remote_index"}
assert get_vectorstore(data) == "vectors/remote_index"
def test_active_docs_not_in_data():
data = {"other_key": "value"}
assert get_vectorstore(data) == ""
def test_multiple_slashes_in_active_docs():
data = {"active_docs": "local/some/other/index"}
assert get_vectorstore(data) == "indexes/local/some/other/index"

@ -13,7 +13,6 @@ services:
backend:
build: ./application
working_dir: /application
environment:
- API_KEY=$OPENAI_API_KEY
- EMBEDDINGS_KEY=$OPENAI_API_KEY
@ -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

@ -13,7 +13,6 @@ services:
backend:
build: ./application
working_dir: /application
environment:
- API_KEY=$OPENAI_API_KEY
- EMBEDDINGS_KEY=$OPENAI_API_KEY
@ -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

@ -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")
Loading…
Cancel
Save