| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | from enum import Enum | 
					
						
							|  |  |  | from typing import Optional | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-14 01:05:37 +08:00
										 |  |  | from pydantic import BaseModel, ConfigDict | 
					
						
							| 
									
										
										
										
											2024-02-06 13:21:13 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | from core.model_runtime.entities.common_entities import I18nObject | 
					
						
							| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | from core.model_runtime.entities.model_entities import ModelType, ProviderModel | 
					
						
							| 
									
										
										
										
											2024-02-06 13:21:13 +08:00
										 |  |  | from core.model_runtime.entities.provider_entities import ProviderEntity | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ModelStatus(Enum): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Enum class for model status. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     ACTIVE = "active" | 
					
						
							|  |  |  |     NO_CONFIGURE = "no-configure" | 
					
						
							|  |  |  |     QUOTA_EXCEEDED = "quota-exceeded" | 
					
						
							|  |  |  |     NO_PERMISSION = "no-permission" | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:04 +08:00
										 |  |  |     DISABLED = "disabled" | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SimpleModelProviderEntity(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Simple provider. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     provider: str | 
					
						
							|  |  |  |     label: I18nObject | 
					
						
							|  |  |  |     icon_small: Optional[I18nObject] = None | 
					
						
							|  |  |  |     icon_large: Optional[I18nObject] = None | 
					
						
							|  |  |  |     supported_model_types: list[ModelType] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def __init__(self, provider_entity: ProviderEntity) -> None: | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         Init simple provider. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         :param provider_entity: provider entity | 
					
						
							|  |  |  |         """
 | 
					
						
							|  |  |  |         super().__init__( | 
					
						
							|  |  |  |             provider=provider_entity.provider, | 
					
						
							|  |  |  |             label=provider_entity.label, | 
					
						
							|  |  |  |             icon_small=provider_entity.icon_small, | 
					
						
							|  |  |  |             icon_large=provider_entity.icon_large, | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  |             supported_model_types=provider_entity.supported_model_types, | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |         ) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:04 +08:00
										 |  |  | class ProviderModelWithStatusEntity(ProviderModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for model response. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-06-05 00:13:04 +08:00
										 |  |  |     status: ModelStatus | 
					
						
							|  |  |  |     load_balancing_enabled: bool = False | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class ModelWithProviderEntity(ProviderModelWithStatusEntity): | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     """
 | 
					
						
							|  |  |  |     Model with provider entity. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     provider: SimpleModelProviderEntity | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DefaultModelProviderEntity(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Default model provider entity. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     provider: str | 
					
						
							|  |  |  |     label: I18nObject | 
					
						
							|  |  |  |     icon_small: Optional[I18nObject] = None | 
					
						
							|  |  |  |     icon_large: Optional[I18nObject] = None | 
					
						
							|  |  |  |     supported_model_types: list[ModelType] | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class DefaultModelEntity(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Default model entity. | 
					
						
							|  |  |  |     """
 | 
					
						
							| 
									
										
										
										
											2024-09-10 17:00:20 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  |     model: str | 
					
						
							|  |  |  |     model_type: ModelType | 
					
						
							|  |  |  |     provider: DefaultModelProviderEntity | 
					
						
							| 
									
										
										
										
											2024-06-14 01:05:37 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     # pydantic configs | 
					
						
							|  |  |  |     model_config = ConfigDict(protected_namespaces=()) |