Merge branch 'dev' of https://github.com/MaiM-with-u/MaiBot into dev
This commit is contained in:
@@ -4,56 +4,47 @@ from typing import Dict, Any
|
|||||||
|
|
||||||
logger = get_module_logger("compare_numbers_tool")
|
logger = get_module_logger("compare_numbers_tool")
|
||||||
|
|
||||||
|
|
||||||
class CompareNumbersTool(BaseTool):
|
class CompareNumbersTool(BaseTool):
|
||||||
"""比较两个数大小的工具"""
|
"""比较两个数大小的工具"""
|
||||||
|
|
||||||
name = "compare_numbers"
|
name = "compare_numbers"
|
||||||
description = "比较两个数的大小,返回较大的数"
|
description = "比较两个数的大小,返回较大的数"
|
||||||
parameters = {
|
parameters = {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
"num1": {
|
"num1": {"type": "number", "description": "第一个数字"},
|
||||||
"type": "number",
|
"num2": {"type": "number", "description": "第二个数字"},
|
||||||
"description": "第一个数字"
|
|
||||||
},
|
|
||||||
"num2": {
|
|
||||||
"type": "number",
|
|
||||||
"description": "第二个数字"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"required": ["num1", "num2"]
|
"required": ["num1", "num2"],
|
||||||
}
|
}
|
||||||
|
|
||||||
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
async def execute(self, function_args: Dict[str, Any], message_txt: str = "") -> Dict[str, Any]:
|
||||||
"""执行比较两个数的大小
|
"""执行比较两个数的大小
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
function_args: 工具参数
|
function_args: 工具参数
|
||||||
message_txt: 原始消息文本
|
message_txt: 原始消息文本
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Dict: 工具执行结果
|
Dict: 工具执行结果
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
num1 = function_args.get("num1")
|
num1 = function_args.get("num1")
|
||||||
num2 = function_args.get("num2")
|
num2 = function_args.get("num2")
|
||||||
|
|
||||||
if num1 > num2:
|
if num1 > num2:
|
||||||
result = f"{num1} 大于 {num2}"
|
result = f"{num1} 大于 {num2}"
|
||||||
elif num1 < num2:
|
elif num1 < num2:
|
||||||
result = f"{num1} 小于 {num2}"
|
result = f"{num1} 小于 {num2}"
|
||||||
else:
|
else:
|
||||||
result = f"{num1} 等于 {num2}"
|
result = f"{num1} 等于 {num2}"
|
||||||
|
|
||||||
return {
|
return {"name": self.name, "content": result}
|
||||||
"name": self.name,
|
|
||||||
"content": result
|
|
||||||
}
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"比较数字失败: {str(e)}")
|
logger.error(f"比较数字失败: {str(e)}")
|
||||||
return {
|
return {"name": self.name, "content": f"比较数字失败: {str(e)}"}
|
||||||
"name": self.name,
|
|
||||||
"content": f"比较数字失败: {str(e)}"
|
|
||||||
}
|
|
||||||
|
|
||||||
# 注册工具
|
# 注册工具
|
||||||
register_tool(CompareNumbersTool)
|
register_tool(CompareNumbersTool)
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ class ToolUser:
|
|||||||
|
|
||||||
# 定义可用工具
|
# 定义可用工具
|
||||||
tools = self._define_tools()
|
tools = self._define_tools()
|
||||||
|
|
||||||
# 使用llm_model_tool发送带工具定义的请求
|
# 使用llm_model_tool发送带工具定义的请求
|
||||||
payload = {
|
payload = {
|
||||||
"model": self.llm_model_tool.model_name,
|
"model": self.llm_model_tool.model_name,
|
||||||
|
|||||||
Reference in New Issue
Block a user