| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | from enum import Enum | 
					
						
							|  |  |  | from typing import Optional | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | from core.model_runtime.entities.model_entities import ModelType | 
					
						
							|  |  |  | from models.provider import ProviderQuotaType | 
					
						
							| 
									
										
										
										
											2024-01-12 12:34:01 +08:00
										 |  |  | from pydantic import BaseModel | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QuotaUnit(Enum): | 
					
						
							|  |  |  |     TIMES = 'times' | 
					
						
							|  |  |  |     TOKENS = 'tokens' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SystemConfigurationStatus(Enum): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Enum class for system configuration status. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     ACTIVE = 'active' | 
					
						
							|  |  |  |     QUOTA_EXCEEDED = 'quota-exceeded' | 
					
						
							|  |  |  |     UNSUPPORTED = 'unsupported' | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-09 19:17:47 +08:00
										 |  |  | class RestrictModel(BaseModel): | 
					
						
							|  |  |  |     model: str | 
					
						
							|  |  |  |     base_model_name: Optional[str] = None | 
					
						
							|  |  |  |     model_type: ModelType | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | class QuotaConfiguration(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for provider quota configuration. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     quota_type: ProviderQuotaType | 
					
						
							|  |  |  |     quota_unit: QuotaUnit | 
					
						
							|  |  |  |     quota_limit: int | 
					
						
							|  |  |  |     quota_used: int | 
					
						
							|  |  |  |     is_valid: bool | 
					
						
							| 
									
										
										
										
											2024-01-09 19:17:47 +08:00
										 |  |  |     restrict_models: list[RestrictModel] = [] | 
					
						
							| 
									
										
										
										
											2024-01-02 23:42:00 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SystemConfiguration(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for provider system configuration. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     enabled: bool | 
					
						
							|  |  |  |     current_quota_type: Optional[ProviderQuotaType] = None | 
					
						
							|  |  |  |     quota_configurations: list[QuotaConfiguration] = [] | 
					
						
							|  |  |  |     credentials: Optional[dict] = None | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CustomProviderConfiguration(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for provider custom configuration. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     credentials: dict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CustomModelConfiguration(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for provider custom model configuration. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     model: str | 
					
						
							|  |  |  |     model_type: ModelType | 
					
						
							|  |  |  |     credentials: dict | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class CustomConfiguration(BaseModel): | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     Model class for provider custom configuration. | 
					
						
							|  |  |  |     """
 | 
					
						
							|  |  |  |     provider: Optional[CustomProviderConfiguration] = None | 
					
						
							|  |  |  |     models: list[CustomModelConfiguration] = [] |