The local server¶
python3 -m venv .venv
.venv/bin/pip install -r server/requirements.txt
.venv/bin/python server/app.py
A small Flask server in server/ serves the page at http://127.0.0.1:5050 and adds
generated pictures. It joins the parts itself, so it is also a way to work on the page: save a part
and reload.
| File | What is in it |
|---|---|
server/app.py |
the page, the addresses under /api, and who may call them |
server/pictures.py |
the models, what a model is told, the call through LlamaIndex |
server/test_app.py |
tests against a pretend OpenRouter; nothing is sent and nothing is paid |
parts/ui-09c-picture.js |
the Picture tab |
The server marks the page with <meta name="sew-server">. The page shows the Picture tab only when it finds that mark, and
asks nothing of a server otherwise.
The call¶
The call goes through LlamaIndex (llama-index-llms-openrouter). The models with a fixed price (the list CHEAP in
server/pictures.py) only make pictures and sit behind OpenRouter's image interface, which LlamaIndex does not speak; a
small subclass of its OpenRouter class does that part. The others are chat models that put a picture in their answer.
Two settings matter. LlamaIndex caps an answer at 256 tokens unless told otherwise, which would cut a picture off. And it tries a failed call again, which would be a second picture to pay for; here it does not.
Addresses¶
| Address | What it does |
|---|---|
GET / |
the page |
GET /api/status |
whether there is a key (not the key itself), and the models with prices and shapes |
GET /api/pictures |
the pictures made so far, the latest first |
POST /api/pictures |
makes a picture |
GET /pictures/… |
a picture |
The server listens on 127.0.0.1 only. A request with another host name, or a POST from any page but its own, is refused, so that another site open in the same browser cannot spend your credit.