chore(api/core): apply ruff reformatting (#7624)

This commit is contained in:
Bowen Liang
2024-09-10 17:00:20 +08:00
committed by GitHub
parent 178730266d
commit 2cf1187b32
724 changed files with 21180 additions and 21123 deletions

View File

@@ -9,9 +9,9 @@ class MathsProvider(BuiltinToolProviderController):
def _validate_credentials(self, credentials: dict[str, Any]) -> None:
try:
EvaluateExpressionTool().invoke(
user_id='',
user_id="",
tool_parameters={
'expression': '1+(2+3)*4',
"expression": "1+(2+3)*4",
},
)
except Exception as e:

View File

@@ -8,22 +8,23 @@ from core.tools.tool.builtin_tool import BuiltinTool
class EvaluateExpressionTool(BuiltinTool):
def _invoke(self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
def _invoke(
self,
user_id: str,
tool_parameters: dict[str, Any],
) -> Union[ToolInvokeMessage, list[ToolInvokeMessage]]:
"""
invoke tools
invoke tools
"""
# get expression
expression = tool_parameters.get('expression', '').strip()
expression = tool_parameters.get("expression", "").strip()
if not expression:
return self.create_text_message('Invalid expression')
return self.create_text_message("Invalid expression")
try:
result = ne.evaluate(expression)
result_str = str(result)
except Exception as e:
logging.exception(f'Error evaluating expression: {expression}')
return self.create_text_message(f'Invalid expression: {expression}, error: {str(e)}')
return self.create_text_message(f'The result of the expression "{expression}" is {result_str}')
logging.exception(f"Error evaluating expression: {expression}")
return self.create_text_message(f"Invalid expression: {expression}, error: {str(e)}")
return self.create_text_message(f'The result of the expression "{expression}" is {result_str}')