🤖 自动格式化代码 [skip ci]
This commit is contained in:
@@ -59,14 +59,14 @@ class SmartGreetingAction(BaseAction):
|
||||
# ===== 功能定义必须项 =====
|
||||
action_parameters = {
|
||||
"username": "要问候的用户名(可选)",
|
||||
"greeting_style": "问候风格:casual(随意)、formal(正式)、friendly(友好),默认casual"
|
||||
"greeting_style": "问候风格:casual(随意)、formal(正式)、friendly(友好),默认casual",
|
||||
}
|
||||
|
||||
action_require = [
|
||||
"用户发送包含问候词汇的消息时使用",
|
||||
"检测到新用户加入时使用",
|
||||
"响应友好交流需求时使用",
|
||||
"避免在短时间内重复问候同一用户"
|
||||
"避免在短时间内重复问候同一用户",
|
||||
]
|
||||
|
||||
associated_types = ["text", "emoji"]
|
||||
@@ -115,7 +115,7 @@ class SmartGreetingAction(BaseAction):
|
||||
style_templates = {
|
||||
"casual": "嗨{username}!很开心见到你~",
|
||||
"formal": "您好{username},很荣幸为您服务!",
|
||||
"friendly": "你好{username}!欢迎来到这里,希望我们能成为好朋友!😊"
|
||||
"friendly": "你好{username}!欢迎来到这里,希望我们能成为好朋友!😊",
|
||||
}
|
||||
|
||||
selected_template = style_templates.get(style, template)
|
||||
@@ -150,7 +150,7 @@ class SmartGreetingAction(BaseAction):
|
||||
model_config=model_config,
|
||||
request_type="plugin.greeting",
|
||||
temperature=0.7,
|
||||
max_tokens=100
|
||||
max_tokens=100,
|
||||
)
|
||||
|
||||
if success and response:
|
||||
@@ -201,14 +201,14 @@ class HelpfulAction(BaseAction):
|
||||
action_parameters = {
|
||||
"help_type": "帮助类型:explanation(解释)、suggestion(建议)、guidance(指导)、tips(提示)",
|
||||
"topic": "帮助主题或用户关心的问题",
|
||||
"complexity": "复杂度:simple(简单)、medium(中等)、advanced(高级)"
|
||||
"complexity": "复杂度:simple(简单)、medium(中等)、advanced(高级)",
|
||||
}
|
||||
|
||||
action_require = [
|
||||
"用户表达困惑或寻求帮助时使用",
|
||||
"检测到用户遇到技术问题时使用",
|
||||
"对话中出现知识盲点时主动提供帮助",
|
||||
"避免过度频繁地提供帮助,要恰到好处"
|
||||
"避免过度频繁地提供帮助,要恰到好处",
|
||||
]
|
||||
|
||||
associated_types = ["text", "emoji"]
|
||||
@@ -258,7 +258,7 @@ class HelpfulAction(BaseAction):
|
||||
"explanation": f"关于{topic},我来为你解释一下:这是一个{complexity}级别的概念...",
|
||||
"suggestion": f"针对{topic},我建议你可以尝试以下方法...",
|
||||
"guidance": f"在{topic}方面,我可以为你提供一些指导...",
|
||||
"tips": f"关于{topic},这里有一些实用的小贴士..."
|
||||
"tips": f"关于{topic},这里有一些实用的小贴士...",
|
||||
}
|
||||
|
||||
base_message = help_templates.get(help_type, f"关于{topic},我很乐意为你提供帮助!")
|
||||
@@ -291,11 +291,7 @@ class HelpfulAction(BaseAction):
|
||||
|
||||
model_config = next(iter(models.values()))
|
||||
success, response, reasoning, model_name = await self.api.generate_with_model(
|
||||
prompt=prompt,
|
||||
model_config=model_config,
|
||||
request_type="plugin.help",
|
||||
temperature=0.7,
|
||||
max_tokens=300
|
||||
prompt=prompt, model_config=model_config, request_type="plugin.help", temperature=0.7, max_tokens=300
|
||||
)
|
||||
|
||||
if success and response:
|
||||
|
||||
@@ -7,8 +7,7 @@
|
||||
import subprocess
|
||||
import sys
|
||||
import importlib
|
||||
from typing import List, Dict, Tuple, Optional
|
||||
from pathlib import Path
|
||||
from typing import List, Dict, Tuple
|
||||
|
||||
from src.common.logger import get_logger
|
||||
from src.plugin_system.base.component_types import PythonDependency
|
||||
@@ -23,7 +22,9 @@ class DependencyManager:
|
||||
self.install_log: List[str] = []
|
||||
self.failed_installs: Dict[str, str] = {}
|
||||
|
||||
def check_dependencies(self, dependencies: List[PythonDependency]) -> Tuple[List[PythonDependency], List[PythonDependency]]:
|
||||
def check_dependencies(
|
||||
self, dependencies: List[PythonDependency]
|
||||
) -> Tuple[List[PythonDependency], List[PythonDependency]]:
|
||||
"""检查依赖包状态
|
||||
|
||||
Args:
|
||||
@@ -107,7 +108,7 @@ class DependencyManager:
|
||||
cmd,
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=300 # 5分钟超时
|
||||
timeout=300, # 5分钟超时
|
||||
)
|
||||
|
||||
if result.returncode == 0:
|
||||
@@ -127,8 +128,9 @@ class DependencyManager:
|
||||
logger.error(f"❌ 安装异常: {pip_requirement} - {str(e)}")
|
||||
return False
|
||||
|
||||
def generate_requirements_file(self, plugins_dependencies: List[List[PythonDependency]],
|
||||
output_path: str = "plugin_requirements.txt") -> bool:
|
||||
def generate_requirements_file(
|
||||
self, plugins_dependencies: List[List[PythonDependency]], output_path: str = "plugin_requirements.txt"
|
||||
) -> bool:
|
||||
"""生成插件依赖的requirements文件
|
||||
|
||||
Args:
|
||||
@@ -166,7 +168,7 @@ class DependencyManager:
|
||||
if dep.description:
|
||||
f.write(f"# {dep.description}\n")
|
||||
if dep.optional:
|
||||
f.write(f"# Optional dependency\n")
|
||||
f.write("# Optional dependency\n")
|
||||
f.write(f"{requirement}\n\n")
|
||||
|
||||
logger.info(f"已生成插件依赖文件: {output_path} ({len(all_deps)} 个包)")
|
||||
@@ -182,7 +184,7 @@ class DependencyManager:
|
||||
"install_log": self.install_log.copy(),
|
||||
"failed_installs": self.failed_installs.copy(),
|
||||
"total_attempts": len(self.install_log),
|
||||
"failed_count": len(self.failed_installs)
|
||||
"failed_count": len(self.failed_installs),
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ if TYPE_CHECKING:
|
||||
from src.common.logger import get_logger
|
||||
from src.plugin_system.core.component_registry import component_registry
|
||||
from src.plugin_system.core.dependency_manager import dependency_manager
|
||||
from src.plugin_system.base.component_types import ComponentType, PluginInfo, PythonDependency
|
||||
from src.plugin_system.base.component_types import ComponentType, PluginInfo
|
||||
|
||||
logger = get_logger("plugin_manager")
|
||||
|
||||
@@ -360,7 +360,7 @@ class PluginManager:
|
||||
all_optional_missing = []
|
||||
plugin_status = {}
|
||||
|
||||
for plugin_name, plugin_instance in self.loaded_plugins.items():
|
||||
for plugin_name, _plugin_instance in self.loaded_plugins.items():
|
||||
plugin_info = component_registry.get_plugin_info(plugin_name)
|
||||
if not plugin_info or not plugin_info.python_dependencies:
|
||||
plugin_status[plugin_name] = {"status": "no_dependencies", "missing": []}
|
||||
@@ -368,16 +368,14 @@ class PluginManager:
|
||||
|
||||
logger.info(f"检查插件 {plugin_name} 的依赖...")
|
||||
|
||||
missing_required, missing_optional = dependency_manager.check_dependencies(
|
||||
plugin_info.python_dependencies
|
||||
)
|
||||
missing_required, missing_optional = dependency_manager.check_dependencies(plugin_info.python_dependencies)
|
||||
|
||||
if missing_required:
|
||||
all_required_missing.extend(missing_required)
|
||||
plugin_status[plugin_name] = {
|
||||
"status": "missing_required",
|
||||
"missing": [dep.package_name for dep in missing_required],
|
||||
"optional_missing": [dep.package_name for dep in missing_optional]
|
||||
"optional_missing": [dep.package_name for dep in missing_optional],
|
||||
}
|
||||
logger.error(f"插件 {plugin_name} 缺少必需依赖: {[dep.package_name for dep in missing_required]}")
|
||||
elif missing_optional:
|
||||
@@ -385,7 +383,7 @@ class PluginManager:
|
||||
plugin_status[plugin_name] = {
|
||||
"status": "missing_optional",
|
||||
"missing": [],
|
||||
"optional_missing": [dep.package_name for dep in missing_optional]
|
||||
"optional_missing": [dep.package_name for dep in missing_optional],
|
||||
}
|
||||
logger.warning(f"插件 {plugin_name} 缺少可选依赖: {[dep.package_name for dep in missing_optional]}")
|
||||
else:
|
||||
@@ -407,21 +405,22 @@ class PluginManager:
|
||||
unique_required[dep.package_name] = dep
|
||||
|
||||
logger.info(f"开始自动安装 {len(unique_required)} 个必需依赖包...")
|
||||
install_success = dependency_manager.install_dependencies(
|
||||
list(unique_required.values()),
|
||||
auto_install=True
|
||||
)
|
||||
install_success = dependency_manager.install_dependencies(list(unique_required.values()), auto_install=True)
|
||||
|
||||
return {
|
||||
"total_plugins_checked": len(plugin_status),
|
||||
"plugins_with_missing_required": len([p for p in plugin_status.values() if p["status"] == "missing_required"]),
|
||||
"plugins_with_missing_optional": len([p for p in plugin_status.values() if p["status"] == "missing_optional"]),
|
||||
"plugins_with_missing_required": len(
|
||||
[p for p in plugin_status.values() if p["status"] == "missing_required"]
|
||||
),
|
||||
"plugins_with_missing_optional": len(
|
||||
[p for p in plugin_status.values() if p["status"] == "missing_optional"]
|
||||
),
|
||||
"total_missing_required": total_missing,
|
||||
"total_missing_optional": total_optional_missing,
|
||||
"plugin_status": plugin_status,
|
||||
"auto_install_attempted": auto_install and bool(all_required_missing),
|
||||
"auto_install_success": install_success,
|
||||
"install_summary": dependency_manager.get_install_summary()
|
||||
"install_summary": dependency_manager.get_install_summary(),
|
||||
}
|
||||
|
||||
def generate_plugin_requirements(self, output_path: str = "plugin_requirements.txt") -> bool:
|
||||
@@ -437,7 +436,7 @@ class PluginManager:
|
||||
|
||||
all_dependencies = []
|
||||
|
||||
for plugin_name, plugin_instance in self.loaded_plugins.items():
|
||||
for plugin_name, _plugin_instance in self.loaded_plugins.items():
|
||||
plugin_info = component_registry.get_plugin_info(plugin_name)
|
||||
if plugin_info and plugin_info.python_dependencies:
|
||||
all_dependencies.append(plugin_info.python_dependencies)
|
||||
|
||||
@@ -84,7 +84,7 @@ class MuteAction(BaseAction):
|
||||
]
|
||||
|
||||
# 关联类型
|
||||
associated_types = ["text","command"]
|
||||
associated_types = ["text", "command"]
|
||||
|
||||
async def execute(self) -> Tuple[bool, Optional[str]]:
|
||||
"""执行智能禁言判定"""
|
||||
|
||||
Reference in New Issue
Block a user