🤖 自动格式化代码 [skip ci]

This commit is contained in:
github-actions[bot]
2025-04-14 13:36:52 +00:00
parent 53332791e4
commit bd66ae272e
6 changed files with 54 additions and 68 deletions

View File

@@ -57,5 +57,3 @@ class GetCurrentTaskTool(BaseTool):
task_info = f"{start_time}{end_time} 之间没有找到日程信息"
return {"name": "get_current_task", "content": f"日程信息: {task_info}"}

View File

@@ -5,6 +5,7 @@ from datetime import datetime
logger = get_module_logger("get_time_date")
class GetCurrentDateTimeTool(BaseTool):
"""获取当前时间、日期、年份和星期的工具"""
@@ -33,7 +34,5 @@ class GetCurrentDateTimeTool(BaseTool):
return {
"name": "get_current_date_time",
"content": f"当前时间: {current_time}, 日期: {current_date}, 年份: {current_year}, 星期: {current_weekday}"
"content": f"当前时间: {current_time}, 日期: {current_date}, 年份: {current_year}, 星期: {current_weekday}",
}

View File

@@ -22,7 +22,9 @@ class ToolUser:
model=global_config.llm_heartflow, temperature=0.2, max_tokens=1000, request_type="tool_use"
)
async def _build_tool_prompt(self, message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None):
async def _build_tool_prompt(
self, message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None
):
"""构建工具使用的提示词
Args:
@@ -38,7 +40,7 @@ class ToolUser:
# print(f"intol111111111111111111111111111111111222222222222mid_memory_info{mid_memory_info}")
else:
mid_memory_info = ""
new_messages = list(
db.messages.find({"chat_id": chat_stream.stream_id, "time": {"$gt": time.time()}}).sort("time", 1).limit(15)
)
@@ -104,7 +106,9 @@ class ToolUser:
logger.error(f"执行工具调用时发生错误: {str(e)}")
return None
async def use_tool(self, message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None):
async def use_tool(
self, message_txt: str, sender_name: str, chat_stream: ChatStream, subheartflow: SubHeartflow = None
):
"""使用工具辅助思考,判断是否需要额外信息
Args:
@@ -117,12 +121,7 @@ class ToolUser:
"""
try:
# 构建提示词
prompt = await self._build_tool_prompt(
message_txt,
sender_name,
chat_stream,
subheartflow
)
prompt = await self._build_tool_prompt(message_txt, sender_name, chat_stream, subheartflow)
# 定义可用工具
tools = self._define_tools()
@@ -170,10 +169,7 @@ class ToolUser:
tool_name = result["name"]
if tool_name not in structured_info:
structured_info[tool_name] = []
structured_info[tool_name].append({
"name": result["name"],
"content": result["content"]
})
structured_info[tool_name].append({"name": result["name"], "content": result["content"]})
# 如果有工具结果,返回结构化的信息
if structured_info: