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.
The project consists of three main components:
respond.py: Core text generation service. Uses OpenRouter to handle requests to generate text. Exposes a /generate endpoint.api_queue.py: Gateway for incoming requests. Receives prompts, queues them using Redis, and forwards them to respond.py for processing. Exposes a /generate endpoint.worker.py: Redis worker that listens for jobs on the queue and executes them for concurrency without blocking.Request flow:
/generate to api_queue.py.api_queue.py enqueues the request via Redis/RQ.worker.py picks up the job and calls the GPU service (respond.py).respond.py generates text using OpenRouter and returns it.api_queue.py returns the generated text to the client.OPENROUTER_API_KEY or ~/.api-openrouter (single-line file)See Redis installation: https://redis.io/docs/getting-started/
git clone <YOUR_REPOSITORY_URL>
cd llm-text-queue-gpu
python -m uv venv .venv
.venv/Scripts/python.exe -m ensurepip
.venv/Scripts/python.exe -m pip install uv
.venv/Scripts/python.exe -m uv pip install -r requirements.txt
Alternatively, you can run the setup helper:
./src/setup.sh
.env file by copying .env.example:cp .env.example .env
.env values as needed:REDIS_URL: Redis server URL (default: redis://localhost:6379)QUEUE_PORT: Queue service port (default: 5000)RESPOND_PORT: Response service port (default: 5001)MAX_NEW_TOKENS: Max new tokens for generation (default: 150)Note: Do not commit .env to source control.
The service uses OpenRouter exclusively. Model is resolved from OPENROUTER_MODEL_NAME env or ~/.model-openrouter (fallback to openrouter/free).
Credentials:
OPENROUTER_API_KEY env or ~/.api-openrouter file containing the key on a single line.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.
GET /health
Returns 200 if all services are healthy.
POST /generate
Content-Type: application/json
{
"prompt": "Your input text here"
}
Example Response:
{
"response": "I am doing well, thank you for asking."
}
Run the full test suite:
.venv/Scripts/python.exe -m pytest -q
{"prompt": "..."}/tmp/*.logThis project is licensed under the MIT-0 License - see the LICENSE file for details.
Companion chat, a Redis generation queue and personality matching over MCP.
Spatial reasoning tests for LLMs, with a multi-model leaderboard.
Writes a full book from a title prompt using OpenRouter.
CLI chatbot with swappable personalities such as tsundere and deredere.
Scores AI conversations by their effect on neurochemistry.
Generates function call graphs for Python code.