SIGN IN SIGN UP

fix: lazy-load Ollama /api/show to reduce unnecessary requests (#11836)

* fix: lazy-load Ollama /api/show to reduce unnecessary requests

Move the /api/show call from the Ollama constructor to a lazy
ensureModelInfo() method that is only invoked on first actual model
usage (_streamComplete, _streamChat, _streamFim). The promise is
cached so subsequent calls reuse the same result.

This fixes the issue where AUTODETECT with many models caused hundreds
of /api/show requests on every config reload, since each model
instantiation fired a request in the constructor.

Additional fixes:
- Null-check regex match result to prevent runtime errors
- Use const instead of let for immutable bindings
- Don't override explicitly configured contextLength with /api/show value
- Silently ignore unparseable stop parameters
- Return empty array from listModels() on failure instead of throwing

Closes #8765

* revert silent error handling, remove verbose comments
D
Dallin Romney committed
8b9f4ab625519ef1fce5077c01493836f7120959
Parent: 2f52b46
Committed by GitHub <noreply@github.com> on 3/25/2026, 10:37:03 PM