Skip to content

Commit

Permalink
Merge pull request #1 from curieo-org/dockerization
Browse files Browse the repository at this point in the history
Dockerize search app
  • Loading branch information
raahulrahl authored Mar 12, 2024
2 parents 676d045 + 25fbcf8 commit 498754d
Show file tree
Hide file tree
Showing 14 changed files with 5,039 additions and 75 deletions.
23 changes: 7 additions & 16 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@ name: Tests

on:
push:
pull_request:

jobs:
tests:
runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: ["3.10", "3.11"]

services:
postgres:
Expand All @@ -24,19 +19,15 @@ jobs:
options: --health-cmd pg_isready --health-interval 5s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v2

- name: Setup Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
- uses: actions/checkout@v4
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: '**/requirements/development.txt'
cache: 'poetry'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r app/requirements/development.txt
run: poetry install

- name: Run tests
env:
Expand All @@ -45,4 +36,4 @@ jobs:
DB_USER: postgres
DB_PASS: postgres
DB_BASE: db_test
run: cd app && pytest .
run: cd app && poetry run pytest
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,4 @@ cython_debug/
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.idea/
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.11
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# pull official base image
FROM python:3.11-slim

# install system dependencies
RUN apt-get update && apt-get -y install libpq-dev gcc


# install python dependencies
COPY ./pyproject.toml /
COPY ./poetry.lock /
RUN pip install poetry uvicorn
RUN poetry config virtualenvs.create false
RUN poetry install --compile

COPY ./app /app
COPY .env /.env

EXPOSE 8000

CMD ["uvicorn", "app.main:app", "--host=0.0.0.0", "--port", "80"]
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,16 @@ The project might have multiple branches: `master`, `development`, etc. which ca
```

### Tools Required

- A text editor or an IDE (VsCode is Preferred)

### Installation

All installation steps go here.

- Install `poetry` for the dependencies. - `poetry install`
- Make sure `pyenv` is installed.
- Create a new virtual environment `python -m venv .venv`
- Activate the env `source .venv/bin/activate`
- Install poetry and uvicorn `pip install poetry uvicorn`
- Install dependencies `poetry install`
- Now you can run the project with `uvicorn app.main:app --reload`

- Set up Embedding Server from [TEI](https://github.com/huggingface/text-embeddings-inference/tree/main)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@
from typing import List
from sqlalchemy import create_engine
from pyvis.network import Network
import phoenix as px

from app.config import OPENAPI_KEY, CLINICAL_TRIALS_TABLE_INFO_DIR, POSTGRES_ENGINE, EMBEDDING_MODEL_API, EMBEDDING_MODEL_NAME
from app.services.search_utility import setup_logger

logger = setup_logger('ClinicalTrialText2SQLEngine')

#px.launch_app(port=6060)

class TableInfo(BaseModel):
"""
Information regarding a structured table.
Expand All @@ -47,7 +44,7 @@ class ClinicalTrialText2SQLEngine:
"""
def __init__(self, config):
self.config = config

self.llm = OpenAI(model="gpt-3.5-turbo", api_key=str(OPENAPI_KEY))
self.engine = create_engine(str(POSTGRES_ENGINE))

Expand All @@ -56,8 +53,8 @@ def __init__(self, config):
self.sql_database = SQLDatabase(self.engine)
self.table_node_mapping = SQLTableNodeMapping(self.sql_database)
self.sql_retriever = SQLRetriever(self.sql_database)
self.table_schema_objs = [SQLTableSchema(table_name=t.table_name, context_str=t.table_summary) for t in self.get_all_table_info()]

self.table_schema_objs = [SQLTableSchema(table_name=t.table_name, context_str=t.table_summary) for t in self.get_all_table_info()]
self.embed_model = TextEmbeddingsInference(base_url=EMBEDDING_MODEL_API, model_name=EMBEDDING_MODEL_NAME)

self.obj_index = ObjectIndex.from_objects(objects=self.table_schema_objs, object_mapping=self.table_node_mapping, index_cls=VectorStoreIndex, embed_model=self.embed_model)
Expand Down Expand Up @@ -85,7 +82,7 @@ def _get_table_info_with_index(self, idx: int) -> str:
raise ValueError(
f"More than one file matching index: {list(results_gen)}"
)

def get_all_table_info(self):
file_counts = len(os.listdir(CLINICAL_TRIALS_TABLE_INFO_DIR))
table_infos = []
Expand Down Expand Up @@ -122,7 +119,7 @@ def parse_response_to_sql(self, response: ChatResponse) -> str:
response = response[:sql_result_start]
logger.debug(f"ClinicalTrialText2SQLEngine.parse_response_to_sql sql: {response}")
return response.strip().strip("```").strip()

def get_response_synthesis_prompt(self, query_str, sql_query, context_str) -> PromptTemplate:
response_synthesis_prompt_str = (
"Given an input question, synthesize a response from the query results.\n"
Expand Down Expand Up @@ -179,7 +176,7 @@ def call_text2sql(self, search_text:str):
except Exception as ex:
logger.exception("ClinicalTrialText2SQLEngine.call_text2sql Exception -", exc_info = ex, stack_info=True)
raise ex

return {
"result" : str(response)
}
2 changes: 2 additions & 0 deletions app/tests/test_stub.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def test_placeholder():
pass
6 changes: 1 addition & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
version: '3.8'

services:

web:
build:
context: .
dockerfile: docker/Dockerfile.local
command: ./scripts/docker-entrypoint.sh
volumes:
- ./app:/usr/src/app
dockerfile: Dockerfile
ports:
- 8000:8000
depends_on:
Expand Down
21 changes: 0 additions & 21 deletions docker/Dockerfile.local

This file was deleted.

Loading

0 comments on commit 498754d

Please sign in to comment.