| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 | 
							- from collections.abc import Sequence
 
- from enum import Enum
 
- from typing import Optional
 
- from pydantic import BaseModel, ConfigDict, Field, field_validator
 
- from core.model_runtime.entities.common_entities import I18nObject
 
- from core.model_runtime.entities.model_entities import AIModelEntity, ModelType
 
- class ConfigurateMethod(Enum):
 
-     """
 
-     Enum class for configurate method of provider model.
 
-     """
 
-     PREDEFINED_MODEL = "predefined-model"
 
-     CUSTOMIZABLE_MODEL = "customizable-model"
 
- class FormType(Enum):
 
-     """
 
-     Enum class for form type.
 
-     """
 
-     TEXT_INPUT = "text-input"
 
-     SECRET_INPUT = "secret-input"
 
-     SELECT = "select"
 
-     RADIO = "radio"
 
-     SWITCH = "switch"
 
- class FormShowOnObject(BaseModel):
 
-     """
 
-     Model class for form show on.
 
-     """
 
-     variable: str
 
-     value: str
 
- class FormOption(BaseModel):
 
-     """
 
-     Model class for form option.
 
-     """
 
-     label: I18nObject
 
-     value: str
 
-     show_on: list[FormShowOnObject] = []
 
-     def __init__(self, **data):
 
-         super().__init__(**data)
 
-         if not self.label:
 
-             self.label = I18nObject(en_US=self.value)
 
- class CredentialFormSchema(BaseModel):
 
-     """
 
-     Model class for credential form schema.
 
-     """
 
-     variable: str
 
-     label: I18nObject
 
-     type: FormType
 
-     required: bool = True
 
-     default: Optional[str] = None
 
-     options: Optional[list[FormOption]] = None
 
-     placeholder: Optional[I18nObject] = None
 
-     max_length: int = 0
 
-     show_on: list[FormShowOnObject] = []
 
- class ProviderCredentialSchema(BaseModel):
 
-     """
 
-     Model class for provider credential schema.
 
-     """
 
-     credential_form_schemas: list[CredentialFormSchema]
 
- class FieldModelSchema(BaseModel):
 
-     label: I18nObject
 
-     placeholder: Optional[I18nObject] = None
 
- class ModelCredentialSchema(BaseModel):
 
-     """
 
-     Model class for model credential schema.
 
-     """
 
-     model: FieldModelSchema
 
-     credential_form_schemas: list[CredentialFormSchema]
 
- class SimpleProviderEntity(BaseModel):
 
-     """
 
-     Simple model class for provider.
 
-     """
 
-     provider: str
 
-     label: I18nObject
 
-     icon_small: Optional[I18nObject] = None
 
-     icon_large: Optional[I18nObject] = None
 
-     supported_model_types: Sequence[ModelType]
 
-     models: list[AIModelEntity] = []
 
- class ProviderHelpEntity(BaseModel):
 
-     """
 
-     Model class for provider help.
 
-     """
 
-     title: I18nObject
 
-     url: I18nObject
 
- class ProviderEntity(BaseModel):
 
-     """
 
-     Model class for provider.
 
-     """
 
-     provider: str
 
-     label: I18nObject
 
-     description: Optional[I18nObject] = None
 
-     icon_small: Optional[I18nObject] = None
 
-     icon_large: Optional[I18nObject] = None
 
-     background: Optional[str] = None
 
-     help: Optional[ProviderHelpEntity] = None
 
-     supported_model_types: Sequence[ModelType]
 
-     configurate_methods: list[ConfigurateMethod]
 
-     models: list[AIModelEntity] = Field(default_factory=list)
 
-     provider_credential_schema: Optional[ProviderCredentialSchema] = None
 
-     model_credential_schema: Optional[ModelCredentialSchema] = None
 
-     # pydantic configs
 
-     model_config = ConfigDict(protected_namespaces=())
 
-     @field_validator("models", mode="before")
 
-     @classmethod
 
-     def validate_models(cls, v):
 
-         # returns EmptyList if v is empty
 
-         if not v:
 
-             return []
 
-         return v
 
-     def to_simple_provider(self) -> SimpleProviderEntity:
 
-         """
 
-         Convert to simple provider.
 
-         :return: simple provider
 
-         """
 
-         return SimpleProviderEntity(
 
-             provider=self.provider,
 
-             label=self.label,
 
-             icon_small=self.icon_small,
 
-             icon_large=self.icon_large,
 
-             supported_model_types=self.supported_model_types,
 
-             models=self.models,
 
-         )
 
- class ProviderConfig(BaseModel):
 
-     """
 
-     Model class for provider config.
 
-     """
 
-     provider: str
 
-     credentials: dict
 
 
  |