From 6a2eb5f442ad8b41a5f10d102e16fa123013e8ff Mon Sep 17 00:00:00 2001 From: takatost Date: Thu, 4 Jan 2024 10:53:50 +0800 Subject: [PATCH] fix: customize model schema fetch failed raise error (#1900) --- api/core/entities/provider_configuration.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/api/core/entities/provider_configuration.py b/api/core/entities/provider_configuration.py index 2228560a87ff97..a587ec9cf71e1b 100644 --- a/api/core/entities/provider_configuration.py +++ b/api/core/entities/provider_configuration.py @@ -1,5 +1,6 @@ import datetime import json +import logging import time from json import JSONDecodeError from typing import Optional, List, Dict, Tuple, Iterator @@ -18,6 +19,8 @@ from extensions.ext_database import db from models.provider import ProviderType, Provider, ProviderModel, TenantPreferredModelProvider +logger = logging.getLogger(__name__) + class ProviderConfiguration(BaseModel): """ @@ -544,13 +547,17 @@ def _get_custom_provider_models(self, if model_configuration.model_type not in model_types: continue - custom_model_schema = ( - provider_instance.get_model_instance(model_configuration.model_type) - .get_customizable_model_schema_from_credentials( - model_configuration.model, - model_configuration.credentials + try: + custom_model_schema = ( + provider_instance.get_model_instance(model_configuration.model_type) + .get_customizable_model_schema_from_credentials( + model_configuration.model, + model_configuration.credentials + ) ) - ) + except Exception as ex: + logger.warning(f'get custom model schema failed, {ex}') + continue if not custom_model_schema: continue