mirror of
https://github.com/snailyp/gemini-balance.git
synced 2026-07-21 04:22:16 +08:00
feat: 根据模型版本调整安全设置逻辑
This commit is contained in:
@@ -53,7 +53,7 @@ class GeminiChatService:
|
||||
return {
|
||||
"contents": payload.get("contents", []),
|
||||
"tools": self._build_tools(model, payload),
|
||||
"safetySettings": self._get_safety_settings(),
|
||||
"safetySettings": self._get_safety_settings(model),
|
||||
"generationConfig": payload.get("generationConfig", {}),
|
||||
"systemInstruction": payload.get("systemInstruction", [])
|
||||
}
|
||||
@@ -78,12 +78,20 @@ class GeminiChatService:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _get_safety_settings(self) -> List[Dict[str, str]]:
|
||||
def _get_safety_settings(self, model: str) -> List[Dict[str, str]]:
|
||||
"""获取安全设置"""
|
||||
if "2.0" in model and model != "gemini-2.0-flash-thinking-exp":
|
||||
return [
|
||||
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_ONLY_HIGH"}
|
||||
]
|
||||
return [
|
||||
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_NONE"}
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_ONLY_HIGH"}
|
||||
]
|
||||
@@ -100,7 +100,7 @@ class OpenAIChatService:
|
||||
"topK": request.top_k
|
||||
},
|
||||
"tools": self._build_tools(request, messages),
|
||||
"safetySettings": self._get_safety_settings()
|
||||
"safetySettings": self._get_safety_settings(request.model)
|
||||
}
|
||||
|
||||
def _build_tools(self, request: ChatRequest, messages: List[Dict[str, Any]]) -> List[Dict[str, Any]]:
|
||||
@@ -125,12 +125,20 @@ class OpenAIChatService:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _get_safety_settings(self) -> List[Dict[str, str]]:
|
||||
def _get_safety_settings(self, model: str) -> List[Dict[str, str]]:
|
||||
"""获取安全设置"""
|
||||
if "2.0" in model and model != "gemini-2.0-flash-thinking-exp":
|
||||
return [
|
||||
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "OFF"},
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_ONLY_HIGH"}
|
||||
]
|
||||
return [
|
||||
{"category": "HARM_CATEGORY_HARASSMENT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_HATE_SPEECH", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_SEXUALLY_EXPLICIT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_DANGEROUS_CONTENT", "threshold": "BLOCK_NONE"},
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_NONE"}
|
||||
{"category": "HARM_CATEGORY_CIVIC_INTEGRITY", "threshold": "BLOCK_ONLY_HIGH"}
|
||||
]
|
||||
Reference in New Issue
Block a user