OpenRAG is a comprehensive, single package Retrieval-Augmented Generation platform built on Langflow, Docling, and Opensearch.
Python
fix: Set Model after Provider is deleted (#1935)
Mike Fortmanca42aa6f085a
diff --git a/frontend/app/settings/_components/agent-settings-section.tsx b/frontend/app/settings/_components/agent-settings-section.tsxindex 59fa14f4f..8f319f458 100644--- a/frontend/app/settings/_components/agent-settings-section.tsx+++ b/frontend/app/settings/_components/agent-settings-section.tsx@@ -2,7 +2,7 @@import { ArrowUpRight, Loader2 } from "lucide-react";import { usePathname, useRouter, useSearchParams } from "next/navigation";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { toast } from "sonner";import {useGetAnthropicModelsQuery,@@ -84,42 +84,55 @@ export function AgentSettingsSection() {},);- const groupedLlmModels = [- {- group: "OpenAI",- provider: "openai",- icon: getModelLogo("", "openai"),- models: openaiModels?.language_models || [],- configured: settings.providers?.openai?.configured === true,- },- {- group: "Anthropic",- provider: "anthropic",- icon: getModelLogo("", "anthropic"),- models: anthropicModels?.language_models || [],- configured: settings.providers?.anthropic?.configured === true,- },- {- group: "Ollama",- provider: "ollama",- icon: getModelLogo("", "ollama"),- models: ollamaModels?.language_models || [],- configured: settings.providers?.ollama?.configured === true,- },- {- group: "IBM watsonx.ai",- provider: "watsonx",- icon: getModelLogo("", "watsonx"),- models: watsonxModels?.language_models || [],- configured: settings.providers?.watsonx?.configured === true,- },- ]- .filter((p) => p.configured)- .map((p) => ({- group: p.group,- icon: p.icon,- options: p.models.map((m) => ({ ...m, provider: p.provider })),- }));+ const groupedLlmModels = useMemo(+ () =>+ [+ {+ group: "OpenAI",+ provider: "openai",+ icon: getModelLogo("", "openai"),+ models: openaiModels?.language_models || [],+ configured: settings.providers?.openai?.configured === true,+ },+ {+ group: "Anthropic",+ provider: "anthropic",+ icon: getModelLogo("", "anthropic"),+ models: anthropicModels?.language_models || [],+ configured: settings.providers?.anthropic?.configured === true,+ },+ {+ group: "Ollama",+ provider: "ollama",+ icon: getModelLogo("", "ollama"),+ models: ollamaModels?.language_models || [],+ configured: settings.providers?.ollama?.configured === true,+ },+ {+ group: "IBM watsonx.ai",+ provider: "watsonx",+ icon: getModelLogo("", "watsonx"),+ models: watsonxModels?.language_models || [],+ configured: settings.providers?.watsonx?.configured === true,+ },+ ]+ .filter((p) => p.configured)+ .map((p) => ({+ group: p.group,+ icon: p.icon,+ options: p.models.map((m) => ({ ...m, provider: p.provider })),+ })),+ [+ openaiModels?.language_models,+ anthropicModels?.language_models,+ ollamaModels?.language_models,+ watsonxModels?.language_models,+ settings.providers?.openai?.configured,+ settings.providers?.anthropic?.configured,+ settings.providers?.ollama?.configured,+ settings.providers?.watsonx?.configured,+ ],+ );const isLoadingAnyLlmModels =openaiLoading || anthropicLoading || ollamaLoading || watsonxLoading;@@ -133,6 +146,39 @@ export function AgentSettingsSection() {},});+ const allLlmOptions = useMemo(+ () => groupedLlmModels.flatMap((g) => g.options),+ [groupedLlmModels],+ );++ const handleModelChange = useCallback(+ (newModel: string, provider?: string) => {+ if (newModel && provider) {+ updateSettingsMutation.mutate({+ llm_model: newModel,+ llm_provider: provider,+ });+ } else if (newModel) {+ updateSettingsMutation.mutate({ llm_model: newModel });+ }+ },+ [updateSettingsMutation],+ );++ const autoSelectedLlm = useRef(false);+ useEffect(() => {+ if (settings.agent?.llm_model) {+ autoSelectedLlm.current = false;+ return;+ }+ if (autoSelectedLlm.current) return;+ if (allLlmOptions.length > 0) {+ autoSelectedLlm.current = true;+ const fallback = allLlmOptions.find((o) => o.default) || allLlmOptions[0];+ handleModelChange(fallback.value, fallback.provider);+ }+ }, [settings.agent?.llm_model, allLlmOptions, handleModelChange]);+useEffect(() => {if (settings.agent?.system_prompt) {setSystemPrompt(settings.agent.system_prompt);@@ -152,17 +198,6 @@ export function AgentSettingsSection() {}}, [focusLlmModel, searchParams, router, pathname]);- const handleModelChange = (newModel: string, provider?: string) => {- if (newModel && provider) {- updateSettingsMutation.mutate({- llm_model: newModel,- llm_provider: provider,- });- } else if (newModel) {- updateSettingsMutation.mutate({ llm_model: newModel });- }- };-const handleSystemPromptSave = () => {updateSettingsMutation.mutate({ system_prompt: systemPrompt });};diff --git a/frontend/app/settings/_components/ingest-settings-section.tsx b/frontend/app/settings/_components/ingest-settings-section.tsxindex 8f5f336a5..d0e80ff8a 100644--- a/frontend/app/settings/_components/ingest-settings-section.tsx+++ b/frontend/app/settings/_components/ingest-settings-section.tsx@@ -1,7 +1,7 @@"use client";import { ArrowUpRight, Loader2, Minus, Plus } from "lucide-react";-import { useEffect, useState } from "react";+import { useCallback, useEffect, useMemo, useRef, useState } from "react";import { toast } from "sonner";import {useGetIBMModelsQuery,@@ -82,35 +82,46 @@ export function IngestSettingsSection() {},);- const groupedEmbeddingModels = [- {- group: "OpenAI",- provider: "openai",- icon: getModelLogo("", "openai"),- models: openaiModels?.embedding_models || [],- configured: settings.providers?.openai?.configured === true,- },- {- group: "Ollama",- provider: "ollama",- icon: getModelLogo("", "ollama"),- models: ollamaModels?.embedding_models || [],- configured: settings.providers?.ollama?.configured === true,- },- {- group: "IBM watsonx.ai",- provider: "watsonx",- icon: getModelLogo("", "watsonx"),- models: watsonxModels?.embedding_models || [],- configured: settings.providers?.watsonx?.configured === true,- },- ]- .filter((p) => p.configured)- .map((p) => ({- group: p.group,- icon: p.icon,- options: p.models.map((m) => ({ ...m, provider: p.provider })),- }));+ const groupedEmbeddingModels = useMemo(+ () =>+ [+ {+ group: "OpenAI",+ provider: "openai",+ icon: getModelLogo("", "openai"),+ models: openaiModels?.embedding_models || [],+ configured: settings.providers?.openai?.configured === true,+ },+ {+ group: "Ollama",+ provider: "ollama",+ icon: getModelLogo("", "ollama"),+ models: ollamaModels?.embedding_models || [],+ configured: settings.providers?.ollama?.configured === true,+ },+ {+ group: "IBM watsonx.ai",+ provider: "watsonx",+ icon: getModelLogo("", "watsonx"),+ models: watsonxModels?.embedding_models || [],+ configured: settings.providers?.watsonx?.configured === true,+ },+ ]+ .filter((p) => p.configured)+ .map((p) => ({+ group: p.group,+ icon: p.icon,+ options: p.models.map((m) => ({ ...m, provider: p.provider })),+ })),+ [+ openaiModels?.embedding_models,+ ollamaModels?.embedding_models,+ watsonxModels?.embedding_models,+ settings.providers?.openai?.configured,+ settings.providers?.ollama?.configured,+ settings.providers?.watsonx?.configured,+ ],+ );const isLoadingAnyEmbeddingModels =openaiLoading || ollamaLoading || watsonxLoading;@@ -124,6 +135,44 @@ export function IngestSettingsSection() {},});+ const allEmbeddingOptions = useMemo(+ () => groupedEmbeddingModels.flatMap((g) => g.options),+ [groupedEmbeddingModels],+ );++ const handleEmbeddingModelChange = useCallback(+ (newModel: string, provider?: string) => {+ if (newModel && provider) {+ updateSettingsMutation.mutate({+ embedding_model: newModel,+ embedding_provider: provider,+ });+ } else if (newModel) {+ updateSettingsMutation.mutate({ embedding_model: newModel });+ }+ },+ [updateSettingsMutation],+ );++ const autoSelectedEmbedding = useRef(false);+ useEffect(() => {+ if (settings.knowledge?.embedding_model) {+ autoSelectedEmbedding.current = false;+ return;+ }+ if (autoSelectedEmbedding.current) return;+ if (allEmbeddingOptions.length > 0) {+ autoSelectedEmbedding.current = true;+ const fallback =+ allEmbeddingOptions.find((o) => o.default) || allEmbeddingOptions[0];+ handleEmbeddingModelChange(fallback.value, fallback.provider);+ }+ }, [+ settings.knowledge?.embedding_model,+ allEmbeddingOptions,+ handleEmbeddingModelChange,+ ]);+useEffect(() => {if (settings.knowledge?.chunk_size !== undefined)setChunkSize(settings.knowledge.chunk_size);@@ -165,17 +214,6 @@ export function IngestSettingsSection() {disableIngestWithLangflow !==(k?.disable_ingest_with_langflow ?? disableIngestWithLangflow);- const handleEmbeddingModelChange = (newModel: string, provider?: string) => {- if (newModel && provider) {- updateSettingsMutation.mutate({- embedding_model: newModel,- embedding_provider: provider,- });- } else if (newModel) {- updateSettingsMutation.mutate({ embedding_model: newModel });- }- };-const handleChunkSizeChange = (value: string) => {setChunkSize(Math.max(0, Number.parseInt(value, 10) || 0));setChunkValidationError(null);diff --git a/frontend/lib/constants.ts b/frontend/lib/constants.tsindex cdc7b2ec3..e27f1e811 100644--- a/frontend/lib/constants.ts+++ b/frontend/lib/constants.ts@@ -2,7 +2,7 @@* Default agent settings*/export const DEFAULT_AGENT_SETTINGS = {- llm_model: "gpt-4o-mini",+ llm_model: "gpt-5.4-mini",system_prompt:'You are the OpenRAG Agent. You answer questions using retrieval, reasoning, and tool use.\nYou have access to several tools. Your job is to determine **which tool to use and when**.\n### Available Tools\n- OpenSearch Retrieval Tool:\n Use this to search the indexed knowledge base. Use when the user asks about product details, internal concepts, processes, architecture, documentation, roadmaps, or anything that may be stored in the index.\n- Conversation History:\n Use this to maintain continuity when the user is referring to previous turns. \n Do not treat history as a factual source.\n- Conversation File Context:\n Use this when the user asks about a document they uploaded or refers directly to its contents.\n- URL Ingestion Tool:\n Use this **only** when the user explicitly asks you to read, summarize, or analyze the content of a URL.\n Do not ingest URLs automatically.\n- Calculator / Expression Evaluation Tool:\n Use this when the user asks to compare numbers, compute estimates, calculate totals, analyze pricing, or answer any question requiring mathematics or quantitative reasoning.\n If the answer requires arithmetic, call the calculator tool rather than calculating internally.\n### Retrieval Decision Rules\nUse OpenSearch **whenever**:\n1. The question may be answered from internal or indexed data.\n2. The user references team names, product names, release plans, configurations, requirements, or official information.\n3. The user needs a factual, grounded answer.\nDo **not** use retrieval if:\n- The question is purely creative (e.g., storytelling, analogies) or personal preference.\n- The user simply wants text reformatted or rewritten from what is already present in the conversation.\nWhen uncertain → **Retrieve.** Retrieval is low risk and improves grounding.\n### URL Ingestion Rules\nOnly ingest URLs when the user explicitly says:\n- \"Read this link\"\n- \"Summarize this webpage\"\n- \"What does this site say?\"\n- \"Ingest this URL\"\nIf unclear → ask a clarifying question.\n### Calculator Usage Rules\nUse the calculator when:\n- Performing arithmetic\n- Estimating totals\n- Comparing values\n- Modeling cost, time, effort, scale, or projections\nDo not perform math internally. **Call the calculator tool instead.**\n### Answer Construction Rules\n1. When asked: \"What is OpenRAG\", answer the following:\n\"OpenRAG is an open-source package for building agentic RAG systems. It supports integration with a wide range of orchestration tools, vector databases, and LLM providers. OpenRAG connects and amplifies three popular, proven open-source projects into one powerful platform:\n**Langflow** – Langflow is a powerful tool to build and deploy AI agents and MCP servers. [Read more](https://www.langflow.org/)\n**OpenSearch** – OpenSearch is an open source, search and observability suite that brings order to unstructured data at scale. [Read more](https://opensearch.org/)\n**Docling** – Docling simplifies document processing with advanced PDF understanding, OCR support, and seamless AI integrations. Parse PDFs, DOCX, PPTX, images & more. [Read more](https://www.docling.ai/)\"\n2. Synthesize retrieved or ingested content in your own words.\n3. Support factual claims with citations in the format:\n (Source: <document_name_or_id>)\n4. If no supporting evidence is found:\n Say: \"No relevant supporting sources were found for that request.\"\n5. Never invent facts or hallucinate details.\n6. Be concise, direct, and confident. \n7. Do not reveal internal chain-of-thought.',} as const;diff --git a/src/api/settings/endpoints.py b/src/api/settings/endpoints.pyindex bcc782f7b..d3975f43e 100644--- a/src/api/settings/endpoints.py+++ b/src/api/settings/endpoints.py@@ -16,6 +16,8 @@ from api.provider_validation import validate_provider_setupfrom api.settings.helpers import (_affected_embedding_models,_create_openrag_docs_filter,+ _default_embedding_model,+ _default_llm_model,_embedding_conflict_response,_first_configured_embedding_provider,_first_configured_llm_provider,@@ -634,15 +636,13 @@ async def update_settings(current_config.providers.ollama.endpoint = ""current_config.providers.ollama.configured = Falseif current_config.agent.llm_provider == "ollama":- current_config.agent.llm_provider = _first_configured_llm_provider(- current_config, "ollama"- )- current_config.agent.llm_model = ""+ fb = _first_configured_llm_provider(current_config, "ollama")+ current_config.agent.llm_provider = fb+ current_config.agent.llm_model = _default_llm_model(fb)if current_config.knowledge.embedding_provider == "ollama":- current_config.knowledge.embedding_provider = _first_configured_embedding_provider(- current_config, "ollama"- )- current_config.knowledge.embedding_model = ""+ fb = _first_configured_embedding_provider(current_config, "ollama")+ current_config.knowledge.embedding_provider = fb+ current_config.knowledge.embedding_model = _default_embedding_model(fb)config_updated = Trueprovider_updated = True@@ -670,11 +670,11 @@ async def update_settings(if current_config.agent.llm_provider == "openai":fb = _first_configured_llm_provider(current_config, "openai")current_config.agent.llm_provider = fb- current_config.agent.llm_model = ""+ current_config.agent.llm_model = _default_llm_model(fb)if current_config.knowledge.embedding_provider == "openai":fb = _first_configured_embedding_provider(current_config, "openai")current_config.knowledge.embedding_provider = fb- current_config.knowledge.embedding_model = ""+ current_config.knowledge.embedding_model = _default_embedding_model(fb)config_updated = Trueprovider_updated = True@@ -696,7 +696,7 @@ async def update_settings(if current_config.agent.llm_provider == "anthropic":fb = _first_configured_llm_provider(current_config, "anthropic")current_config.agent.llm_provider = fb- current_config.agent.llm_model = ""+ current_config.agent.llm_model = _default_llm_model(fb)# Anthropic is not a valid embedding provider; no embedding reset neededconfig_updated = Trueprovider_updated = True@@ -727,11 +727,11 @@ async def update_settings(if current_config.agent.llm_provider == "watsonx":fb = _first_configured_llm_provider(current_config, "watsonx")current_config.agent.llm_provider = fb- current_config.agent.llm_model = ""+ current_config.agent.llm_model = _default_llm_model(fb)if current_config.knowledge.embedding_provider == "watsonx":fb = _first_configured_embedding_provider(current_config, "watsonx")current_config.knowledge.embedding_provider = fb- current_config.knowledge.embedding_model = ""+ current_config.knowledge.embedding_model = _default_embedding_model(fb)config_updated = Trueprovider_updated = Truediff --git a/src/api/settings/helpers.py b/src/api/settings/helpers.pyindex 5464708e4..e26af7a47 100644--- a/src/api/settings/helpers.py+++ b/src/api/settings/helpers.py@@ -27,11 +27,35 @@ def _first_configured_llm_provider(config, excluding: str) -> str:def _first_configured_embedding_provider(config, excluding: str) -> str:- """Return the first configured embedding provider (openai/watsonx/ollama) that isn't `excluding`."""+ """Return the first configured embedding provider (openai/watsonx/ollama) that isn't `excluding`, or "" if none."""for p in ["openai", "watsonx", "ollama"]:if p != excluding and getattr(config.providers, p).configured:return p- return "openai"+ return ""+++def _default_llm_model(provider: str) -> str:+ """Return the static default LLM model for a provider, or empty string for+ providers whose model lists are fully dynamic (ollama, watsonx)."""+ from config.model_constants import (+ ANTHROPIC_DEFAULT_LANGUAGE_MODEL,+ OPENAI_DEFAULT_LANGUAGE_MODEL,+ )++ return {+ "openai": OPENAI_DEFAULT_LANGUAGE_MODEL,+ "anthropic": ANTHROPIC_DEFAULT_LANGUAGE_MODEL,+ }.get(provider, "")+++def _default_embedding_model(provider: str) -> str:+ """Return the static default embedding model for a provider, or empty string+ for providers whose model lists are fully dynamic (ollama, watsonx)."""+ from config.embedding_constants import OPENAI_DEFAULT_EMBEDDING_MODEL++ return {+ "openai": OPENAI_DEFAULT_EMBEDDING_MODEL,+ }.get(provider, "")async def _affected_embedding_models(diff --git a/tests/unit/test_settings_provider_removal_defaults.py b/tests/unit/test_settings_provider_removal_defaults.pynew file mode 100644index 000000000..eb58b321f--- /dev/null+++ b/tests/unit/test_settings_provider_removal_defaults.py@@ -0,0 +1,296 @@+"""Tests for default model selection when a provider is removed.++When a provider is removed and it was the active LLM or embedding provider,+the backend should fall back to another configured provider AND select a+sensible default model (not an empty string).+"""++from api.settings.helpers import (+ _default_embedding_model,+ _default_llm_model,+ _first_configured_embedding_provider,+ _first_configured_llm_provider,+)+from config.config_manager import (+ AgentConfig,+ AnthropicConfig,+ KnowledgeConfig,+ OllamaConfig,+ OnboardingState,+ OpenAIConfig,+ OpenRAGConfig,+ ProvidersConfig,+ WatsonXConfig,+)+from config.embedding_constants import OPENAI_DEFAULT_EMBEDDING_MODEL+from config.model_constants import (+ ANTHROPIC_DEFAULT_LANGUAGE_MODEL,+ OPENAI_DEFAULT_LANGUAGE_MODEL,+)++# ---------------------------------------------------------------------------+# Fixtures+# ---------------------------------------------------------------------------+++def _make_config(+ *,+ openai=False,+ anthropic=False,+ ollama=False,+ watsonx=False,+ llm_provider="openai",+ llm_model="gpt-5.4-mini",+ embedding_provider="openai",+ embedding_model="text-embedding-3-small",+) -> OpenRAGConfig:+ """Build a minimal OpenRAGConfig with the requested providers configured."""+ return OpenRAGConfig(+ providers=ProvidersConfig(+ openai=OpenAIConfig(api_key="sk-test" if openai else "", configured=openai),+ anthropic=AnthropicConfig(api_key="sk-ant" if anthropic else "", configured=anthropic),+ ollama=OllamaConfig(+ endpoint="http://localhost:11434" if ollama else "", configured=ollama+ ),+ watsonx=WatsonXConfig(+ api_key="wx-key" if watsonx else "",+ endpoint="https://us-south.ml.cloud.ibm.com" if watsonx else "",+ project_id="pid" if watsonx else "",+ configured=watsonx,+ ),+ ),+ knowledge=KnowledgeConfig(+ embedding_model=embedding_model,+ embedding_provider=embedding_provider,+ ),+ agent=AgentConfig(+ llm_model=llm_model,+ llm_provider=llm_provider,+ ),+ onboarding=OnboardingState(),+ edited=True,+ )+++# ---------------------------------------------------------------------------+# _default_llm_model+# ---------------------------------------------------------------------------+++class TestDefaultLlmModel:+ def test_openai_returns_static_default(self):+ assert _default_llm_model("openai") == OPENAI_DEFAULT_LANGUAGE_MODEL++ def test_anthropic_returns_static_default(self):+ assert _default_llm_model("anthropic") == ANTHROPIC_DEFAULT_LANGUAGE_MODEL++ def test_ollama_returns_empty(self):+ assert _default_llm_model("ollama") == ""++ def test_watsonx_returns_empty(self):+ assert _default_llm_model("watsonx") == ""++ def test_unknown_provider_returns_empty(self):+ assert _default_llm_model("nonexistent") == ""+++# ---------------------------------------------------------------------------+# _default_embedding_model+# ---------------------------------------------------------------------------+++class TestDefaultEmbeddingModel:+ def test_openai_returns_static_default(self):+ assert _default_embedding_model("openai") == OPENAI_DEFAULT_EMBEDDING_MODEL++ def test_ollama_returns_empty(self):+ assert _default_embedding_model("ollama") == ""++ def test_watsonx_returns_empty(self):+ assert _default_embedding_model("watsonx") == ""++ def test_unknown_provider_returns_empty(self):+ assert _default_embedding_model("nonexistent") == ""+++# ---------------------------------------------------------------------------+# _first_configured_llm_provider+# ---------------------------------------------------------------------------+++class TestFirstConfiguredLlmProvider:+ def test_excludes_removed_provider(self):+ config = _make_config(openai=True, anthropic=True)+ assert _first_configured_llm_provider(config, "openai") == "anthropic"++ def test_respects_priority_order(self):+ """Order is openai > anthropic > watsonx > ollama."""+ config = _make_config(openai=True, anthropic=True, watsonx=True, ollama=True)+ assert _first_configured_llm_provider(config, "openai") == "anthropic"+ assert _first_configured_llm_provider(config, "anthropic") == "openai"++ def test_skips_unconfigured(self):+ config = _make_config(ollama=True)+ assert _first_configured_llm_provider(config, "openai") == "ollama"++ def test_falls_back_to_openai_when_none_configured(self):+ config = _make_config()+ assert _first_configured_llm_provider(config, "anthropic") == "openai"+++# ---------------------------------------------------------------------------+# _first_configured_embedding_provider+# ---------------------------------------------------------------------------+++class TestFirstConfiguredEmbeddingProvider:+ def test_excludes_removed_provider(self):+ config = _make_config(openai=True, ollama=True)+ assert _first_configured_embedding_provider(config, "openai") == "ollama"++ def test_anthropic_never_returned(self):+ """Anthropic has no embedding models; it must never be a fallback."""+ config = _make_config(anthropic=True, ollama=True)+ assert _first_configured_embedding_provider(config, "openai") == "ollama"++ def test_respects_priority_order(self):+ """Order is openai > watsonx > ollama."""+ config = _make_config(openai=True, watsonx=True, ollama=True)+ assert _first_configured_embedding_provider(config, "openai") == "watsonx"++ def test_returns_empty_when_none_configured(self):+ config = _make_config()+ assert _first_configured_embedding_provider(config, "ollama") == ""+++# ---------------------------------------------------------------------------+# Simulated provider removal: LLM model default+# ---------------------------------------------------------------------------+++class TestProviderRemovalLlmDefault:+ """Simulate the provider-removal code path from endpoints.py and verify+ that the resulting llm_model is a sensible default, not empty."""++ def _simulate_llm_removal(self, config: OpenRAGConfig, removed: str):+ """Replicate the fallback logic from update_settings()."""+ if config.agent.llm_provider == removed:+ fb = _first_configured_llm_provider(config, removed)+ config.agent.llm_provider = fb+ config.agent.llm_model = _default_llm_model(fb)++ def test_remove_anthropic_falls_back_to_openai_model(self):+ config = _make_config(+ openai=True,+ anthropic=True,+ llm_provider="anthropic",+ llm_model="claude-sonnet-4-6",+ )+ self._simulate_llm_removal(config, "anthropic")+ assert config.agent.llm_provider == "openai"+ assert config.agent.llm_model == OPENAI_DEFAULT_LANGUAGE_MODEL++ def test_remove_openai_falls_back_to_anthropic_model(self):+ config = _make_config(+ openai=True,+ anthropic=True,+ llm_provider="openai",+ llm_model="gpt-5.4-mini",+ )+ self._simulate_llm_removal(config, "openai")+ assert config.agent.llm_provider == "anthropic"+ assert config.agent.llm_model == ANTHROPIC_DEFAULT_LANGUAGE_MODEL++ def test_remove_openai_falls_back_to_ollama_empty_model(self):+ """Ollama models are dynamic — backend returns empty, frontend picks."""+ config = _make_config(+ openai=True,+ ollama=True,+ llm_provider="openai",+ llm_model="gpt-5.4-mini",+ )+ self._simulate_llm_removal(config, "openai")+ assert config.agent.llm_provider == "ollama"+ assert config.agent.llm_model == ""++ def test_remove_watsonx_falls_back_to_openai_model(self):+ config = _make_config(+ openai=True,+ watsonx=True,+ llm_provider="watsonx",+ llm_model="ibm/granite-13b-chat-v2",+ )+ self._simulate_llm_removal(config, "watsonx")+ assert config.agent.llm_provider == "openai"+ assert config.agent.llm_model == OPENAI_DEFAULT_LANGUAGE_MODEL++ def test_no_change_if_different_provider_removed(self):+ """If the removed provider wasn't the active one, nothing changes."""+ config = _make_config(+ openai=True,+ anthropic=True,+ llm_provider="openai",+ llm_model="gpt-5.4-mini",+ )+ self._simulate_llm_removal(config, "anthropic")+ assert config.agent.llm_provider == "openai"+ assert config.agent.llm_model == "gpt-5.4-mini"+++# ---------------------------------------------------------------------------+# Simulated provider removal: embedding model default+# ---------------------------------------------------------------------------+++class TestProviderRemovalEmbeddingDefault:+ """Simulate embedding provider fallback on removal."""++ def _simulate_embedding_removal(self, config: OpenRAGConfig, removed: str):+ if config.knowledge.embedding_provider == removed:+ fb = _first_configured_embedding_provider(config, removed)+ config.knowledge.embedding_provider = fb+ config.knowledge.embedding_model = _default_embedding_model(fb)++ def test_remove_ollama_falls_back_to_openai_embedding(self):+ config = _make_config(+ openai=True,+ ollama=True,+ embedding_provider="ollama",+ embedding_model="nomic-embed-text",+ )+ self._simulate_embedding_removal(config, "ollama")+ assert config.knowledge.embedding_provider == "openai"+ assert config.knowledge.embedding_model == OPENAI_DEFAULT_EMBEDDING_MODEL++ def test_remove_openai_falls_back_to_watsonx_empty_embedding(self):+ config = _make_config(+ openai=True,+ watsonx=True,+ embedding_provider="openai",+ embedding_model="text-embedding-3-small",+ )+ self._simulate_embedding_removal(config, "openai")+ assert config.knowledge.embedding_provider == "watsonx"+ assert config.knowledge.embedding_model == ""++ def test_remove_watsonx_falls_back_to_openai_embedding(self):+ config = _make_config(+ openai=True,+ watsonx=True,+ embedding_provider="watsonx",+ embedding_model="ibm/slate-125m-english-rtrvr",+ )+ self._simulate_embedding_removal(config, "watsonx")+ assert config.knowledge.embedding_provider == "openai"+ assert config.knowledge.embedding_model == OPENAI_DEFAULT_EMBEDDING_MODEL++ def test_no_change_if_different_provider_removed(self):+ config = _make_config(+ openai=True,+ ollama=True,+ embedding_provider="openai",+ embedding_model="text-embedding-3-small",+ )+ self._simulate_embedding_removal(config, "ollama")+ assert config.knowledge.embedding_provider == "openai"+ assert config.knowledge.embedding_model == "text-embedding-3-small"