LLM Text Queue GPU

GPU-accelerated text processing pipeline.

This project provides a simple and efficient text generation service using OpenRouter with a Redis queue for handling requests. It consists of a Flask-based API that exposes endpoints for generating text and checking service health.

Table of Contents

Features

Architecture

The project consists of three main components:

Request flow:

  1. Client sends POST /generate to api_queue.py.
  2. api_queue.py enqueues the request via Redis/RQ.
  3. worker.py picks up the job and calls the GPU service (respond.py).
  4. respond.py generates text using OpenRouter and returns it.
  5. api_queue.py returns the generated text to the client.

Prerequisites

See Redis installation: https://redis.io/docs/getting-started/

Installation

  1. Clone the repository:
git clone <YOUR_REPOSITORY_URL>
cd llm-text-queue-gpu
  1. Create a virtual environment using uv and install tooling inside:
python -m uv venv .venv
.venv/Scripts/python.exe -m ensurepip
.venv/Scripts/python.exe -m pip install uv
  1. Install dependencies using uv:
.venv/Scripts/python.exe -m uv pip install -r requirements.txt

Alternatively, you can run the setup helper:

./src/setup.sh

Configuration

  1. Create a .env file by copying .env.example:
cp .env.example .env
  1. Update .env values as needed:

Note: Do not commit .env to source control.

Provider Selection and Models

The service uses OpenRouter exclusively. Model is resolved from OPENROUTER_MODEL_NAME env or ~/.model-openrouter (fallback to openrouter/free).

Credentials:

Running the Service

Start all services using:

./scripts/start-services.sh

The script ensures the uv venv exists, installs dependencies if needed, then starts Redis (if not running), the worker, the queue service, and the response service. Logs are written to /tmp/*.log where applicable.

API Documentation

Health Check

GET /health

Returns 200 if all services are healthy.

Generate Text

POST /generate
Content-Type: application/json

{
  "prompt": "Your input text here"
}

Example Response:

{
  "response": "I am doing well, thank you for asking."
}

Testing

Run the full test suite:

.venv/Scripts/python.exe -m pytest -q

Troubleshooting

Contributing

  1. Fork the repository.
  2. Create a branch for your change.
  3. Commit and push your branch.
  4. Open a pull request.

License

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

Related