LLM API Aggregator is a tool that allows you to store your chats from various LLMs in one place, making it easier to manage them. Its backend is built on FastAPI, SQLAlchemy for communicating with a PostgreSQL database along with Alembic for migrations, Redis for caching and Pydantic for performing data validation.
The repository with the application's frontend is located at this link. Make sure to set it up if you want to use it with a user interface.
llm-api-aggregator-preview.mp4
- OpenAI
- Google Gemini
- Project was develoepd using Python 3.12, PostgreSQL 15.6 and Redis 7.2.5.
- Docker - it is not required, but highly recommended to simplify the installation of all dependencies and minimize manual configuration, using Docker Compose.
Before installing the application, make sure that a .env
file is created. To populate the .env
file, you can use either the .env.docker-example
or .env.example
as a template. Copy the contents of example file to .env
and fill in the required values.
-
Remember to adjust DATABASE_URL according to your database username and password. If the project is running locally, you should set the host and port as
localhost:5432
(or127.0.0.1:5432
if it doesn't work) since it is running on your local machine and5432
is the default port for PostgreSQL. -
The REDIS_SERVER_HOST and REDIS_SERVER_PORT variables should be set to the address and port of your Redis server. If you are running Redis locally, you should set it to
localhost
and6379
respectively. -
The ALLOWED_ORIGIN variable should be set to the address of the API consumer. If you are running the frontend locally, you should set it to
http://localhost:5173
as it is the default address for the frontend running on Vite. -
You can generate JWT_AUTH_SECRET_KEY by executing this command in your console:
openssl rand -hex 32
-
To generate FERNET_MASTER_KEY, you can use the following code snippet, e.g. in Python console:
>>> from cryptography.fernet import Fernet >>> key = Fernet.generate_key() >>> key.decode() 'YwBQY5h4XpXiFsffgrq-RJmZerMmAvjHFVgY4e9hx48='
Then you should copy the key as
YwBQY5h4XpXiFsffgrq-RJmZerMmAvjHFVgY4e9hx48=
(without the quotes) and paste it into the.env
file.
Values in this file, compared to .env.example
, are mostly prepared to work in a local environment.
POSTGRES_USER=postgres
# Remember to change the password ;)
POSTGRES_PASSWORD=topsecretpassword
POSTGRES_DB=llm-api-aggregator
REDIS_SERVER_HOST=redis
REDIS_SERVER_PORT=6379
# Docker image of the frontend runs on host 3000
ALLOWED_ORIGIN=http://localhost:3000
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
AWS_REGION=YOUR_AWS_REGION
AWS_S3_BUCKET_NAME=YOUR_S3_BUCKET_NAME
JWT_AUTH_SECRET_KEY=YOUR_GENERATED_AUTH_SECRET_KEY
FERNET_MASTER_KEY=YOUR_GENERATED_FERNET_MASTER_KEY
DATABASE_URL=postgresql+psycopg://USER:PASSWORD@HOST:PORT/DATABASE
REDIS_SERVER_HOST=YOUR_REDIS_SERVER_URL
REDIS_SERVER_PORT=YOUR_REDIS_SERVER_PORT
ALLOWED_ORIGIN=YOUR_API_CONSUMER
AWS_ACCESS_KEY_ID=YOUR_AWS_ACCESS_KEY
AWS_SECRET_ACCESS_KEY=YOUR_AWS_SECRET_KEY
AWS_REGION=YOUR_AWS_REGION
AWS_S3_BUCKET_NAME=YOUR_S3_BUCKET_NAME
JWT_AUTH_SECRET_KEY=YOUR_GENERATED_AUTH_SECRET_KEY
FERNET_MASTER_KEY=YOUR_GENERATED_FERNET_MASTER_KEY
git clone https://github.com/marchewadm/llm-api-aggregator-backend.git
cd llm-api-aggregator-backend
- Build Docker Image
docker compose build
- Run The Container
docker compose up -d
- Stop The Container
docker compose down
- Create Virtual Environment
python -m venv venv
- Activate Virtual Environment
- For Windows by using Powershell:
./venv/Scripts/Activate.ps1
- For GNU/Linux and macOS by using bash shell:
source venv/bin/activate
- Install All Necessary Dependencies
pip install -r requirements/requirements.txt
- Running Migrations
alembic upgrade head
- Initializing API Providers
Once the database tables have been created, run the following command from the root directory to execute the script that will initialize the API providers in the database:
python -m src.core.init_api_providers
And that's it! Now you can proceed to the next step: running your new, freshly installed and configured app.
- Usage
# NOTE:
# Command below should be executed from the root directory
uvicorn src.main:app --reload
After executing the command, the server should start listening at the address 127.0.0.1:8000
.
This project is licensed under the MIT License.