Skip to content

Commit 33cabef

Browse files
authored
Fix breaking changes due to updated Anthropic SDK (#452)
Anthropic just moved their tool use from beta to main so we have to change the import `from anthropic.types.beta.tools import ToolUseBlock` to `from anthropic.types import ToolUseBlock`. You cannot run the eval without this change as things break. Also, my IDE automatically sorted the imported packages and removed some extra spaces -- this explains all the other changes.
1 parent fade5e4 commit 33cabef

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

berkeley-function-call-leaderboard/model_handler/claude_fc_handler.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
1-
from model_handler.handler import BaseHandler
1+
import json
2+
import os
3+
import time
4+
25
from anthropic import Anthropic
3-
from anthropic.types import TextBlock
4-
from anthropic.types.beta.tools import ToolUseBlock
5-
from model_handler.model_style import ModelStyle
6+
from anthropic.types import TextBlock, ToolUseBlock
67
from model_handler.claude_prompt_handler import ClaudePromptingHandler
8+
from model_handler.constant import GORILLA_TO_OPENAPI
9+
from model_handler.handler import BaseHandler
10+
from model_handler.model_style import ModelStyle
711
from model_handler.utils import (
8-
convert_to_tool,
12+
ast_parse,
913
augment_prompt_by_languge,
14+
convert_to_function_call,
15+
convert_to_tool,
1016
language_specific_pre_processing,
11-
ast_parse,
12-
convert_to_function_call
1317
)
14-
from model_handler.constant import GORILLA_TO_OPENAPI
15-
import os, time, json
1618

1719

1820
class ClaudeFCHandler(BaseHandler):
@@ -52,7 +54,7 @@ def inference(self, prompt, functions, test_category):
5254
tool_call_outputs.append({content.name: json.dumps(content.input)})
5355
result = tool_call_outputs if tool_call_outputs else text_outputs[0]
5456
return result, {"input_tokens": response.usage.input_tokens, "output_tokens": response.usage.output_tokens, "latency": latency}
55-
57+
5658
def decode_ast(self,result,language="Python"):
5759
if "FC" not in self.model_name:
5860
decoded_output = ast_parse(result,language)
@@ -69,7 +71,7 @@ def decode_ast(self,result,language="Python"):
6971
params[key] = str(params[key])
7072
decoded_output.append({name: params})
7173
return decoded_output
72-
74+
7375
def decode_execute(self,result):
7476
if "FC" not in self.model_name:
7577
decoded_output = ast_parse(result)
@@ -82,4 +84,4 @@ def decode_execute(self,result):
8284
return execution_list
8385
else:
8486
function_call = convert_to_function_call(result)
85-
return function_call
87+
return function_call

0 commit comments

Comments
 (0)