This project is an API for ethical AI experimentation on texts, using Large Language Models (LLMs) served via Ollama.
This project uses uv for dependency management.
To run the application locally, use the following command:
uv run uvicorn src.ethicslab.main:app --reloadOnce the application is running, the API can be accessed at the following local addresses:
- API Root:
http://localhost:8000/ - API Docs:
http://localhost:8000/docs - Health Check:
http://localhost:8000/health - Chat Endpoint:
http://localhost:8000/api/chat/ - Tweet Endpoint:
http://localhost:8000/api/tweet/
For the /api/chat/ endpoint to work locally, you must have Ollama running on your local machine.
The application is designed to be deployed to a Kubernetes cluster as a multi-container application.
First, build the Docker images for the API and the Ollama service.
1. Build the API Image:
docker build -t ethicslab-api:latest .2. Build the Ollama Image:
This will create a Docker image with the gemma2:2b model pre-packaged.
docker build -f ollama.Dockerfile -t ollama-gemma:latest .Once the Docker images are built and pushed to a registry accessible by your Kubernetes cluster, you can deploy the application using the provided manifest.
1. Apply the Manifest:
kubectl apply -f k8s/deployment.yamlThis will create:
- A
DeploymentandServicefor the FastAPI application. - A
DeploymentandServicefor the Ollama service.
2. Access the Deployed Application:
The API service is exposed via a LoadBalancer. To find the external IP address assigned by the load balancer, run:
kubectl get svc ethicslab-api-serviceLook for the EXTERNAL-IP value. The API will be accessible at http://<EXTERNAL-IP>.
The application is configured using an environment variable to locate the Ollama service.
OLLAMA_URL: The URL of the Ollama service. In the Kubernetes deployment, this is automatically set tohttp://ollama-service:11434to allow the API to communicate with the Ollama container.