Skip to content

Commit

Permalink
[BFCL] Update tool construction for Palmyra models (#897)
Browse files Browse the repository at this point in the history
I've updated `utils.py` in BFCL to reflect some needed changes to how
tools are constructed when using Writer's models such as Palmyra X 004.

cc @HuanzhiMao
  • Loading branch information
samjulien authored Feb 2, 2025
1 parent c5ffaf0 commit cfca2f4
Showing 1 changed file with 12 additions and 5 deletions.
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

0 comments on commit cfca2f4

Please sign in to comment.