Self-improving AI Employees for everyone
Python ai-agentsai-employeeai-employeesassistantautonomous-agentsco-employeescompanygrok-botinstinctloop-agentsmuseown-your-datapersonalself-hosted
fix(model): real model lists for Ollama / LM Studio in credentials modal
trohitg422f57162cdf
diff --git a/client/src/components/credentials/panels/ApiKeyPanel.tsx b/client/src/components/credentials/panels/ApiKeyPanel.tsxindex da962a78..66b52c6c 100644--- a/client/src/components/credentials/panels/ApiKeyPanel.tsx+++ b/client/src/components/credentials/panels/ApiKeyPanel.tsx@@ -77,30 +77,29 @@ const ApiKeyPanel: React.FC<{ config: ProviderConfig; visible: boolean }> = ({ csetValidated(false);}}onSave={() =>- // Cloud providers store under config.id and validate via- // the upstream API. Local servers (Ollama, LM Studio)- // declare a non-`apiKey` field key (e.g. `ollama_proxy`)- // because nothing remote needs validating — just persist- // the base URL where the existing proxy_url lookup in- // execute_chat will find it.- (field.key === 'apiKey'- ? panel.actions.validate(config.id, inputValue.trim())- : panel.actions.save(field.key, inputValue.trim())- ).then((r) => {- if (r?.isValid) setValidated(true);- })+ panel.actions+ .validate(config.id, inputValue.trim())+ .then((r) => {+ if (r?.isValid) setValidated(true);+ })}onDelete={validated- ? () => {- panel.actions.remove(field.key === 'apiKey' ? config.id : field.key);+ ? async () => {+ // Local providers also stored a Base URL under+ // {field.key} (e.g. `ollama_proxy`) — wipe both+ // so the modal returns to a clean empty state.+ await panel.actions.remove(config.id);+ if (field.key !== 'apiKey') {+ await panel.actions.remove(field.key);+ }setInputValue('');setValidated(false);}: undefined}placeholder={field.placeholder}- loading={panel.loading === 'validate' || panel.loading === 'save'}+ loading={panel.loading === 'validate'}isStored={validated}/>)}diff --git a/server/config/llm_defaults.json b/server/config/llm_defaults.jsonindex 7730e0a3..46c91124 100644--- a/server/config/llm_defaults.json+++ b/server/config/llm_defaults.json@@ -253,8 +253,7 @@},"ollama": {- "_description": "Local Ollama server (OpenAI-compatible /v1). The shape mirrors deepseek/kimi/mistral: base_url + models_endpoint, no auth field. The user's custom server address lives in the {provider}_proxy credential (existing Ollama-style auth-delegation path) which OpenAIProvider treats as the API base.",- "default_model": "llama3.2:3b",+ "_description": "Local Ollama server (OpenAI-compatible /v1). No `default_model` because the dropdown should reflect the user's actually-pulled models — fetch_models hits the user's saved {provider}_proxy URL and returns whatever Ollama reports; when the server is offline we want an empty list (a 'start your server' cue), not a placeholder name the user almost certainly doesn't have.","detection_patterns": ["ollama"],"base_url": "http://localhost:11434/v1","models_endpoint": "http://localhost:11434/v1/models",@@ -266,8 +265,7 @@},"lmstudio": {- "_description": "Local LM Studio server (pure OpenAI-compatible). Same OpenAIProvider+base_url path as deepseek/kimi/mistral; user's custom URL rides via {provider}_proxy.",- "default_model": "local-model",+ "_description": "Local LM Studio server (pure OpenAI-compatible). Same no-default-model rule as ollama — the dropdown reflects what the user has loaded in LM Studio, not a fake placeholder.","detection_patterns": ["lmstudio", "lm_studio", "lm-studio"],"base_url": "http://localhost:1234/v1","models_endpoint": "http://localhost:1234/v1/models",diff --git a/server/nodes/model/_local_validator.py b/server/nodes/model/_local_validator.pynew file mode 100644index 00000000..62fe122a--- /dev/null+++ b/server/nodes/model/_local_validator.py@@ -0,0 +1,100 @@+"""Local-LLM credential validator (Ollama, LM Studio).++Lives next to the chat-model plugins so all per-provider behaviour for+the local servers stays in `nodes/model/`. Registered into+`routers.websocket._SPECIAL_PROVIDER_VALIDATORS` from the same place+the cloud-provider mapping is declared — same shim shape as apify and+google_maps, the function body just lives here instead.++The frontend reuses the standard ``validate_api_key`` WebSocket message+for these providers; the ``api_key`` field carries the user's Base URL,+not a secret. We:++1. Save the URL under ``{provider}_proxy`` — the existing Ollama-style+ auth-delegation key that ``AIService.create_model`` and+ ``AIService.fetch_models`` already read.+2. Call ``ai_service.fetch_models(provider, "ollama")`` which (after the+ proxy_url passthrough in services/ai.py) probes the user's URL and+ returns the actually-installed models.+3. Store the placeholder api_key + discovered model list under the+ provider id so the Provider Defaults dropdown shows real entries.+4. Return ``valid=True`` only when at least one model was found, so a+ misconfigured URL surfaces as a clear "no models" message instead+ of a silent success.+"""++from __future__ import annotations++import time+from typing import Any, Dict++from fastapi import WebSocket++from core.container import container+from core.logging import get_logger+from services.status_broadcaster import get_status_broadcaster++logger = get_logger(__name__)+++async def validate_local_llm(data: Dict[str, Any], websocket: WebSocket) -> Dict[str, Any]:+ """Validator for ollama / lmstudio. Matches the SPECIAL_PROVIDER_VALIDATORS contract."""+ provider = data["provider"].lower()+ base_url = data.get("api_key", "").strip()+ session_id = data.get("session_id", "default")++ if not base_url:+ return {"success": False, "valid": False, "error": "Base URL required"}++ auth_service = container.auth_service()+ ai_service = container.ai_service()+ broadcaster = get_status_broadcaster()++ # Persist the URL first so the upcoming fetch_models call can read+ # it via the existing {provider}_proxy lookup. Without this step+ # the probe would hit the JSON default base_url, not the user's+ # custom server.+ await auth_service.store_api_key(+ provider=f"{provider}_proxy",+ api_key=base_url,+ models=[],+ session_id=session_id,+ )++ try:+ models = await ai_service.fetch_models(provider, "ollama")+ except Exception as e:+ logger.warning("[%s] fetch_models failed: %s", provider, e)+ models = []++ if not models:+ message = (+ f"Saved URL but {provider} returned no models — is the server "+ "running and a model loaded?"+ )+ await broadcaster.update_api_key_status(+ provider=provider, valid=False, message=message,+ has_key=True, models=[],+ )+ return {"success": True, "valid": False, "message": message, "models": []}++ # Store placeholder api_key + the real model list. The placeholder+ # ("ollama") is the documented value LiteLLM / OpenAI clients accept+ # for unauthenticated local servers; it's never sent over the wire+ # because OpenAIProvider rewrites it when proxy_url is set.+ await auth_service.store_api_key(+ provider=provider,+ api_key="ollama",+ models=models,+ session_id=session_id,+ )+ await broadcaster.update_api_key_status(+ provider=provider, valid=True,+ message=f"{len(models)} model(s) discovered at {base_url}",+ has_key=True, models=models,+ )+ return {+ "provider": provider, "success": True, "valid": True,+ "models": models, "message": f"Connected to {provider} at {base_url}",+ "timestamp": time.time(),+ }diff --git a/server/routers/websocket.py b/server/routers/websocket.pyindex c90cbb15..dcbcf2ec 100644--- a/server/routers/websocket.py+++ b/server/routers/websocket.py@@ -1976,10 +1976,16 @@ async def handle_validate_apify_key(data: Dict[str, Any], websocket: WebSocket)# Per-provider validation strategies. Register any non-LLM provider here# and `handle_validate_api_key` will dispatch to it automatically, so the-# frontend only ever calls one WS message type.+# frontend only ever calls one WS message type. Local-LLM validators+# live in their plugin folder (see `nodes/model/_local_validator.py`)+# so all per-provider behaviour for ollama/lmstudio stays in `nodes/model/`.+from nodes.model._local_validator import validate_local_llm as _validate_local_llm+_SPECIAL_PROVIDER_VALIDATORS = {"google_maps": handle_validate_maps_key,"apify": handle_validate_apify_key,+ "ollama": _validate_local_llm,+ "lmstudio": _validate_local_llm,}diff --git a/server/services/ai.py b/server/services/ai.pyindex 4610887b..1728d920 100644--- a/server/services/ai.py+++ b/server/services/ai.py@@ -1397,11 +1397,16 @@ class AIService:"""Fetch available models from provider API.Native providers use their SDK-based fetch_models(). Groq/Cerebras- fall back to the LangChain httpx path.+ fall back to the LangChain httpx path. Local providers (ollama,+ lmstudio) honour the user's stored ``{provider}_proxy`` base URL+ the same way ``execute_chat`` does — without this passthrough the+ probe always hits the JSON default and never sees the user's+ actual installed models."""# --- Native SDK path ---if is_native_provider(provider):- native_provider = create_provider(provider, api_key)+ proxy_url = await self.auth.get_api_key(f"{provider}_proxy")+ native_provider = create_provider(provider, api_key, proxy_url=proxy_url)return await native_provider.fetch_models(api_key)# --- LangChain fallback (groq, cerebras) ---@@ -1435,10 +1440,14 @@ class AIService:except Exception as e:logger.warning(f"[AI] Failed to fetch models from {provider} API: {e}")- # Fallback to curated list from llm_defaults.json+ # Fallback to curated list from llm_defaults.json. When the+ # provider has no default_model declared (intentional for local+ # servers like ollama/lmstudio), return an empty list so the+ # frontend dropdown shows a real "no models" empty state instead+ # of a placeholder name the user doesn't actually have.if curated:return curated- return [config.default_model]+ return [config.default_model] if config.default_model else []async def execute_chat(self, node_id: str, node_type: str, parameters: Dict[str, Any]) -> Dict[str, Any]:"""Execute AI chat model."""