mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-03-20 03:57:30 +08:00
fix agent tools
This commit is contained in:
@@ -37,13 +37,11 @@ class MoviePilotTool(BaseTool, metaclass=ABCMeta):
|
|||||||
# 发送运行工具前的消息
|
# 发送运行工具前的消息
|
||||||
agent_message = await self._callback_handler.get_message()
|
agent_message = await self._callback_handler.get_message()
|
||||||
if agent_message:
|
if agent_message:
|
||||||
await self.send_tool_message(agent_message)
|
await self.send_tool_message(agent_message, title="MoviePilot助手")
|
||||||
# 发送执行工具说明
|
# 发送执行工具说明
|
||||||
explanation = kwargs.get("explanation")
|
explanation = kwargs.get("explanation")
|
||||||
if explanation:
|
if explanation:
|
||||||
if not explanation.startswith("正在"):
|
await self.send_tool_message(f"⏯️[{explanation}]")
|
||||||
explanation = "正在" + explanation
|
|
||||||
await self.send_tool_message(f"{explanation} ...")
|
|
||||||
return await self.run(**kwargs)
|
return await self.run(**kwargs)
|
||||||
|
|
||||||
@abstractmethod
|
@abstractmethod
|
||||||
|
|||||||
@@ -58,7 +58,8 @@ class AddDownloadTool(MoviePilotTool):
|
|||||||
# 创建下载上下文
|
# 创建下载上下文
|
||||||
torrent_info = TorrentInfo(
|
torrent_info = TorrentInfo(
|
||||||
title=torrent_title,
|
title=torrent_title,
|
||||||
download_url=torrent_url,
|
description=torrent_description,
|
||||||
|
enclosure=torrent_url,
|
||||||
site_name=site_name,
|
site_name=site_name,
|
||||||
site_ua=siteinfo.ua,
|
site_ua=siteinfo.ua,
|
||||||
site_cookie=siteinfo.cookie,
|
site_cookie=siteinfo.cookie,
|
||||||
@@ -67,7 +68,7 @@ class AddDownloadTool(MoviePilotTool):
|
|||||||
site_downloader=siteinfo.downloader
|
site_downloader=siteinfo.downloader
|
||||||
)
|
)
|
||||||
meta_info = MetaInfo(title=torrent_title, subtitle=torrent_description)
|
meta_info = MetaInfo(title=torrent_title, subtitle=torrent_description)
|
||||||
media_info = ToolChain().recognize_media(meta=meta_info)
|
media_info = await ToolChain().async_recognize_media(meta=meta_info)
|
||||||
if not media_info:
|
if not media_info:
|
||||||
return "错误:无法识别媒体信息,无法添加下载任务"
|
return "错误:无法识别媒体信息,无法添加下载任务"
|
||||||
context = Context(
|
context = Context(
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ class AddSubscribeTool(MoviePilotTool):
|
|||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
logger.warning(f"无效的 tmdb_id: {tmdb_id},将忽略")
|
logger.warning(f"无效的 tmdb_id: {tmdb_id},将忽略")
|
||||||
|
|
||||||
sid, message = subscribe_chain.add(
|
sid, message = await subscribe_chain.async_add(
|
||||||
mtype=MediaType(media_type),
|
mtype=MediaType(media_type),
|
||||||
title=title,
|
title=title,
|
||||||
year=year,
|
year=year,
|
||||||
|
|||||||
@@ -38,17 +38,17 @@ class GetRecommendationsTool(MoviePilotTool):
|
|||||||
recommend_chain = RecommendChain()
|
recommend_chain = RecommendChain()
|
||||||
results = []
|
results = []
|
||||||
if source == "tmdb_trending":
|
if source == "tmdb_trending":
|
||||||
results = recommend_chain.tmdb_trending(limit=limit)
|
results = await recommend_chain.async_tmdb_trending(limit=limit)
|
||||||
elif source == "douban_hot":
|
elif source == "douban_hot":
|
||||||
if media_type == "movie":
|
if media_type == "movie":
|
||||||
results = recommend_chain.douban_movie_hot(limit=limit)
|
results = await recommend_chain.async_douban_movie_hot(limit=limit)
|
||||||
elif media_type == "tv":
|
elif media_type == "tv":
|
||||||
results = recommend_chain.douban_tv_hot(limit=limit)
|
results = await recommend_chain.async_douban_tv_hot(limit=limit)
|
||||||
else: # all
|
else: # all
|
||||||
results.extend(recommend_chain.douban_movie_hot(limit=limit))
|
results.extend(await recommend_chain.async_douban_movie_hot(limit=limit))
|
||||||
results.extend(recommend_chain.douban_tv_hot(limit=limit))
|
results.extend(await recommend_chain.async_douban_tv_hot(limit=limit))
|
||||||
elif source == "bangumi_calendar":
|
elif source == "bangumi_calendar":
|
||||||
results = recommend_chain.bangumi_calendar(limit=limit)
|
results = await recommend_chain.async_bangumi_calendar(limit=limit)
|
||||||
|
|
||||||
if results:
|
if results:
|
||||||
# 限制最多20条结果
|
# 限制最多20条结果
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ class QueryDownloadsTool(MoviePilotTool):
|
|||||||
if total_count > 20:
|
if total_count > 20:
|
||||||
return f"注意:查询结果共找到 {total_count} 条,为节省上下文空间,仅显示前 20 条结果。\n\n{result_json}"
|
return f"注意:查询结果共找到 {total_count} 条,为节省上下文空间,仅显示前 20 条结果。\n\n{result_json}"
|
||||||
return result_json
|
return result_json
|
||||||
return "未找到相关下载任务。"
|
return "未找到相关下载任务"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"查询下载失败: {e}", exc_info=True)
|
logger.error(f"查询下载失败: {e}", exc_info=True)
|
||||||
return f"查询下载时发生错误: {str(e)}"
|
return f"查询下载时发生错误: {str(e)}"
|
||||||
|
|||||||
@@ -32,10 +32,10 @@ class QueryMediaLibraryTool(MoviePilotTool):
|
|||||||
logger.info(f"执行工具: {self.name}, 参数: media_type={media_type}, title={title}")
|
logger.info(f"执行工具: {self.name}, 参数: media_type={media_type}, title={title}")
|
||||||
try:
|
try:
|
||||||
media_server_oper = MediaServerOper()
|
media_server_oper = MediaServerOper()
|
||||||
filtered_medias: List[MediaServerItem] = media_server_oper.exists(title=title, year=year, mtype=media_type)
|
filtered_medias: List[MediaServerItem] = await media_server_oper.async_exists(title=title, year=year, mtype=media_type)
|
||||||
if filtered_medias:
|
if filtered_medias:
|
||||||
return json.dumps([m.to_dict() for m in filtered_medias])
|
return json.dumps([m.to_dict() for m in filtered_medias])
|
||||||
return "媒体库中未找到相关媒体。"
|
return "媒体库中未找到相关媒体"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"查询媒体库失败: {e}", exc_info=True)
|
logger.error(f"查询媒体库失败: {e}", exc_info=True)
|
||||||
return f"查询媒体库时发生错误: {str(e)}"
|
return f"查询媒体库时发生错误: {str(e)}"
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ class QuerySitesTool(MoviePilotTool):
|
|||||||
try:
|
try:
|
||||||
site_oper = SiteOper()
|
site_oper = SiteOper()
|
||||||
# 获取所有站点(按优先级排序)
|
# 获取所有站点(按优先级排序)
|
||||||
sites = site_oper.list_order_by_pri()
|
sites = await site_oper.async_list()
|
||||||
filtered_sites = []
|
filtered_sites = []
|
||||||
for site in sites:
|
for site in sites:
|
||||||
# 按状态过滤
|
# 按状态过滤
|
||||||
@@ -59,7 +59,7 @@ class QuerySitesTool(MoviePilotTool):
|
|||||||
simplified_sites.append(simplified)
|
simplified_sites.append(simplified)
|
||||||
result_json = json.dumps(simplified_sites, ensure_ascii=False, indent=2)
|
result_json = json.dumps(simplified_sites, ensure_ascii=False, indent=2)
|
||||||
return result_json
|
return result_json
|
||||||
return "未找到相关站点。"
|
return "未找到相关站点"
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"查询站点失败: {e}", exc_info=True)
|
logger.error(f"查询站点失败: {e}", exc_info=True)
|
||||||
return f"查询站点时发生错误: {str(e)}"
|
return f"查询站点时发生错误: {str(e)}"
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class QuerySubscribesTool(MoviePilotTool):
|
|||||||
logger.info(f"执行工具: {self.name}, 参数: status={status}, media_type={media_type}")
|
logger.info(f"执行工具: {self.name}, 参数: status={status}, media_type={media_type}")
|
||||||
try:
|
try:
|
||||||
subscribe_oper = SubscribeOper()
|
subscribe_oper = SubscribeOper()
|
||||||
subscribes = subscribe_oper.list()
|
subscribes = await subscribe_oper.async_list()
|
||||||
filtered_subscribes = []
|
filtered_subscribes = []
|
||||||
for sub in subscribes:
|
for sub in subscribes:
|
||||||
if status != "all" and sub.state != status:
|
if status != "all" and sub.state != status:
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ class SearchMediaTool(MoviePilotTool):
|
|||||||
search_title = f"{search_title} S{season:02d}"
|
search_title = f"{search_title} S{season:02d}"
|
||||||
|
|
||||||
# 使用 MediaChain.search 方法
|
# 使用 MediaChain.search 方法
|
||||||
meta, results = media_chain.search(title=search_title)
|
meta, results = await media_chain.async_search(title=search_title)
|
||||||
|
|
||||||
# 过滤结果
|
# 过滤结果
|
||||||
if results:
|
if results:
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ class SearchTorrentsTool(MoviePilotTool):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
search_chain = SearchChain()
|
search_chain = SearchChain()
|
||||||
torrents = search_chain.search_by_title(title=title, sites=sites)
|
torrents = await search_chain.async_search_by_title(title=title, sites=sites)
|
||||||
filtered_torrents = []
|
filtered_torrents = []
|
||||||
# 编译正则表达式(如果提供)
|
# 编译正则表达式(如果提供)
|
||||||
regex_pattern = None
|
regex_pattern = None
|
||||||
|
|||||||
Reference in New Issue
Block a user