mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-06 16:07:01 +08:00
refactor(agent): 按需加载 Agent 运行时 (#6336)
This commit is contained in:
@@ -1,18 +1,3 @@
|
||||
# 把真实 Agent 服务注册进 application 门面(幂等),供测试 patch 门面背后的单例方法。
|
||||
from app.agent.llm import AgentCapabilityManager, LLMHelper
|
||||
from app.agent.orchestrator import agent_manager
|
||||
from app.agent.prompt import prompt_manager
|
||||
from app.agent.prompt.transfer_redo import build_manual_redo_prompt
|
||||
from app.application.agent import register_agent_services
|
||||
|
||||
register_agent_services(
|
||||
agent_manager=agent_manager,
|
||||
prompt_manager=prompt_manager,
|
||||
capability_manager=AgentCapabilityManager,
|
||||
llm_helper=LLMHelper,
|
||||
manual_redo_prompt_builder=build_manual_redo_prompt,
|
||||
)
|
||||
|
||||
import asyncio
|
||||
import base64
|
||||
import json
|
||||
@@ -301,15 +286,14 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
"feishu://file/om_audio/file_audio/voice.opus",
|
||||
]
|
||||
|
||||
with patch.object(
|
||||
AgentCapabilityManager, "is_audio_input_available", return_value=True
|
||||
with patch(
|
||||
"app.chain.message.is_audio_input_available", return_value=True
|
||||
), patch.object(
|
||||
chain,
|
||||
"run_module",
|
||||
side_effect=[b"slack", b"discord", b"qq", b"vocechat", b"synology", b"feishu"],
|
||||
) as run_module, patch.object(
|
||||
AgentCapabilityManager,
|
||||
"transcribe_audio",
|
||||
) as run_module, patch(
|
||||
"app.chain.message.transcribe_audio",
|
||||
side_effect=[
|
||||
"slack text",
|
||||
"discord text",
|
||||
@@ -466,11 +450,13 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
}
|
||||
],
|
||||
) as prepare_files, patch(
|
||||
"app.application.agent._agent_manager.process_message", new_callable=AsyncMock
|
||||
) as process_message, patch(
|
||||
"app.chain.message.get_running_agent_manager"
|
||||
) as get_running_manager, patch(
|
||||
"app.chain.message.asyncio.run_coroutine_threadsafe",
|
||||
side_effect=lambda coro, _loop: coro.close(),
|
||||
) as run_coroutine_threadsafe:
|
||||
process_message = AsyncMock()
|
||||
get_running_manager.return_value.process_message = process_message
|
||||
chain._handle_ai_message(
|
||||
text="/ai 帮我看看这张图",
|
||||
channel=MessageChannel.Telegram,
|
||||
@@ -499,11 +485,13 @@ class AgentImageSupportTest(unittest.TestCase):
|
||||
with patch.object(settings, "AI_AGENT_ENABLE", True), patch.object(
|
||||
chain, "_get_or_create_session_id", return_value="session-1"
|
||||
), patch(
|
||||
"app.application.agent._agent_manager.process_message", new_callable=AsyncMock
|
||||
) as process_message, patch(
|
||||
"app.chain.message.get_running_agent_manager"
|
||||
) as get_running_manager, patch(
|
||||
"app.chain.message.asyncio.run_coroutine_threadsafe",
|
||||
side_effect=lambda coro, _loop: coro.close(),
|
||||
):
|
||||
process_message = AsyncMock()
|
||||
get_running_manager.return_value.process_message = process_message
|
||||
chain._handle_ai_message(
|
||||
text="帮我推荐一部电影",
|
||||
channel=MessageChannel.Telegram,
|
||||
|
||||
Reference in New Issue
Block a user