mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-09-05 15:36:45 +08:00
refactor: 优化代码格式,增强可读性;调整类型注解和字段命名风格
This commit is contained in:
@@ -1,12 +1,30 @@
|
|||||||
from typing import List, Optional, Dict, Any, Literal, Union
|
from typing import Any, Dict, List, Literal, Optional, Union
|
||||||
from pydantic import BaseModel
|
|
||||||
|
from pydantic import BaseModel, Field
|
||||||
|
|
||||||
from app.core.constants import DEFAULT_TEMPERATURE, DEFAULT_TOP_K, DEFAULT_TOP_P
|
from app.core.constants import DEFAULT_TEMPERATURE, DEFAULT_TOP_K, DEFAULT_TOP_P
|
||||||
|
|
||||||
|
|
||||||
class SafetySetting(BaseModel):
|
class SafetySetting(BaseModel):
|
||||||
category: Optional[Literal["HARM_CATEGORY_HATE_SPEECH", "HARM_CATEGORY_DANGEROUS_CONTENT", "HARM_CATEGORY_HARASSMENT", "HARM_CATEGORY_SEXUALLY_EXPLICIT", "HARM_CATEGORY_CIVIC_INTEGRITY"]] = None
|
category: Optional[
|
||||||
threshold: Optional[Literal["HARM_BLOCK_THRESHOLD_UNSPECIFIED", "BLOCK_LOW_AND_ABOVE", "BLOCK_MEDIUM_AND_ABOVE", "BLOCK_ONLY_HIGH", "BLOCK_NONE", "OFF"]] = None
|
Literal[
|
||||||
|
"HARM_CATEGORY_HATE_SPEECH",
|
||||||
|
"HARM_CATEGORY_DANGEROUS_CONTENT",
|
||||||
|
"HARM_CATEGORY_HARASSMENT",
|
||||||
|
"HARM_CATEGORY_SEXUALLY_EXPLICIT",
|
||||||
|
"HARM_CATEGORY_CIVIC_INTEGRITY",
|
||||||
|
]
|
||||||
|
] = None
|
||||||
|
threshold: Optional[
|
||||||
|
Literal[
|
||||||
|
"HARM_BLOCK_THRESHOLD_UNSPECIFIED",
|
||||||
|
"BLOCK_LOW_AND_ABOVE",
|
||||||
|
"BLOCK_MEDIUM_AND_ABOVE",
|
||||||
|
"BLOCK_ONLY_HIGH",
|
||||||
|
"BLOCK_NONE",
|
||||||
|
"OFF",
|
||||||
|
]
|
||||||
|
] = None
|
||||||
|
|
||||||
|
|
||||||
class GenerationConfig(BaseModel):
|
class GenerationConfig(BaseModel):
|
||||||
@@ -26,7 +44,7 @@ class GenerationConfig(BaseModel):
|
|||||||
|
|
||||||
class SystemInstruction(BaseModel):
|
class SystemInstruction(BaseModel):
|
||||||
role: str = "system"
|
role: str = "system"
|
||||||
parts: List[Dict[str, Any]]|Dict[str, Any]
|
parts: List[Dict[str, Any]] | Dict[str, Any]
|
||||||
|
|
||||||
|
|
||||||
class GeminiContent(BaseModel):
|
class GeminiContent(BaseModel):
|
||||||
@@ -37,9 +55,18 @@ class GeminiContent(BaseModel):
|
|||||||
class GeminiRequest(BaseModel):
|
class GeminiRequest(BaseModel):
|
||||||
contents: List[GeminiContent] = []
|
contents: List[GeminiContent] = []
|
||||||
tools: Optional[Union[List[Dict[str, Any]], Dict[str, Any]]] = []
|
tools: Optional[Union[List[Dict[str, Any]], Dict[str, Any]]] = []
|
||||||
safetySettings: Optional[List[SafetySetting]] = None
|
safety_settings: Optional[List[SafetySetting]] = Field(
|
||||||
generationConfig: Optional[GenerationConfig] = None
|
default=None, alias="safetySettings"
|
||||||
systemInstruction: Optional[SystemInstruction] = None
|
)
|
||||||
|
generation_config: Optional[GenerationConfig] = Field(
|
||||||
|
default=None, alias="generationConfig"
|
||||||
|
)
|
||||||
|
system_instruction: Optional[SystemInstruction] = Field(
|
||||||
|
default=None, alias="systemInstruction"
|
||||||
|
)
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
populate_by_name = True
|
||||||
|
|
||||||
|
|
||||||
class ResetSelectedKeysRequest(BaseModel):
|
class ResetSelectedKeysRequest(BaseModel):
|
||||||
|
|||||||
Reference in New Issue
Block a user