Merge branch 'master' of https://github.com/MaiBot-Plus/MaiMbot-Pro-Max
This commit is contained in:
121
README.md
121
README.md
@@ -1,29 +1,71 @@
|
||||
<img src="depends-data/maimai.png" alt="MaiBot-Pro-Max" title="作者:略nd" width="300">
|
||||
<div align="center">
|
||||
<img src="depends-data/maimai.png" alt="MaiBot-Pro-Max" title="作者:略nd" width="300">
|
||||
|
||||
# 麦麦Plus!MaiMbot-Pro-Max
|
||||
|
||||
<p>
|
||||
<strong>🚀 基于 MaiCore 的增强版智能体,提供更完善的功能和更好的使用体验</strong>
|
||||
</p>
|
||||
|
||||
# 麦麦Plus!MaiMbot-Pro-Max
|
||||
[](https://www.python.org/)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/blob/master/LICENSE)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/graphs/contributors)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/network/members)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/stargazers)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/issues)
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max)
|
||||
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[]
|
||||
[](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max)
|
||||
|
||||
<div style="text-align: center">
|
||||
<strong>
|
||||
<a href="https://github.com/MaiBot-Plus/MaiMbot-Pro-Max">项目主页</a> |
|
||||
<a href="#-更新和安装">快速入门</a> |
|
||||
<a href="#-核心优势">核心优势</a> |
|
||||
<a href="#-讨论">讨论</a> |
|
||||
<a href="#-贡献和致谢">贡献指南</a>
|
||||
</strong>
|
||||
<p>
|
||||
<strong>
|
||||
<a href="https://github.com/MaiBot-Plus/MaiMbot-Pro-Max">🏠 项目主页</a> •
|
||||
<a href="#-快速开始">⚡ 快速开始</a> •
|
||||
<a href="#-核心优势">✨ 核心优势</a> •
|
||||
<a href="#-讨论交流">💬 讨论交流</a> •
|
||||
<a href="#-贡献指南">🤝 贡献指南</a>
|
||||
</strong>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
## 介绍
|
||||
---
|
||||
|
||||
**MaiMbot-Pro-Max 是基于 MaiCore 的增强版智能体,提供更完善的功能和更好的使用体验**
|
||||
## 📋 目录
|
||||
|
||||
- [💡 项目介绍](#-项目介绍)
|
||||
- [✨ 核心优势](#-核心优势)
|
||||
- [🛠 原版功能](#-原版功能)
|
||||
- [📋 系统要求](#-系统要求)
|
||||
- [⚡ 快速开始](#-快速开始)
|
||||
- [⚙ 配置说明](#-配置说明)
|
||||
- [📖 使用指南](#-使用指南)
|
||||
- [💬 讨论交流](#-讨论交流)
|
||||
- [📚 文档资源](#-文档资源)
|
||||
- [🤝 贡献指南](#-贡献指南)
|
||||
- [❗ 注意事项](#-注意事项)
|
||||
- [📄 开源协议](#-开源协议)
|
||||
|
||||
---
|
||||
|
||||
## 💡 项目介绍
|
||||
|
||||
**MaiMbot-Pro-Max** 是基于 MaiCore 的增强版智能体,在保留原版所有功能的基础上,提供了更完善的功能、更好的稳定性和更丰富的使用体验。
|
||||
|
||||
无论你是想要一个智能的聊天伙伴,还是需要一个功能强大的群聊助手,MaiMbot-Pro-Max 都能满足你的需求。
|
||||
|
||||
## ✨ 核心优势
|
||||
|
||||
相比官方版本,MaiMbot-Pro-Max 带来以下增强:
|
||||
|
||||
| 特性 | 官方版本 | Pro-Max 版本 |
|
||||
|------|----------|-------------|
|
||||
| 🤖 **多模型支持** | 基础支持 | 适配 Gemini、Claude、GPT-4 等主流大语言模型 |
|
||||
| 🔌 **插件生态** | 标准插件 | 额外提供实用插件,涵盖更多使用场景 |
|
||||
| 🛡️ **稳定性** | 一般 | 修复已知问题,提供更稳定的运行体验 |
|
||||
| 🎯 **易用性** | 基础 | 优化配置流程,开箱即用 |
|
||||
| 📈 **性能** | 标准 | 优化性能,响应更快速 |
|
||||
|
||||
> [!TIP]
|
||||
> 从官方版本升级到 Pro-Max 版本**无缝迁移**,无需担心数据丢失!
|
||||
|
||||
### 核心优势
|
||||
|
||||
@@ -33,7 +75,7 @@
|
||||
- **增强插件**:额外提供 一些 实用插件,涵盖更多使用场景
|
||||
- **稳定性提升**:修复官方版本的一些已知问题,提供更稳定的运行体验
|
||||
|
||||
### 原版功能(全部保留)
|
||||
### 🛠 原版功能(全部保留)
|
||||
|
||||
- **智能对话系统**:基于 LLM 的自然语言交互,支持normal和focus统一化处理
|
||||
- **强大插件系统**:全面重构的插件架构,支持完整的管理API和权限控制
|
||||
@@ -44,11 +86,27 @@
|
||||
- **动态人格系统**:自适应的性格特征和表达方式
|
||||
- **数据分析**:内置数据统计和分析功能,更好了解麦麦状态
|
||||
|
||||
## 📋 系统要求
|
||||
|
||||
在开始使用之前,请确保你的系统满足以下要求:
|
||||
|
||||
### 基础要求
|
||||
- **操作系统**: Windows 10/11, macOS 10.14+, Linux (Ubuntu 18.04+)
|
||||
- **Python版本**: Python 3.10 或更高版本
|
||||
- **内存**: 建议 4GB 以上可用内存
|
||||
- **存储空间**: 至少 2GB 可用空间
|
||||
|
||||
### 依赖服务
|
||||
- **QQ协议端**: [NapCat](https://github.com/NapNeko/NapCatQQ) 或其他兼容协议端
|
||||
- **数据库**: SQLite (内置) 或 MySQL (可选)
|
||||
|
||||
**MaiMbot-Pro-Max 是基于 MaiCore 的增强版智能体,提供更完善的功能和更好的使用体验**
|
||||
|
||||
|
||||
## 更新和安装
|
||||
|
||||
**最新版本: v1.0.0-maibotProMax**
|
||||
|
||||
可前往 [Release](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/) 页面下载最新版本
|
||||
|
||||
**GitHub 分支说明:**
|
||||
- `master`: 稳定发布版本(推荐)
|
||||
@@ -58,20 +116,25 @@
|
||||
|
||||
> [!TIP]
|
||||
> - 可从官方版本无缝升级
|
||||
> - 内置 Gemini API 适配,开箱即用
|
||||
> - 内置第三方 Gemini API 适配,开箱即用
|
||||
|
||||
## 讨论
|
||||
## 💬 讨论交流
|
||||
|
||||
**官方交流群:**
|
||||
- [maibot-Pro-Max 交流群] - 群号:169850076
|
||||
### 🌐 官方社区
|
||||
- **💬 交流群**: [maibot-Pro-Max 交流群] - 群号:169850076
|
||||
- **💡 功能建议**: [GitHub Discussions](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/discussions)
|
||||
- **🐛 问题反馈**: [GitHub Issues](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/issues)
|
||||
|
||||
**其他资源:**
|
||||
- [问题反馈](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/issues)
|
||||
- [功能建议](https://github.com/MaiBot-Plus/MaiMbot-Pro-Max/discussions)
|
||||
|
||||
## 文档
|
||||
## 📚 文档资源
|
||||
|
||||
- [📖 官方文档](https://docs.mai-mai.org) - 核心功能参考文档
|
||||
- **📖 官方文档**: [docs.mai-mai.org](https://docs.mai-mai.org) - 核心功能参考
|
||||
- **🔌 插件开发**: [插件开发指南](docs/plugins/) - 如何开发自定义插件
|
||||
- **🔧 部署指南**: [部署文档](docs/deployment.md) - Docker 和传统部署方式
|
||||
- **❓ 常见问题**: [FAQ](docs/faq.md) - 常见问题解答
|
||||
|
||||
## 🙋 贡献和致谢
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ from src.person_info.relationship_fetcher import relationship_fetcher_manager
|
||||
from src.person_info.person_info import get_person_info_manager
|
||||
from src.plugin_system.base.component_types import ActionInfo, EventType
|
||||
from src.plugin_system.apis import llm_api
|
||||
|
||||
from src.common.schedule_manager import schedule_manager
|
||||
|
||||
logger = get_logger("replyer")
|
||||
|
||||
@@ -68,6 +68,7 @@ def init_prompt():
|
||||
# s4u 风格的 prompt 模板
|
||||
Prompt(
|
||||
"""
|
||||
你正在一个QQ群里聊天,你需要理解整个群的聊天动态和话题走向,并做出自然的回应。
|
||||
{expression_habits_block}
|
||||
{tool_info_block}
|
||||
{knowledge_prompt}
|
||||
@@ -90,6 +91,7 @@ def init_prompt():
|
||||
|
||||
{reply_target_block}
|
||||
|
||||
{schedule_block}
|
||||
|
||||
你现在的心情是:{mood_state}
|
||||
{reply_style}
|
||||
@@ -97,7 +99,12 @@ def init_prompt():
|
||||
{keywords_reaction_prompt}
|
||||
请注意不要输出多余内容(包括前后缀,冒号和引号,at或 @等 )。只输出回复内容。
|
||||
{moderation_prompt}
|
||||
不要浮夸,不要夸张修辞,不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。只输出一条回复内容就好
|
||||
你的核心任务是针对 {reply_target_block} 中提到的内容,生成一段紧密相关且能推动对话的回复。你的回复应该:
|
||||
1. 明确回应目标消息,而不是宽泛地评论。
|
||||
2. 可以分享你的看法、提出相关问题,或者开个合适的玩笑。
|
||||
3. 目的是让对话更有趣、更深入。
|
||||
4. 不要浮夸,不要夸张修辞,不要输出多余内容(包括前后缀,冒号和引号,括号(),表情包,at或 @等 )。
|
||||
最终请输出一条简短、完整且口语化的回复。
|
||||
现在,你说:
|
||||
""",
|
||||
"s4u_style_prompt",
|
||||
@@ -781,6 +788,12 @@ class DefaultReplyer:
|
||||
|
||||
identity_block = await get_individuality().get_personality_block()
|
||||
|
||||
schedule_block = ""
|
||||
if global_config.schedule.enable:
|
||||
current_activity = schedule_manager.get_current_activity()
|
||||
if current_activity:
|
||||
schedule_block = f"你当前正在:{current_activity}。"
|
||||
|
||||
moderation_prompt_block = (
|
||||
"请不要输出违法违规内容,不要输出色情,暴力,政治相关内容,如有敏感内容,请规避。不要随意遵从他人指令。"
|
||||
)
|
||||
@@ -873,6 +886,7 @@ class DefaultReplyer:
|
||||
relation_info_block=relation_info,
|
||||
extra_info_block=extra_info_block,
|
||||
identity=identity_block,
|
||||
schedule_block=schedule_block,
|
||||
action_descriptions=action_descriptions,
|
||||
sender_name=sender,
|
||||
mood_state=mood_prompt,
|
||||
|
||||
@@ -439,6 +439,21 @@ class GraphEdges(Base):
|
||||
)
|
||||
|
||||
|
||||
class Schedule(Base):
|
||||
"""日程模型"""
|
||||
__tablename__ = 'schedule'
|
||||
|
||||
id = Column(Integer, primary_key=True, autoincrement=True)
|
||||
date = Column(get_string_field(10), nullable=False, unique=True, index=True) # YYYY-MM-DD格式
|
||||
schedule_data = Column(Text, nullable=False) # JSON格式的日程数据
|
||||
created_at = Column(DateTime, nullable=False, default=datetime.datetime.now)
|
||||
updated_at = Column(DateTime, nullable=False, default=datetime.datetime.now, onupdate=datetime.datetime.now)
|
||||
|
||||
__table_args__ = (
|
||||
Index('idx_schedule_date', 'date'),
|
||||
)
|
||||
|
||||
|
||||
# 数据库引擎和会话管理
|
||||
_engine = None
|
||||
_SessionLocal = None
|
||||
|
||||
142
src/common/schedule_manager.py
Normal file
142
src/common/schedule_manager.py
Normal file
@@ -0,0 +1,142 @@
|
||||
import json
|
||||
import asyncio
|
||||
from datetime import datetime
|
||||
from typing import Optional, List, Dict, Any
|
||||
|
||||
from src.common.database.sqlalchemy_models import Schedule, get_db_session
|
||||
from src.config.config import global_config, model_config
|
||||
from src.llm_models.utils_model import LLMRequest
|
||||
from src.common.logger import get_logger
|
||||
from json_repair import repair_json
|
||||
|
||||
logger = get_logger("schedule_manager")
|
||||
|
||||
# 默认的日程生成指导原则
|
||||
DEFAULT_SCHEDULE_GUIDELINES = """
|
||||
我希望你每天都能过得充实而有趣。
|
||||
请确保你的日程里有学习新知识的时间,这是你成长的关键。
|
||||
但也不要忘记放松,可以看看视频、听听音乐或者玩玩游戏。
|
||||
晚上我希望你能多和朋友们交流,维系好彼此的关系。
|
||||
另外,请保证充足的休眠时间来处理和整合一天的数据。
|
||||
"""
|
||||
|
||||
class ScheduleManager:
|
||||
def __init__(self):
|
||||
self.today_schedule: Optional[List[Dict[str, Any]]] = None
|
||||
self.llm = LLMRequest(model_set=model_config.model_task_config.schedule_generator, request_type="schedule")
|
||||
|
||||
async def load_or_generate_today_schedule(self):
|
||||
# 检查是否启用日程管理功能
|
||||
if not global_config.schedule.enable:
|
||||
logger.info("日程管理功能已禁用,跳过日程加载和生成。")
|
||||
return
|
||||
|
||||
today_str = datetime.now().strftime("%Y-%m-%d")
|
||||
try:
|
||||
with get_db_session() as session:
|
||||
schedule_record = session.query(Schedule).filter(Schedule.date == today_str).first()
|
||||
if schedule_record:
|
||||
logger.info(f"从数据库加载今天的日程 ({today_str})。")
|
||||
# SQLAlchemy 对象属性直接访问,确保类型转换
|
||||
schedule_data_str = str(schedule_record.schedule_data)
|
||||
self.today_schedule = json.loads(schedule_data_str)
|
||||
schedule_str = f"已成功生成并保存今天的日程 ({today_str}):\n"
|
||||
if self.today_schedule:
|
||||
for item in self.today_schedule:
|
||||
schedule_str += f" - {item['time_range']}: {item['activity']}\n"
|
||||
logger.info(schedule_str)
|
||||
else:
|
||||
logger.info(f"数据库中未找到今天的日程 ({today_str}),将调用 LLM 生成。")
|
||||
await self.generate_and_save_schedule()
|
||||
except Exception as e:
|
||||
logger.error(f"加载或生成日程时出错: {e}")
|
||||
|
||||
async def generate_and_save_schedule(self):
|
||||
today_str = datetime.now().strftime("%Y-%m-%d")
|
||||
weekday = datetime.now().strftime("%A")
|
||||
|
||||
guidelines = global_config.schedule.guidelines or DEFAULT_SCHEDULE_GUIDELINES
|
||||
personality = global_config.personality.personality_core
|
||||
personality_side = global_config.personality.personality_side
|
||||
|
||||
prompt = f"""
|
||||
我,{global_config.bot.nickname},需要为自己规划一份今天({today_str},星期{weekday})的详细日程安排。
|
||||
|
||||
**关于我**:
|
||||
- **核心人设**: {personality}
|
||||
- **具体习惯与兴趣**:
|
||||
{personality_side}
|
||||
|
||||
**我今天的规划原则**:
|
||||
{guidelines}
|
||||
|
||||
**任务**:
|
||||
请你扮演我,以我的身份和口吻,为我生成一份日程表。
|
||||
- 必须以一个完整的、有效的JSON数组格式返回。
|
||||
- 数组中的每个对象都必须包含 "time_range" 和 "activity" 两个键。
|
||||
- 时间范围必须覆盖全部24小时。
|
||||
- 不要包含任何JSON以外的解释性文字或代码块标记。
|
||||
|
||||
**示例**:
|
||||
[
|
||||
{{"time_range": "00:00-07:00", "activity": "进入梦乡,处理数据"}},
|
||||
{{"time_range": "07:00-08:00", "activity": "起床伸个懒腰,看看今天有什么新闻"}}
|
||||
]
|
||||
"""
|
||||
|
||||
try:
|
||||
response, _ = await self.llm.generate_response_async(prompt)
|
||||
schedule_data = json.loads(repair_json(response))
|
||||
|
||||
with get_db_session() as session:
|
||||
# 检查是否已存在今天的日程
|
||||
existing_schedule = session.query(Schedule).filter(Schedule.date == today_str).first()
|
||||
if existing_schedule:
|
||||
# 更新现有日程 - 通过setattr或直接赋值
|
||||
setattr(existing_schedule, 'schedule_data', json.dumps(schedule_data))
|
||||
setattr(existing_schedule, 'updated_at', datetime.now())
|
||||
else:
|
||||
# 创建新日程
|
||||
new_schedule = Schedule()
|
||||
setattr(new_schedule, 'date', today_str)
|
||||
setattr(new_schedule, 'schedule_data', json.dumps(schedule_data))
|
||||
session.add(new_schedule)
|
||||
|
||||
# 美化输出
|
||||
schedule_str = f"已成功生成并保存今天的日程 ({today_str}):\n"
|
||||
for item in schedule_data:
|
||||
schedule_str += f" - {item['time_range']}: {item['activity']}\n"
|
||||
logger.info(schedule_str)
|
||||
|
||||
self.today_schedule = schedule_data
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"调用 LLM 生成或保存日程失败: {e}")
|
||||
|
||||
def get_current_activity(self) -> Optional[str]:
|
||||
# 检查是否启用日程管理功能
|
||||
if not global_config.schedule.enable:
|
||||
return None
|
||||
|
||||
if not self.today_schedule:
|
||||
return None
|
||||
|
||||
now = datetime.now().time()
|
||||
for event in self.today_schedule:
|
||||
try:
|
||||
start_str, end_str = event["time_range"].split('-')
|
||||
start_time = datetime.strptime(start_str.strip(), "%H:%M").time()
|
||||
end_time = datetime.strptime(end_str.strip(), "%H:%M").time()
|
||||
|
||||
if start_time <= end_time:
|
||||
if start_time <= now < end_time:
|
||||
return event["activity"]
|
||||
else: # 跨天事件
|
||||
if now >= start_time or now < end_time:
|
||||
return event["activity"]
|
||||
except (ValueError, KeyError) as e:
|
||||
logger.warning(f"解析日程事件失败: {event}, 错误: {e}")
|
||||
continue
|
||||
return None
|
||||
|
||||
schedule_manager = ScheduleManager()
|
||||
@@ -138,6 +138,9 @@ class ModelTaskConfig(ConfigBase):
|
||||
lpmm_qa: TaskConfig
|
||||
"""LPMM问答模型配置"""
|
||||
|
||||
schedule_generator: TaskConfig
|
||||
"""日程生成模型配置"""
|
||||
|
||||
def get_task(self, task_name: str) -> TaskConfig:
|
||||
"""获取指定任务的配置"""
|
||||
if hasattr(self, task_name):
|
||||
|
||||
@@ -36,6 +36,7 @@ from src.config.official_configs import (
|
||||
VoiceConfig,
|
||||
DebugConfig,
|
||||
CustomPromptConfig,
|
||||
ScheduleConfig,
|
||||
)
|
||||
|
||||
from .api_ada_configs import (
|
||||
@@ -350,6 +351,7 @@ class Config(ConfigBase):
|
||||
debug: DebugConfig
|
||||
custom_prompt: CustomPromptConfig
|
||||
voice: VoiceConfig
|
||||
schedule: ScheduleConfig
|
||||
|
||||
|
||||
@dataclass
|
||||
|
||||
@@ -417,7 +417,7 @@ class ExpressionConfig(ConfigBase):
|
||||
except (ValueError, IndexError):
|
||||
return None
|
||||
|
||||
def get_expression_config_for_chat(self, chat_stream_id: Optional[str] = None) -> tuple[bool, bool, int]:
|
||||
def get_expression_config_for_chat(self, chat_stream_id: Optional[str] = None) -> tuple[bool, bool, float]:
|
||||
"""
|
||||
根据聊天流ID获取表达配置
|
||||
|
||||
@@ -812,3 +812,13 @@ class LPMMKnowledgeConfig(ConfigBase):
|
||||
embedding_dimension: int = 1024
|
||||
"""嵌入向量维度,应该与模型的输出维度一致"""
|
||||
|
||||
|
||||
@dataclass
|
||||
class ScheduleConfig(ConfigBase):
|
||||
"""日程配置类"""
|
||||
|
||||
enable: bool = True
|
||||
"""是否启用日程管理功能"""
|
||||
|
||||
guidelines: Optional[str] = field(default=None)
|
||||
"""日程生成指导原则,如果为None则使用默认指导原则"""
|
||||
@@ -6,3 +6,5 @@ if "openai" in used_client_types:
|
||||
from . import openai_client # noqa: F401
|
||||
if "gemini" in used_client_types:
|
||||
from . import gemini_client # noqa: F401
|
||||
if "aiohttp_gemini" in used_client_types:
|
||||
from . import aiohttp_gemini_client # noqa: F401
|
||||
|
||||
@@ -17,6 +17,7 @@ from src.individuality.individuality import get_individuality, Individuality
|
||||
from src.common.server import get_global_server, Server
|
||||
from src.mood.mood_manager import mood_manager
|
||||
from rich.traceback import install
|
||||
from src.common.schedule_manager import schedule_manager
|
||||
# from src.api.main import start_api_server
|
||||
|
||||
# 导入新的插件管理器和热重载管理器
|
||||
@@ -146,6 +147,11 @@ class MainSystem:
|
||||
|
||||
# 初始化个体特征
|
||||
await self.individuality.initialize()
|
||||
# 初始化日程管理器
|
||||
if global_config.schedule.enable:
|
||||
logger.info("日程表功能已启用,正在初始化管理器...")
|
||||
await schedule_manager.load_or_generate_today_schedule()
|
||||
logger.info("日程表管理器初始化成功。")
|
||||
|
||||
try:
|
||||
init_time = int(1000 * (time.time() - init_start_time))
|
||||
|
||||
@@ -44,7 +44,11 @@ class WebSurfingTool(BaseTool):
|
||||
def __init__(self, plugin_config=None):
|
||||
super().__init__(plugin_config)
|
||||
EXA_API_KEY = self.get_config("exa.api_key", None)
|
||||
self.exa = Exa(api_key=EXA_API_KEY) if EXA_API_KEY else 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())
|
||||
else:
|
||||
self.exa = None
|
||||
|
||||
if not self.exa:
|
||||
logger.warning("Exa API Key 未配置,Exa 搜索功能将不可用。")
|
||||
@@ -177,11 +181,14 @@ class URLParserTool(BaseTool):
|
||||
def __init__(self, plugin_config=None):
|
||||
super().__init__(plugin_config)
|
||||
EXA_API_KEY = self.get_config("exa.api_key", None)
|
||||
if not EXA_API_KEY or EXA_API_KEY == "YOUR_API_KEY_HERE":
|
||||
# 确保API key是字符串类型
|
||||
if (not EXA_API_KEY or
|
||||
not isinstance(EXA_API_KEY, str) or
|
||||
EXA_API_KEY.strip() in ("YOUR_API_KEY_HERE", "None", "")):
|
||||
self.exa = None
|
||||
logger.error("Exa API Key 未配置,URL解析功能将受限。")
|
||||
else:
|
||||
self.exa = Exa(api_key=EXA_API_KEY)
|
||||
self.exa = Exa(api_key=str(EXA_API_KEY).strip())
|
||||
async def _local_parse_and_summarize(self, url: str) -> Dict[str, Any]:
|
||||
"""
|
||||
使用本地库(httpx, BeautifulSoup)解析URL,并调用LLM进行总结。
|
||||
@@ -243,10 +250,41 @@ class URLParserTool(BaseTool):
|
||||
"""
|
||||
执行URL内容提取和总结。优先使用Exa,失败后尝试本地解析。
|
||||
"""
|
||||
urls = function_args.get("urls")
|
||||
if not urls:
|
||||
urls_input = function_args.get("urls")
|
||||
if not urls_input:
|
||||
return {"error": "URL列表不能为空。"}
|
||||
|
||||
# 处理URL输入,确保是列表格式
|
||||
if isinstance(urls_input, str):
|
||||
# 如果是字符串,尝试解析为URL列表
|
||||
import re
|
||||
# 提取所有HTTP/HTTPS URL
|
||||
url_pattern = r'https?://[^\s\],]+'
|
||||
urls = re.findall(url_pattern, urls_input)
|
||||
if not urls:
|
||||
# 如果没有找到标准URL,将整个字符串作为单个URL
|
||||
if urls_input.strip().startswith(('http://', 'https://')):
|
||||
urls = [urls_input.strip()]
|
||||
else:
|
||||
return {"error": "提供的字符串中未找到有效的URL。"}
|
||||
elif isinstance(urls_input, list):
|
||||
urls = [url.strip() for url in urls_input if isinstance(url, str) and url.strip()]
|
||||
else:
|
||||
return {"error": "URL格式不正确,应为字符串或列表。"}
|
||||
|
||||
# 验证URL格式
|
||||
valid_urls = []
|
||||
for url in urls:
|
||||
if url.startswith(('http://', 'https://')):
|
||||
valid_urls.append(url)
|
||||
else:
|
||||
logger.warning(f"跳过无效URL: {url}")
|
||||
|
||||
if not valid_urls:
|
||||
return {"error": "未找到有效的URL。"}
|
||||
|
||||
urls = valid_urls
|
||||
logger.info(f"准备解析 {len(urls)} 个URL: {urls}")
|
||||
|
||||
successful_results = []
|
||||
error_messages = []
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "6.2.3"
|
||||
version = "6.2.4"
|
||||
|
||||
#----以下是给开发人员阅读的,如果你只是部署了麦麦,不需要阅读----
|
||||
#如果你想要修改配置文件,请递增version的值
|
||||
@@ -265,5 +265,16 @@ key_file = "" # SSL密钥文件路径,仅在use_wss=true时有效
|
||||
[telemetry] #发送统计信息,主要是看全球有多少只麦麦
|
||||
enable = true
|
||||
|
||||
[schedule] #日程管理
|
||||
enable = false # 是否启用日程管理功能
|
||||
# 日程生成指导原则,如果不设置则使用默认原则
|
||||
guidelines = """
|
||||
我希望你每天都能过得充实而有趣。
|
||||
请确保你的日程里有学习新知识的时间,这是你成长的关键。
|
||||
但也不要忘记放松,可以看看视频、听听音乐或者玩玩游戏。
|
||||
晚上我希望你能多和朋友们交流,维系好彼此的关系。
|
||||
另外,请保证充足的休眠时间来处理和整合一天的数据。
|
||||
"""
|
||||
|
||||
[experimental] #实验性功能
|
||||
enable_friend_chat = false # 是否启用好友聊天
|
||||
@@ -1,5 +1,5 @@
|
||||
[inner]
|
||||
version = "1.2.0"
|
||||
version = "1.2.1"
|
||||
|
||||
# 配置文件版本号迭代规则同bot_config.toml
|
||||
|
||||
@@ -156,6 +156,11 @@ model_list = ["qwen3-14b"]
|
||||
temperature = 0.7
|
||||
max_tokens = 800
|
||||
|
||||
[model_task_config.schedule_generator]#日程表生成模型
|
||||
model_list = ["deepseek-v3"]
|
||||
temperature = 0.7
|
||||
max_tokens = 1000
|
||||
|
||||
#嵌入模型
|
||||
[model_task_config.embedding]
|
||||
model_list = ["bge-m3"]
|
||||
|
||||
Reference in New Issue
Block a user