From 8635aacb46ceda44ed35f37512c827dc57e96450 Mon Sep 17 00:00:00 2001 From: Xiyuan Chen <52963600+GareArc@users.noreply.github.com> Date: Mon, 15 Sep 2025 23:15:53 -0700 Subject: [PATCH] =?UTF-8?q?Enhance=20LLM=20model=20configuration=20validat?= =?UTF-8?q?ion=20to=20include=20active=20status=20c=E2=80=A6=20(#25759)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com> --- api/services/workflow_service.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/api/services/workflow_service.py b/api/services/workflow_service.py index abda024555..ea73b6105e 100644 --- a/api/services/workflow_service.py +++ b/api/services/workflow_service.py @@ -375,13 +375,14 @@ class WorkflowService: def _validate_llm_model_config(self, tenant_id: str, provider: str, model_name: str) -> None: """ - Validate that an LLM model configuration can fetch valid credentials. + Validate that an LLM model configuration can fetch valid credentials and has active status. This method attempts to get the model instance and validates that: 1. The provider exists and is configured 2. The model exists in the provider 3. Credentials can be fetched for the model 4. The credentials pass policy compliance checks + 5. The model status is ACTIVE (not NO_CONFIGURE, DISABLED, etc.) :param tenant_id: The tenant ID :param provider: The provider name @@ -391,6 +392,7 @@ class WorkflowService: try: from core.model_manager import ModelManager from core.model_runtime.entities.model_entities import ModelType + from core.provider_manager import ProviderManager # Get model instance to validate provider+model combination model_manager = ModelManager() @@ -402,6 +404,22 @@ class WorkflowService: # via ProviderConfiguration.get_current_credentials() -> _check_credential_policy_compliance() # If it fails, an exception will be raised + # Additionally, check the model status to ensure it's ACTIVE + provider_manager = ProviderManager() + provider_configurations = provider_manager.get_configurations(tenant_id) + models = provider_configurations.get_models(provider=provider, model_type=ModelType.LLM) + + target_model = None + for model in models: + if model.model == model_name and model.provider.provider == provider: + target_model = model + break + + if target_model: + target_model.raise_for_status() + else: + raise ValueError(f"Model {model_name} not found for provider {provider}") + except Exception as e: raise ValueError( f"Failed to validate LLM model configuration (provider: {provider}, model: {model_name}): {str(e)}"