Trustworthy Language Model app - a standalone web application for serving the TLM model.
To set up the development environment, you need the following pre-requisites:
- Docker: To run the service and its dependencies.
- Tilt: To run the development environment.
- Kind: To run the Kubernetes cluster.
Additionally, you should have a .env file created using the .env.example file as a reference in each service directory.
Note -- the values of the .env files should not be quoted.
To run tests, run ./scripts/test.sh <service>.
For now, the chat backend is the only service that has tests (./scripts/test.sh chat-backend).
You can add additional arguments to the script by adding them to the test invocation command. See the below examples:
./scripts/test.sh chat-backend tests/routers/test_chat.py # just run the tests in test_chat.py
./scripts/test.sh chat-backend --pdb # open breakpoint on errors
./scripts/test.sh chat-backend -s # forward all stdout
To run the application locally, we will use kind and tilt to run a local Kubernetes cluster and deploy the application to it.
To create the cluster, run kind create cluster --name tlm-app.
To deploy the application, run tilt up.
You should not need to manually rebuild the image at any point, as Tilt will live update the running container with any changes you make to the code.
The application will be available at http://localhost:8080.
This service is built using the FastAPI framework and is designed to be deployed as a Docker container. The service is designed to be stateless and can be scaled horizontally to handle increased load.
The service is built using the following components:
- FastAPI: An ASGI web framework with strong support for type annotations, validation, and automatic API documentation generation.
- Pydantic: A data validation and parsing library for Python.
For example purposes, this service also includes a Postgres database and a Redis cache. These components are not required for the service to run, but are included to demonstrate how to integrate these components into the service.
The service is organized as follows (with all relevant code in the services directory):
.devcontainer: A directory containing configuration files for the VSCode development container. This directory is used to configure the development environment when using the Remote - Containers extension in VSCode.services/*/Dockerfile: The Dockerfile used to build the service container.services/*/requirements.txt: A list of Python dependencies required by the service.services/*/scripts/: A directory containing scripts used to manage the service. This includes scripts for running the application, running tests (TODO), and running database migrations.services/*/src/app.py: The main entry point for the FastAPI application.services/*/src/routers/: The directory containing the FastAPI router definitions. This is where the API endpoints are defined. Each router corresponds to a different part of the API, similar to a blueprint in Flask.services/*/src/schemas/: The directory containing the Pydantic schema definitions. This is where the request and response schemas are defined. The schemas are used to validate and parse incoming and outgoing data.services/*/src/dependencies/: The directory containing the dependency definitions. This is where the dependencies used by the routers are defined. Dependencies can be used to perform common tasks such as authentication, acquiring database connections, etc.
API documentation is automatically generated by FastAPI and is available at http://localhost:8080/api/docs. This page provides an interactive interface for testing the API endpoints.
SonarQube is used to scan the code for quality issues. The project key is TLM-app.
Scans are run automatically in CI on the main branch. You can view the results on our hosted SonarQube instance.
The URL and credentials can be found in AWS Secrets Manager.