fix(gemini): 对 thinking_budget 不同模型的处理

pull/1205/head
foxplaying 2025-08-21 05:53:03 +08:00 committed by GitHub
parent 068b2dc3d6
commit ea64f1b2ed
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 6 deletions

View File

@ -345,21 +345,19 @@ class GeminiClient(BaseClient):
""" """
按模型限制思考预算范围仅支持指定的模型支持带数字后缀的新版本 按模型限制思考预算范围仅支持指定的模型支持带数字后缀的新版本
""" """
# 精确匹配或更精确的包含匹配
limits = None limits = None
matched_key = None matched_key = None
# 先尝试精确匹配 # 先尝试精确匹配
if model_id in THINKING_BUDGET_LIMITS: if model_id in THINKING_BUDGET_LIMITS:
limits = THINKING_BUDGET_LIMITS[model_id] limits = THINKING_BUDGET_LIMITS[model_id]
matched_key = model_id matched_key = model_id
else: else:
# 如果没有精确匹配,尝试更精确的包含匹配 # 按 key 长度倒序,保证更长的(更具体的,如 -lite优先
# 按键的长度降序排序,优先匹配更长的键
sorted_keys = sorted(THINKING_BUDGET_LIMITS.keys(), key=len, reverse=True) sorted_keys = sorted(THINKING_BUDGET_LIMITS.keys(), key=len, reverse=True)
for key in sorted_keys: for key in sorted_keys:
# 使用更精确的匹配逻辑键必须是模型ID的一部分但不能是部分匹配 # 必须满足:完全等于 或者 前缀匹配(带 "-" 边界)
if key in model_id and (model_id == key or model_id.startswith(key + "-")): if model_id == key or model_id.startswith(key + "-"):
limits = THINKING_BUDGET_LIMITS[key] limits = THINKING_BUDGET_LIMITS[key]
matched_key = key matched_key = key
break break