mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
refactor: enhance tool message handling and improve error logging
- Updated _send_tool_message to accept a title parameter for better message context. - Modified various tool implementations to utilize the new title parameter for clearer messaging. - Improved error logging across multiple tools to include exception details for better debugging.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
import json
|
||||
from typing import Optional
|
||||
|
||||
from app.db.download_oper import DownloadOper
|
||||
from app.chain.download import DownloadChain
|
||||
from app.log import logger
|
||||
from app.agent.tools.base import MoviePilotTool
|
||||
|
||||
@@ -16,8 +16,9 @@ class QueryDownloadsTool(MoviePilotTool):
|
||||
status: Optional[str] = "all") -> str:
|
||||
logger.info(f"执行工具: {self.name}, 参数: downloader={downloader}, status={status}")
|
||||
try:
|
||||
download_oper = DownloadOper()
|
||||
downloads = download_oper.list()
|
||||
download_chain = DownloadChain()
|
||||
# 使用 DownloadChain.downloading 方法获取正在下载的任务
|
||||
downloads = download_chain.downloading(name=downloader)
|
||||
filtered_downloads = []
|
||||
for dl in downloads:
|
||||
if downloader and dl.downloader != downloader:
|
||||
@@ -26,8 +27,8 @@ class QueryDownloadsTool(MoviePilotTool):
|
||||
continue
|
||||
filtered_downloads.append(dl)
|
||||
if filtered_downloads:
|
||||
return json.dumps([d.dict() for d in filtered_downloads], ensure_ascii=False, indent=2)
|
||||
return json.dumps([d.dict() if hasattr(d, 'dict') else d.model_dump() if hasattr(d, 'model_dump') else d for d in filtered_downloads], ensure_ascii=False, indent=2)
|
||||
return "未找到相关下载任务。"
|
||||
except Exception as e:
|
||||
logger.error(f"查询下载失败: {e}")
|
||||
logger.error(f"查询下载失败: {e}", exc_info=True)
|
||||
return f"查询下载时发生错误: {str(e)}"
|
||||
|
||||
Reference in New Issue
Block a user