Skip to content

Commit

Permalink
Working packaging (#16)
Browse files Browse the repository at this point in the history
* Poetry WIP

* Working package management

* Updated README

* Building dockerfile

* Updated dependencies
  • Loading branch information
valentinyanakiev authored Aug 3, 2023
1 parent 212309c commit 42db637
Show file tree
Hide file tree
Showing 8 changed files with 2,057 additions and 38 deletions.
3 changes: 1 addition & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
},
"python.formatting.provider": "none",
"python.analysis.typeCheckingMode": "basic"
"python.formatting.provider": "none"
}
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ FROM python:3-slim-bookworm
# Set the working directory in the container to /app
WORKDIR /app

# Install Poetry
RUN pip install poetry

# Copy the current directory contents into the container at /app
COPY . /app

# install chromium-driver
RUN apt update && apt install chromium-driver -y

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Use Poetry to install dependencies
RUN poetry config virtualenvs.create true && poetry install --no-interaction --no-ansi

# Run app.py when the container launches
CMD ["python", "app.py"]
CMD ["poetry", "run", "python", "app.py"]
30 changes: 10 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,8 @@ Training a LLM is prohibitatively expensive for most organisations, but for most

## Implementation

The projects has been implemented as a container based micro-service with a RabbitMQ RPC. There are two RabbitMQ queues:
- `alkemio-chatbot-request` - queue for submitting requests to the microservice
- `alkemio-chatbot-response` - queue for receiving responses from the microservice

Request need to be submitted with the following properties:
- `correlation_id` - a unique correlation id for a specific user
- `reply_to` - name of the response queue (`alkemio-chatbot-response`)
The projects has been implemented as a container based micro-service with a RabbitMQ RPC. There is one RabbitMQ queue:
- `alkemio-chat-guidance` - queue for submitting requests to the microservice

The request payload consists of json with the following structure `{"operation" : "*operation type*", "param": "*addition request data*"}

Expand All @@ -36,9 +31,7 @@ The operation types are:
- `reset`: reset the chat history for the ongoing chat, no *addition request data*.
- `query`: post the next question in a chat sequence, with user question as *addition request data*

The response is published in the `alkemio-chatbot-response`.

The microservice expects a RabbitMQ server to be available on the specified host with no authentication requirements and the default port 5672.
The response is published in an auto-generated, exclusive, unnamed queue.

*note: there is an earlier (outdated) RESTful implementation available at https://github.com/alkem-io/poc-genai-api/tree/http-api

Expand All @@ -47,7 +40,7 @@ The following command can be used to build the container from the Docker CLI:
`docker build -t genai-api . `

The following command can be used to start the container from the Docker CLI:
`docker run --name genai-api -v /dev/shm:/dev/shm -p 5672:5672 -e "OPENAI_API_KEY=$OPENAI_API_KEY" -e "RABBITMQ_HOST=$RABBITMQ_HOST" genai-api`
`docker run --name genai-api -v /dev/shm:/dev/shm -v .env genai-api`

with:
- `OPENAI_API_KEY`: a valid OpenAI API key
Expand All @@ -64,17 +57,14 @@ with:

You can find sample values in `.azure-template.env` and `.openai-template.env`. Configure them and create `.env` file with the updated settings.

### Python
The required Python packages are listed in the `requirements.txt` file.
### Python & Poetry
The project requires Python & Poetry installed. The minimum version dependencies can be found at `pyproject.toml`.
After installing Python & Poetry, you simply need to run `poetry run python app.py`

### Linux
The project required Python 3.10 as a minimum and the chromium driver is required for scraing of the Alkemio website:
install Chromium-driver: `sudo apt-get install chromium-driver`

## Outstanding tasks
This Proof of Concept is functional, but morework is required to make it production ready, including:
- make it deployable on Kubernetes.
- improve the LLM performance (e.g. chunck sizes, LLM parameters, prompt template).
- improve security and error handling.
- improve the comments in the code and code optimsation.
- add additional configuration options (e.g. easy switch between OpenAI and Azure OpenAI, target website)
Note: make sure the version of the driver of chromium-driver is compatible with your chrome version. Otherwise, in order for this to work, you will need to:
- re-install chrome / chromium driver to match the versions
- uninstall chrome
2 changes: 0 additions & 2 deletions ai_utils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
from langchain.prompts.prompt import PromptTemplate
from langchain.embeddings import OpenAIEmbeddings
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.question_answering import load_qa_chain
from langchain.vectorstores import FAISS
from langchain.chat_models import ChatOpenAI
from langchain.llms import AzureOpenAI

import os
Expand Down
1 change: 1 addition & 0 deletions def_ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def mainapp() -> None:
Returns:
N/A
"""

# Site maps for the Alkemio website
sitemap_url_list = [
"https://www.alkemio.org/sitemap.xml",
Expand Down
Loading

0 comments on commit 42db637

Please sign in to comment.