mirror of
https://github.com/zhenxun-org/zhenxun_bot.git
synced 2025-12-15 14:22:55 +08:00
🐛 fix(gemini): 增加响应验证以处理内容过滤(promptFeedback)
This commit is contained in:
parent
50c04f3625
commit
ddbe75704d
@ -354,6 +354,24 @@ class GeminiAdapter(BaseAdapter):
|
|||||||
|
|
||||||
return safety_settings if safety_settings else None
|
return safety_settings if safety_settings else None
|
||||||
|
|
||||||
|
def validate_response(self, response_json: dict[str, Any]) -> None:
|
||||||
|
"""验证 Gemini API 响应,增加对 promptFeedback 的检查"""
|
||||||
|
super().validate_response(response_json)
|
||||||
|
|
||||||
|
if prompt_feedback := response_json.get("promptFeedback"):
|
||||||
|
if block_reason := prompt_feedback.get("blockReason"):
|
||||||
|
logger.warning(
|
||||||
|
f"Gemini 内容因 promptFeedback 被安全过滤: {block_reason}"
|
||||||
|
)
|
||||||
|
raise LLMException(
|
||||||
|
f"内容被安全过滤: {block_reason}",
|
||||||
|
code=LLMErrorCode.CONTENT_FILTERED,
|
||||||
|
details={
|
||||||
|
"block_reason": block_reason,
|
||||||
|
"safety_ratings": prompt_feedback.get("safetyRatings"),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
def parse_response(
|
def parse_response(
|
||||||
self,
|
self,
|
||||||
model: "LLMModel",
|
model: "LLMModel",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user