Skip to content

Commit

Permalink
🐛 Bug: Fix the bug where the Gemini API does not support the tool def…
Browse files Browse the repository at this point in the history
…ault field.
  • Loading branch information
yym68686 committed Dec 11, 2024
1 parent deea261 commit 5f0c2f2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion request.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,25 @@ async def get_gemini_payload(request, engine, provider):
for field, value in request.model_dump(exclude_unset=True).items():
if field not in miss_fields and value is not None:
if field == "tools":
# 处理每个工具的 function 定义
processed_tools = []
for tool in value:
function_def = tool["function"]
# 处理 parameters.properties 中的 default 字段
if safe_get(function_def, "parameters", "properties", default=None):
for prop_value in function_def["parameters"]["properties"].values():
if "default" in prop_value:
# 将 default 值添加到 description 中
default_value = prop_value["default"]
description = prop_value.get("description", "")
prop_value["description"] = f"{description}\nDefault: {default_value}"
# 删除 default 字段
del prop_value["default"]
processed_tools.append({"function": function_def})

payload.update({
"tools": [{
"function_declarations": [tool["function"] for tool in value]
"function_declarations": [tool["function"] for tool in processed_tools]
}],
"tool_config": {
"function_calling_config": {
Expand Down

0 comments on commit 5f0c2f2

Please sign in to comment.