Skip to content

Commit

Permalink
[BFCL] Fix Irrelevance Category Performance for DeepSeek Coder Handler (
Browse files Browse the repository at this point in the history
ShishirPatil#796)

This PR updates the decoding logic for DeepSeek-Coder handler to fix its
performance issue in the irrelevance category.
The irrelevance category metric we use is that, either the `decode_ast`
should fail (error) or the decoded output is empty (eg, empty list or
empty string).

For the DeepSeek-Coder model, 
When it outputs a valid function call, the model response will be a list
of dictionaries `[{func1:{param1:val1,...}},{func2:{param2:val2,...}}]`,
so it's fine for `decode_ast` to just return it without any processing.
However, when the output is a message (not valid function call), under
the `_parse_query_response_prompting` logic, the model response will be
that message string, and in the current `decode_ast` implementation,
that string will just be treated as the decoded output, and it would
fail both the metric for the irrelevance category, which is not ideal.
  • Loading branch information
HuanzhiMao authored and VishnuSuresh27 committed Nov 28, 2024
1 parent c3520ad commit 77a0cbb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
20 changes: 16 additions & 4 deletions berkeley-function-call-leaderboard/bfcl/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,22 @@ def list_commands(self, ctx):
)


# Input is like 'a,b,c,d', we need to transform it to ['a', 'b', 'c', 'd'] because that's the expected format in the actual main funciton
handle_multiple_input = lambda x: [
item.strip() for item in ",".join(x).split(",") if item.strip()
]
def handle_multiple_input(input_str):
"""
Input is like 'a,b,c,d', we need to transform it to ['a', 'b', 'c', 'd'] because that's the expected format in the actual main funciton
"""
if input_str is None:
"""
Cannot return None here, as typer will check the length of the return value and len(None) will raise an error
But when default is None, an empty list will be internally converted to None, and so the pipeline still works as expected
```
if default_value is None and len(value) == 0:
return None
```
"""
return []

return [item.strip() for item in ",".join(input_str).split(",") if item.strip()]


@cli.command()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@ def __init__(self, model_name, temperature) -> None:

@overrides
def decode_ast(self, result, language="Python"):
# The input is already a list of dictionaries, so no need to decode
# `[{func1:{param1:val1,...}},{func2:{param2:val2,...}}]`
if type(result) != list:
return []
return result

@overrides
def decode_execute(self, result):
if type(result) != list:
return []
return convert_to_function_call(result)

@overrides
Expand Down

0 comments on commit 77a0cbb

Please sign in to comment.