@@ -526,6 +526,7 @@ def parse_agentlab_action_str_to_func_args(action: str):
526526 ('hotkey', [], {'keys': ['ctrl', 'alt', 't']})
527527 """
528528 try :
529+ action = action .strip ()
529530 parsed = ast .parse (action , mode = "eval" )
530531 if isinstance (parsed .body , ast .Call ):
531532 func_name = ast .unparse (parsed .body .func )
@@ -584,17 +585,22 @@ def to_tool_description(self, api="openai"):
584585 """
585586 # TODO: Rename bgym AbstractActionSet 'to_tool_descriptor' method as 'to_tool_description' for consistency.
586587 if self .action_space == "computer_13" :
587- tools = format_chat_completion_tools_to_response_api (
588- COMPUTER_13_ACTIONS_OAI_CHATCOMPLETION_TOOLS
589- )
588+ tools = COMPUTER_13_ACTIONS_OAI_CHATCOMPLETION_TOOLS
589+
590590 else :
591591 raise ValueError (
592592 "Only 'computer_13' action space is currently supported for tool description."
593593 )
594- if api == "anthropic" :
595- return format_chat_completion_tools_to_anthropic (tools )
596- else :
597- return tools
594+ api_formatters = {
595+ "openai" : lambda : format_chat_completion_tools_to_response_api (tools ),
596+ "chatcompletion" : lambda : tools ,
597+ "anthropic" : lambda : format_chat_completion_tools_to_anthropic (tools )
598+ }
599+
600+ if api not in api_formatters :
601+ raise ValueError (f"Unsupported API type: { api } " )
602+
603+ return api_formatters [api ]()
598604
599605
600606def format_chat_completion_tools_to_anthropic (tools : list [dict ]) -> list [dict ]:
0 commit comments