Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BFCL] Update tool construction for Palmyra models #897

Merged
merged 1 commit into from
Feb 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions berkeley-function-call-leaderboard/bfcl/model_handler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ def convert_to_tool(functions, mapping, model_style):
item["inputSchema"] = {"json": item["parameters"]}
del item["parameters"]

if model_style == ModelStyle.Google:
# Remove fields that are not supported by Gemini.
if model_style in [
ModelStyle.Google,
ModelStyle.WRITER,
]:
# Remove fields that are not supported by Gemini or Palmyra.
# No `optional` field in function schema.
if "optional" in item["parameters"]:
del item["parameters"]["optional"]
for params in item["parameters"]["properties"].values():
# No `default` field in Google's schema.
# No `default` field in Google or Palmyra's schema.
if "default" in params:
params["description"] += f" Default is: {str(params['default'])}."
del params["default"]
Expand Down Expand Up @@ -129,8 +132,12 @@ def convert_to_tool(functions, mapping, model_style):
"description"
] += f" Additional properties: {str(params['additionalProperties'])}."
del params["additionalProperties"]
# Only `enum` field when the type is `string`.
if "enum" in params and params["type"] != "string":
# For Gemini, only `enum` field when the type is `string`.
# For Palmyra, `enum` field is not supported.
if "enum" in params and (
model_style == ModelStyle.WRITER
or (model_style == ModelStyle.Google and params["type"] != "string")
):
params["description"] += f" Enum values: {str(params['enum'])}."
del params["enum"]

Expand Down