Skip to content

fix: Ollama model selection and error messages in AI settings (#712) - #716

Merged
datlechin merged 2 commits into
mainfrom
fix/ai-ollama-model-selection
Apr 13, 2026
Merged

datlechin merged 2 commits into
mainfrom
fix/ai-ollama-model-selection

Conversation

@datlechin

Copy link
Copy Markdown
Member

Summary

  • Fix model field showing stale models from cached provider when switching to Ollama
  • Fix generic "Connection test failed" error with actionable Ollama-specific messages
  • Clean up model field to use native Picker only — no custom UI

Closes #712

Root causes

  1. Stale cached provider: AIProviderFactory caches providers by config.id. When editing a draft and switching type (e.g., Claude → Ollama), the draft keeps the same UUID, so the factory returned the old Claude provider — fetching Claude models and failing auth with Ollama's empty API key.

  2. No text input fallback: When model fetch failed, the UI showed "No models loaded" with no way to retry or interact.

  3. Generic errors: Ollama test failures showed "Connection test failed" with no guidance about checking if Ollama is running.

Changes

File Change
AISettingsView.swift Invalidate provider cache on type/endpoint change; clean model field: loading → spinner, empty → "Load Models" retry button, loaded → native Picker
OpenAICompatibleProvider.swift Ollama-specific error messages: connection refused, no models, HTTP errors with endpoint/status

Test plan

  • Add Ollama provider (Ollama running) → models load in Picker, Test succeeds
  • Add Ollama provider (Ollama not running) → "Load Models" button shown, Test shows "Cannot connect to Ollama at... Is Ollama running?"
  • Switch type Claude → Ollama → should fetch Ollama models, not Claude models
  • Change endpoint → should re-fetch models from new endpoint
  • Other providers (Claude, OpenAI, Gemini) → no regression

@datlechin
datlechin force-pushed the fix/ai-ollama-model-selection branch from 8b74031 to ed19c1b Compare April 13, 2026 03:27
@datlechin
datlechin merged commit 68e546c into main Apr 13, 2026
2 checks passed
@datlechin
datlechin deleted the fix/ai-ollama-model-selection branch April 13, 2026 03:31
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.

Tính năng AI chưa cho tự nhập model

1 participant