Merge branch 'master' of https://github.com/MaiBot-Plus/MaiMbot-Pro-Max
This commit is contained in:
@@ -20,6 +20,7 @@ class Server:
|
||||
origins = [
|
||||
"http://localhost:3000", # 允许的前端源
|
||||
"http://127.0.0.1:3000",
|
||||
"http://127.0.0.1:3000",
|
||||
# 在生产环境中,您应该添加实际的前端域名
|
||||
]
|
||||
|
||||
|
||||
@@ -39,6 +39,8 @@ from src.config.official_configs import (
|
||||
ScheduleConfig,
|
||||
VideoAnalysisConfig,
|
||||
DependencyManagementConfig,
|
||||
ExaConfig,
|
||||
WebSearchConfig,
|
||||
)
|
||||
|
||||
from .api_ada_configs import (
|
||||
@@ -356,6 +358,8 @@ class Config(ConfigBase):
|
||||
schedule: ScheduleConfig
|
||||
utils_video: VideoAnalysisConfig = field(default_factory=lambda: VideoAnalysisConfig())
|
||||
dependency_management: DependencyManagementConfig = field(default_factory=lambda: DependencyManagementConfig())
|
||||
exa: ExaConfig = field(default_factory=lambda: ExaConfig())
|
||||
web_search: WebSearchConfig = field(default_factory=lambda: WebSearchConfig())
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -901,4 +901,23 @@ class DependencyManagementConfig(ConfigBase):
|
||||
"""安装前是否提示用户(暂未实现)"""
|
||||
|
||||
install_log_level: str = "INFO"
|
||||
"""依赖安装日志级别"""
|
||||
"""依赖安装日志级别"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class ExaConfig(ConfigBase):
|
||||
"""EXA搜索引擎配置类"""
|
||||
|
||||
api_key: str = "None"
|
||||
"""EXA API密钥,用于联网搜索功能。请填入有效的EXA API密钥"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class WebSearchConfig(ConfigBase):
|
||||
"""联网搜索组件配置类"""
|
||||
|
||||
enable_web_search_tool: bool = True
|
||||
"""是否启用联网搜索工具"""
|
||||
|
||||
enable_url_tool: bool = True
|
||||
"""是否启用URL解析工具"""
|
||||
@@ -47,22 +47,6 @@ class DependencyConfig:
|
||||
return config.dependency_management.mirror_url
|
||||
return ""
|
||||
|
||||
@property
|
||||
def use_proxy(self) -> bool:
|
||||
"""是否使用网络代理"""
|
||||
config = self._get_config()
|
||||
if config and hasattr(config, 'dependency_management'):
|
||||
return config.dependency_management.use_proxy
|
||||
return False
|
||||
|
||||
@property
|
||||
def proxy_url(self) -> str:
|
||||
"""网络代理URL"""
|
||||
config = self._get_config()
|
||||
if config and hasattr(config, 'dependency_management'):
|
||||
return config.dependency_management.proxy_url
|
||||
return ""
|
||||
|
||||
@property
|
||||
def install_timeout(self) -> int:
|
||||
"""安装超时时间(秒)"""
|
||||
@@ -71,17 +55,6 @@ class DependencyConfig:
|
||||
return config.dependency_management.auto_install_timeout
|
||||
return 300
|
||||
|
||||
@property
|
||||
def pip_options(self) -> list:
|
||||
"""pip安装选项"""
|
||||
config = self._get_config()
|
||||
if config and hasattr(config, 'dependency_management'):
|
||||
return config.dependency_management.pip_options
|
||||
return [
|
||||
"--no-warn-script-location",
|
||||
"--disable-pip-version-check"
|
||||
]
|
||||
|
||||
|
||||
|
||||
@property
|
||||
|
||||
@@ -19,15 +19,13 @@ class DependencyManager:
|
||||
负责检查和自动安装插件的Python包依赖
|
||||
"""
|
||||
|
||||
def __init__(self, auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None, use_proxy: bool = False, proxy_url: Optional[str] = None):
|
||||
def __init__(self, auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None):
|
||||
"""初始化依赖管理器
|
||||
|
||||
Args:
|
||||
auto_install: 是否自动安装缺失的依赖
|
||||
use_mirror: 是否使用PyPI镜像源
|
||||
mirror_url: PyPI镜像源URL
|
||||
use_proxy: 是否使用网络代理
|
||||
proxy_url: 网络代理URL
|
||||
"""
|
||||
# 延迟导入配置以避免循环依赖
|
||||
try:
|
||||
@@ -38,20 +36,14 @@ class DependencyManager:
|
||||
self.auto_install = config.auto_install if auto_install is True else auto_install
|
||||
self.use_mirror = config.use_mirror if use_mirror is False else use_mirror
|
||||
self.mirror_url = config.mirror_url if mirror_url is None else mirror_url
|
||||
self.use_proxy = config.use_proxy if use_proxy is False else use_proxy
|
||||
self.proxy_url = config.proxy_url if proxy_url is None else proxy_url
|
||||
self.install_timeout = config.install_timeout
|
||||
self.pip_options = config.pip_options.copy()
|
||||
|
||||
except Exception as e:
|
||||
logger.warning(f"无法加载依赖配置,使用默认设置: {e}")
|
||||
self.auto_install = auto_install
|
||||
self.use_mirror = use_mirror or False
|
||||
self.mirror_url = mirror_url or ""
|
||||
self.use_proxy = use_proxy
|
||||
self.proxy_url = proxy_url or ""
|
||||
self.install_timeout = 300
|
||||
self.pip_options = ["--no-warn-script-location", "--disable-pip-version-check"]
|
||||
|
||||
def check_dependencies(self, dependencies: Any, plugin_name: str = "") -> Tuple[bool, List[str], List[str]]:
|
||||
"""检查依赖包是否满足要求
|
||||
@@ -240,19 +232,11 @@ class DependencyManager:
|
||||
try:
|
||||
cmd = [sys.executable, "-m", "pip", "install", package]
|
||||
|
||||
# 添加镜像源设置(优先)
|
||||
# 添加镜像源设置
|
||||
if self.use_mirror and self.mirror_url:
|
||||
cmd.extend(["-i", self.mirror_url])
|
||||
logger.debug(f"[Plugin:{plugin_name}] 使用PyPI镜像源: {self.mirror_url}")
|
||||
|
||||
# 添加代理设置
|
||||
if self.use_proxy and self.proxy_url:
|
||||
cmd.extend(["--proxy", self.proxy_url])
|
||||
logger.debug(f"[Plugin:{plugin_name}] 使用网络代理: {self.proxy_url}")
|
||||
|
||||
# 添加配置的pip选项
|
||||
cmd.extend(self.pip_options)
|
||||
|
||||
logger.debug(f"[Plugin:{plugin_name}] 执行安装命令: {' '.join(cmd)}")
|
||||
|
||||
result = subprocess.run(
|
||||
@@ -289,13 +273,11 @@ def get_dependency_manager() -> DependencyManager:
|
||||
return _global_dependency_manager
|
||||
|
||||
|
||||
def configure_dependency_manager(auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None, use_proxy: bool = False, proxy_url: Optional[str] = None):
|
||||
def configure_dependency_manager(auto_install: bool = True, use_mirror: bool = False, mirror_url: Optional[str] = None):
|
||||
"""配置全局依赖管理器"""
|
||||
global _global_dependency_manager
|
||||
_global_dependency_manager = DependencyManager(
|
||||
auto_install=auto_install,
|
||||
use_mirror=use_mirror,
|
||||
mirror_url=mirror_url,
|
||||
use_proxy=use_proxy,
|
||||
proxy_url=proxy_url
|
||||
)
|
||||
mirror_url=mirror_url
|
||||
)
|
||||
@@ -12,8 +12,8 @@
|
||||
"host_application": {
|
||||
"min_version": "0.10.0"
|
||||
},
|
||||
"homepage_url": "https://github.com/MaiBot-Plus/mmc",
|
||||
"repository_url": "https://github.com/MaiBot-Plus/mmc",
|
||||
"homepage_url": "https://github.com/MaiBot-Plus/MaiMbot-Pro-Max",
|
||||
"repository_url": "https://github.com/MaiBot-Plus/MaiMbot-Pro-Max",
|
||||
"keywords": ["web_search", "url_parser"],
|
||||
"categories": ["web_search", "url_parser"],
|
||||
|
||||
@@ -17,6 +17,7 @@ from src.plugin_system import (
|
||||
ToolParamType,
|
||||
PythonDependency
|
||||
)
|
||||
from src.plugin_system.apis import config_api # 添加config_api导入
|
||||
import httpx
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
@@ -35,7 +36,8 @@ class WebSurfingTool(BaseTool):
|
||||
|
||||
def __init__(self, plugin_config=None):
|
||||
super().__init__(plugin_config)
|
||||
EXA_API_KEY = self.get_config("exa.api_key", None)
|
||||
# 从主配置文件读取EXA API密钥
|
||||
EXA_API_KEY = config_api.get_global_config("exa.api_key", None)
|
||||
# 确保API key是字符串类型
|
||||
if EXA_API_KEY and isinstance(EXA_API_KEY, str) and EXA_API_KEY.strip() != "None":
|
||||
self.exa = Exa(api_key=str(EXA_API_KEY).strip())
|
||||
@@ -172,7 +174,8 @@ class URLParserTool(BaseTool):
|
||||
]
|
||||
def __init__(self, plugin_config=None):
|
||||
super().__init__(plugin_config)
|
||||
EXA_API_KEY = self.get_config("exa.api_key", None)
|
||||
# 从主配置文件读取EXA API密钥
|
||||
EXA_API_KEY = config_api.get_global_config("exa.api_key", None)
|
||||
# 确保API key是字符串类型
|
||||
if (not EXA_API_KEY or
|
||||
not isinstance(EXA_API_KEY, str) or
|
||||
@@ -426,33 +429,37 @@ class WEBSEARCHPLUGIN(BasePlugin):
|
||||
config_file_name: str = "config.toml" # 配置文件名
|
||||
|
||||
# 配置节描述
|
||||
config_section_descriptions = {"plugin": "插件基本信息", "exa": "EXA相关配置", "proxy": "链接本地解析代理配置", "components": "组件设置"}
|
||||
config_section_descriptions = {"plugin": "插件基本信息", "proxy": "链接本地解析代理配置"}
|
||||
|
||||
# 配置Schema定义
|
||||
# 注意:EXA配置和组件设置已迁移到主配置文件(bot_config.toml)的[exa]和[web_search]部分
|
||||
config_schema: dict = {
|
||||
"plugin": {
|
||||
"name": ConfigField(type=str, default="WEB_SEARCH_PLUGIN", description="插件名称"),
|
||||
"version": ConfigField(type=str, default="1.0.0", description="插件版本"),
|
||||
"enabled": ConfigField(type=bool, default=False, description="是否启用插件"),
|
||||
},
|
||||
"exa":{
|
||||
"api_key":ConfigField(type=str, default="None", description="exa的API密钥")
|
||||
},
|
||||
"proxy": {
|
||||
"http_proxy": ConfigField(type=str, default=None, description="HTTP代理地址,格式如: http://proxy.example.com:8080"),
|
||||
"https_proxy": ConfigField(type=str, default=None, description="HTTPS代理地址,格式如: http://proxy.example.com:8080"),
|
||||
"socks5_proxy": ConfigField(type=str, default=None, description="SOCKS5代理地址,格式如: socks5://proxy.example.com:1080"),
|
||||
"enable_proxy": ConfigField(type=bool, default=False, description="是否启用代理")
|
||||
},
|
||||
"components":{
|
||||
"enable_web_search_tool":ConfigField(type=bool, default=True, description="是否启用联网搜索tool"),
|
||||
"enable_url_tool":ConfigField(type=bool, default=True, description="是否启用URL解析tool")
|
||||
}
|
||||
# EXA相关配置已迁移到主配置文件 bot_config.toml 的 [exa] 部分
|
||||
# "exa":{
|
||||
# "api_key":ConfigField(type=str, default="None", description="exa的API密钥")
|
||||
# },
|
||||
# 组件设置已迁移到主配置文件 bot_config.toml 的 [web_search] 部分
|
||||
# "components":{
|
||||
# "enable_web_search_tool":ConfigField(type=bool, default=True, description="是否启用联网搜索tool"),
|
||||
# "enable_url_tool":ConfigField(type=bool, default=True, description="是否启用URL解析tool")
|
||||
# }
|
||||
}
|
||||
def get_plugin_components(self) -> List[Tuple[ComponentInfo, Type]]:
|
||||
enable_tool =[]
|
||||
if self.get_config("components.enable_web_search_tool"):
|
||||
# 从主配置文件读取组件启用配置
|
||||
if config_api.get_global_config("web_search.enable_web_search_tool", True):
|
||||
enable_tool.append((WebSurfingTool.get_tool_info(), WebSurfingTool))
|
||||
if self.get_config("components.enable_url_tool"):
|
||||
if config_api.get_global_config("web_search.enable_url_tool", True):
|
||||
enable_tool.append((URLParserTool.get_tool_info(), URLParserTool))
|
||||
return enable_tool
|
||||
@@ -268,15 +268,6 @@ auto_install_timeout = 300
|
||||
use_mirror = true
|
||||
mirror_url = "https://pypi.tuna.tsinghua.edu.cn/simple" # PyPI镜像源URL,如: "https://pypi.tuna.tsinghua.edu.cn/simple"
|
||||
|
||||
# 是否使用网络代理(高级选项)
|
||||
use_proxy = false
|
||||
proxy_url = "" # 网络代理URL,如: "http://proxy.example.com:8080"
|
||||
|
||||
# pip安装选项
|
||||
pip_options = [
|
||||
"--no-warn-script-location",
|
||||
"--disable-pip-version-check"
|
||||
]
|
||||
|
||||
# 安装前是否提示用户(暂未实现)
|
||||
prompt_before_install = false
|
||||
@@ -333,4 +324,16 @@ batch_analysis_prompt = """请分析这个视频的内容。这些图片是从
|
||||
5. 整体氛围和情感表达
|
||||
6. 任何特殊的视觉效果或文字内容
|
||||
|
||||
请用中文回答,分析要详细准确。"""
|
||||
请用中文回答,分析要详细准确。"""
|
||||
|
||||
# EXA搜索引擎配置
|
||||
[exa]
|
||||
# EXA API密钥,用于联网搜索功能
|
||||
api_key = "None" # 请填入有效的EXA API密钥
|
||||
|
||||
# 联网搜索组件配置
|
||||
[web_search]
|
||||
# 是否启用联网搜索工具
|
||||
enable_web_search_tool = true
|
||||
# 是否启用URL解析工具
|
||||
enable_url_tool = true
|
||||
Reference in New Issue
Block a user