Fix: Handle dict input for tool arguments in call_tool
This commit is contained in:
@@ -78,16 +78,30 @@ class BaseTelegramInferenceBot(ABC):
|
||||
|
||||
def call_tool(self, function_call_name, function_call_arguments):
|
||||
function_name = function_call_name
|
||||
function_args = None
|
||||
if isinstance(function_call_arguments, dict):
|
||||
function_args = function_call_arguments
|
||||
elif isinstance(function_call_arguments, str):
|
||||
try:
|
||||
function_args = json.loads(function_call_arguments if function_call_arguments is not None else "{}")
|
||||
function_args = json.loads(function_call_arguments)
|
||||
except json.JSONDecodeError as e:
|
||||
logging.error(f"Error decoding function call arguments for {function_call_name}: {e}. Arguments: {function_call_arguments}")
|
||||
logging.error(f"Error decoding function call arguments (string) for {function_call_name}: {e}. Arguments: {function_call_arguments}")
|
||||
return f"Error: Malformed arguments for tool call: {e}"
|
||||
else: # Handle cases where arguments might be None or other unexpected types
|
||||
if function_call_arguments is None:
|
||||
function_args = {} # Default to empty dict if arguments are None
|
||||
else:
|
||||
logging.error(f"Unexpected type for function_call_arguments for {function_call_name}: {type(function_call_arguments)}. Arguments: {function_call_arguments}")
|
||||
return f"Error: Invalid argument type for tool call: {type(function_call_arguments)}"
|
||||
|
||||
for tool in self.tools:
|
||||
for function in tool.get_functions():
|
||||
if function["function"]["name"] == function_name:
|
||||
try:
|
||||
# Ensure function_args is a dictionary before unpacking
|
||||
if not isinstance(function_args, dict):
|
||||
logging.error(f"Internal error: function_args not a dict for {function_name} before execution. Args: {function_args}")
|
||||
return f"Internal error preparing arguments for tool {function_name}."
|
||||
return tool.execute(function_name, **function_args)
|
||||
except Exception as e:
|
||||
logging.error(f"Error executing tool {function_name} with args {function_args}: {e}")
|
||||
|
||||
Reference in New Issue
Block a user