i-dot-ai / redbox

Bringing Generative AI to the way the Civil Service works
https://i-dot-ai.github.io/redbox/
MIT License
83 stars 27 forks source link
chat-application docker-compose embeddings generative-ai government parsing prompt-engineering queue-workers rag summarization

Integration Tests

📮 Redbox

[!IMPORTANT] Incubation Project: This project is an incubation project; as such, we DON’T recommend using it in any critical use case. This project is in active development and a work in progress. This project may one day Graduate, in which case this disclaimer will be removed.

[!NOTE] The original streamlit-app has moved to its own repository https://github.com/i-dot-ai/redbox-copilot-streamlit.

Redbox is a retrieval augmented generation (RAG) app that uses GenAI to chat with and summarise civil service documents. It's designed to handle a variety of administrative sources, such as letters, briefings, minutes, and speech transcripts.

https://github.com/i-dot-ai/redbox-copilot/assets/8233643/e7984242-1403-4c93-9e68-03b3f065b38d

Setup

Please refer to the DEVELOPER_SETUP.md for detailed instructions on setting up the project.

Codespace

For a quick start, you can use GitHub Codespaces to run the project in a cloud-based development environment. Click the button below to open the project in a new Codespace.

Open in GitHub Codespaces

Development

You will need to install poppler and tesseract to run the worker

Testing

Dependencies

This project uses a microservice architecture.

Each microservice runs in its own container defined by a Dockerfile.

For every microservice that we have written in python we define its dependencies using https://python-poetry.org/.

This means that our project is structured approximately like this:

redbox/
├── django_app
│  ├── app/
│  ├── static/
│  ├── tests/
│  ├── manage.py
│  ├── pyproject.toml
│  └── Dockerfile
├── worker
│  ├── src/
│  │  └── app.py
│  ├── tests/
│  ├── pyproject.toml
│  └── Dockerfile
├── core-api
│  ├── src/
│  │  └── app.py
│  ├── tests/
│  ├── pyproject.toml
│  └── Dockerfile
├── redbox-core/
│  ├── redbox
│  │  ├── loader/
│  │  ├── models/
│  │  └── storage/
│  ├── tests/
│  ├── pyproject.toml
│  └── Dockerfile
├── docker-compose.yaml
├── pyproject.toml
├── Makefile
└── README.md

Configuration

System-wide, static, settings are defined Settings.py, these are set via environment file .env

Dynamic, per-request, settings are defined in AISettings.py, these are set within the django-app, and can be changed by an administrator. This includes the LLM to use which by default will be GPT-4o.

Contributing

We welcome contributions to this project. Please see the CONTRIBUTING.md file for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Security

[!IMPORTANT] The core-api is the http-gateway to the backend. Currently, this is unsecured, you should only run this on a private network.

However:

You can generate your JWT using the following snippet. Note that you whilst you can use a more secure key than an empty string this is currently not verified.

from jose import jwt
import requests

my_uuid = "a93a8f40-f261-4f12-869a-2cea3f3f0d71"
token = jwt.encode({"user_uuid": my_uuid}, key="")

requests.get(..., headers={"Authorization": f"Bearer {token}"})

You can find a link to a notebook on how to generate a JWT in the here.

If you discover a security vulnerability within this project, please follow our Security Policy.

Troubleshooting

Error: Elasticsearch 137

ERROR: Elasticsearch exited unexpectedly, with exit code 137

This is caused by Elasticsearch not having enough memory.

Increase total memory available to 8gb.

colima down
colima start --memory 8

Error: Docker... no space left on device

docker: /var/lib/... no space left on device

This is caused by your own laptop being too full to create a new image.

Clear out old docker artefacts:

docker system prune --all --force

Frontend

To build the frontend assets, from the django_app/frontend/ folder run:

npm install

Then, for a one-off build run:

npx parcel build

Or, to watch for changes (e.g. if making CSS and JS changes):

npx parcel watch

On initial app setup you will need to run poetry run python manage.py collectstatic to copy them to the frontend folder from where runserver can serve them. Or you can run make build-django-static which combines the parcel build and collectstatic commands.

How to deploy

checkout the main branch of the following repos:

If, and only if, you want to deploy something other than HEAD then replace var.image_tag in infrastructure/aws/ecs.tf with the hash of the build you want deployed.

Now run the commands below remembering to replace ENVIRONMENT with dev, preprod or prod

cd redbox
make tf_init
make tf_apply env=<ENVIRONMENT>