Skip to content

Commit

Permalink
Dockerize search app
Browse files Browse the repository at this point in the history
  • Loading branch information
ivarflakstad committed Mar 12, 2024
1 parent 676d045 commit 065932a
Show file tree
Hide file tree
Showing 12 changed files with 4,982 additions and 60 deletions.
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 `

- 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)
}
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 065932a

Please sign in to comment.