diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 412aca1..3ac8714 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -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 diff --git a/application/Dockerfile b/application/Dockerfile index 1285972..8c08392 100644 --- a/application/Dockerfile +++ b/application/Dockerfile @@ -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"] diff --git a/application/app.py b/application/app.py index 5d5a1e5..3ba2de6 100644 --- a/application/app.py +++ b/application/app.py @@ -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 diff --git a/application/tests/__init__.py b/application/tests/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/application/tests/test_app.py b/application/tests/test_app.py deleted file mode 100644 index 5bd3e4f..0000000 --- a/application/tests/test_app.py +++ /dev/null @@ -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" diff --git a/docker-compose-azure.yaml b/docker-compose-azure.yaml index e13d6dd..70a1680 100644 --- a/docker-compose-azure.yaml +++ b/docker-compose-azure.yaml @@ -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 diff --git a/docker-compose.yaml b/docker-compose.yaml index 9eb42bb..d5dd10e 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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 diff --git a/tests/test_app.py b/tests/test_app.py new file mode 100644 index 0000000..8ae9ee3 --- /dev/null +++ b/tests/test_app.py @@ -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")