Skip to content

Auto-select an installed model, add a model picker, and show the screenshot on PyPI - #5

Merged
punnerud merged 2 commits into
mainfrom
fix/legacy-embeddings-endpoint
Aug 10, 2026
Merged

Auto-select an installed model, add a model picker, and show the screenshot on PyPI#5
punnerud merged 2 commits into
mainfrom
fix/legacy-embeddings-endpoint

Conversation

@punnerud

Copy link
Copy Markdown
Owner

Two small things.

The screenshot did not render on PyPI. The README used a relative path, and PyPI renders the README standalone, so docs/example.png resolved against pypi.org and 404'd. Now an absolute raw.githubusercontent.com URL, verified to return 200 image/png. Version bumped to 0.2.1 so the fixed description can be published.

Tests for the Ollama HTTP paths a real Ollama cannot exercise, via a stub server:

  • Ollama older than v0.3.4 has no /api/embed. The fallback to the singular /api/embeddings existed but was untested — and it is one of the two plausible causes of the blank page in Issues running project : errors in ollama serve logs #1.
  • A 404 meaning no such model and a 404 meaning no such route look identical and mean opposite things. The first must name the ollama pull command and must not retry the legacy route; the second must fall back.
  • A response with fewer rows than inputs is refused rather than silently misaligning every later vector.

One of these took 122 seconds on its own. Constructing an HTTPServer and not serving it does not give you a closed port — the socket is already bound and listening, so the connect succeeds and the request blocks until the 120-second timeout. It now closes a real socket to get a refused port: 2 seconds instead of 122, six times over in CI.

The example image did not render on pypi.org. The README used a relative
path, and PyPI renders the README standalone, so docs/example.png resolved
against pypi.org and 404'd. It is now an absolute raw.githubusercontent URL,
verified to return 200 image/png.

Also adds tests for the Ollama HTTP paths a real Ollama on a developer's
machine cannot exercise, using a stub server:

- An Ollama older than v0.3.4 has no /api/embed at all. The fallback to the
  singular /api/embeddings existed but had no test, and it is one of the two
  plausible causes of the blank page in #1.
- A 404 meaning "no such model" and a 404 meaning "no such route" look
  identical and mean opposite things. The first must name the ollama pull
  command and must NOT retry the legacy route; the second must fall back.
- A response with fewer rows than inputs is refused rather than silently
  misaligning every later vector.

One of these took two minutes on its own: constructing an HTTPServer without
serving it does not give a closed port -- the socket is already bound and
listening, so the connection succeeds and the request blocks until the
120-second timeout. The test now closes a real socket to get a refused port,
which takes 2 seconds instead of 122, six times over in CI.
Reported from a real first run: three usable models installed -- llama3.2:3b,
nomic-embed-text, all-minilm -- and the app insisting on pulling llama3.1:8b.

The embedding model had always been discovered from what Ollama reports. The
chat model was hardcoded, so LKG_CHAT_MODEL was a *default* rather than an
override, and anyone whose model happened to have another name was told to
download one they did not need. It is now discovered the same way, with a
preference order used only to break a tie between several installed models --
any installed model beats a missing one, so this can no longer produce a
"not found" when something usable is present.

Three additions to the page:

- Dropdowns for the chat and embedding model, listing what Ollama actually
  has. Which model answers is the first thing a new user gets wrong, and it
  was only changeable through an environment variable documented in the
  README.
- When Ollama has no chat model at all, the page lists a few with their
  download sizes, links to ollama.com, and can fetch one with streamed
  progress rather than printing a command and stopping.
- A favicon, because it was a 404 in everyone's terminal on every page load.

Two guards on the download route, which exists to start a multi-gigabyte
transfer:

- An allowlist, not free text. Only the models the page offers can be named.
- A same-origin check. A page on the internet can POST to a service on your
  loopback address, so starting a download has to be something this page
  asked for.

The model-selection route is equally not free text: a name is only accepted
if Ollama reports it as installed, because that value goes straight to the
model API.

18 new tests, including the exact reported case: llama3.2:3b present,
llama3.1:8b absent, health must be ok. Verified end to end against a real
Ollama with no environment variables set at all.
@punnerud punnerud changed the title Show the screenshot on PyPI, and test the legacy embeddings endpoint Auto-select an installed model, add a model picker, and show the screenshot on PyPI Aug 10, 2026
@punnerud
punnerud merged commit fd4134b into main Aug 10, 2026
6 checks passed
@punnerud
punnerud deleted the fix/legacy-embeddings-endpoint branch August 10, 2026 12:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant