🎓 BMSCE助理
为BMS工程学院学生打造的友好型AI聊天机器人,采用模型上下文协议(MCP)和Mistral 7B构建。通过自然对话界面,实时获取学院活动、通知以及查询学术文档的最新信息。
✨ 特点
- 📰(新闻纸/报纸的简写或象征) 最新消息与活动随时了解大学活动、研讨会、节日及各种新动向
- 📢 大学通知查阅官方通知、通告、公告及截止日期
- 🔍 知识库查询搜索上传的PDF文档(课程大纲、简历、学术内容)
- 💬(表示说话或评论的表情符号,无实际翻译内容) 自然对话由Mistral 7B驱动的友好、以学生为中心的聊天界面
- 🚀 表情符号“🚀”通常表示火箭、太空旅行或快速前进等概念,在中文中可以翻译为“🚀(火箭/太空旅行/快速前进等)”。不过,由于表情符号本身没有固定的中文翻译,所以这里只是根据其常见含义给出了一个大致的翻译方向。在实际使用中,可以根据上下文来灵活翻译。 MCP建筑事务所/建筑公司基于模型上下文协议的可扩展工具集成
🏗️ 建筑学
┌─────────────────┐
│ User Input │
└────────┬────────┘
│
▼
┌─────────────────┐
│ client.py │ ◄── Mistral 7B LLM (via Ollama)
│ (MCP Client) │
└────────┬────────┘
│
▼
┌─────────────────┐
│ main.py │
│ (MCP Server) │
│ │
│ Tools: │
│ • get_latest_news
│ • get_college_notifications
│ • query_knowledge_base
└────────┬────────┘
│
┌────┴────┬──────────────┐
▼ ▼ ▼
┌────────┐ ┌──────┐ ┌────────────────┐
│Web │ │Web │ │ChromaDB │
│Scraper │ │Scraper│ │Vector Store │
│(News) │ │(Notif)│ │(PDF Documents) │
└────────┘ └──────┘ └────────────────┘📋 先决条件
- Python 3.8及以上版本
- Ollama(注:Ollama是一个开源的机器学习框架,此处直接音译,不改变其原名) 以下型号:
- mistral:7b LLM - nomic-embed-text:v1.5 (嵌入表示)
安装Ollama
# macOS/Linux
curl -fsSL https://ollama.com/install.sh | sh
# Windows
# Download from https://ollama.com/download拉取所需模型
ollama pull mistral:7b
ollama pull nomic-embed-text:v1.5🚀 安装
- 克隆仓库
git clone
cd bmsce-assistant- 安装Python依赖项
pip install -r requirements.txt- 建立向量数据库 (可选,用于PDF查询)
如果您想将PDF文档添加到知识库中:
# Edit vector_db.py and add your PDF files to the pdf_files list
python vector_db.py这将创建一个 chroma_storage 包含索引文档的目录。
💻 使用方法
运行助手
启动聊天机器人,使用:
python client.py你会看到一个欢迎屏幕:
🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓
Welcome to BMSCE Assistant! 🤖
Your friendly AI helper for all things BMS College
🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓 🎓
✅ Connected to MCP Server
💬 Hey there! Ask me about college events, notifications, or anything else!
Type 'quit' or 'exit' when you're done.
────────────────────────────────────────────────────────────────
You: 示例查询
新闻与活动:
You: What events are happening this month?
You: Tell me about upcoming workshops
You: Any festivals coming up?通知:
You: What are the latest notifications?
You: Show me recent announcements
You: Any important deadlines?知识库:
You: Search for syllabus information
You: Find details about [specific topic]
You: What does the document say about [query]?一般聊天:
You: Hi!
You: Thank you
You: How are you?退出
输入以下任意内容以退出:
quitexitbyegoodbye- 或者按下
Ctrl+C
📁 项目结构
bmsce-assistant/
│
├── client.py # MCP client with Mistral integration
├── main.py # MCP server with tool definitions
├── web_scrap.py # Web scrapers for BMSCE website
├── vector_db.py # ChromaDB setup and PDF indexing
├── requirements.txt # Python dependencies
├── .gitignore # Git ignore file
│
├── chroma_storage/ # ChromaDB persistent storage (auto-created)
└── *.pdf # Your PDF documents to index🛠️ 组件
1. MCP 服务器(main.py)
定义了三种工具:
get_latest_news()从BMSCE网站抓取新闻和事件get_college_notifications()抓取大学通知query_knowledge_base(query_text, n_results=3)查询 ChromaDB 向量存储
2. MCP 客户端(client.py)
- 连接到MCP服务器
- 使用Mistral 7B来:
- 解释用户查询 - 选择合适的工具 - 生成自然、友好的回复
- 提供对话式界面
3. 网页抓取工具(或:网络爬虫)web_scrap.py)
- 抓取BMSCE网站(https://bmsce.ac.in)的数据
- 从以下来源提取结构化数据:
- 新闻与活动版块 - 大学通知板块
- 以JSON格式返回数据
4. 向量数据库 (vector_db.py)
- 使用ChromaDB进行语义搜索
- 使用Nomic嵌入索引PDF文档
- 支持分块文档检索
🔧 配置
添加PDF文档
编辑 vector_db.py:
if __name__ == "__main__":
pdf_files = [
"syllabus.pdf",
"handbook.pdf",
"your_document.pdf"
]
for pdf in pdf_files:
add_pdf_to_vectordb(pdf)然后运行:
python vector_db.py自定义大型语言模型(LLM)的行为
在 client.py,你可以修改:
- 温度控制随机性(0.1 = 聚焦,0.9 = 创造性)
- 模型改变
mistral:7b到其他Ollama模型 - 提示编辑不同个性的系统提示
调整块大小
在 vector_db.py:
chunks = split_text(pdf_text, chunk_size=1000, overlap=100)🤝 工作原理
- 用户提出问题 → 发送给
client.py - Mistral 进行分析 查询并决定使用哪个工具
- 客户端调用工具 在MCP服务器上(
main.py) - 服务器执行 该工具:
- 用于新闻/通知的网页抓取 - 向量搜索用于知识库查询
- 返回的原始数据 致客户
- Mistral 格式 将数据转化为自然反应
- 用户看到了友好的回复 🎉(庆祝、欢呼的符号,无直接对应中文翻译,可理解为“庆祝”或根据语境翻译为相应的表达)
🐛 故障排除
“未连接到服务器”错误
- 确保两者都
client.py并且main.py位于同一目录下 - 检查Python是否可以执行
main.py作为一个子过程
未找到Ollama模型
# Pull the models
ollama pull mistral:7b
ollama pull nomic-embed-text:v1.5
# Verify installation
ollama listChromaDB 错误
- 删除
chroma_storage文件夹并重新运行vector_db.py - 确保项目目录中存在PDF文件
网页抓取失败
- 检查您的网络连接
- 验证BMSCE网站是否可访问
- 网站结构可能已发生变化(请更新选择器中的内容)
web_scrap.py)
📝 依赖项
关键库:
fastmcp- MCP服务器框架mcp- MCP 客户端 SDKollama- Ollama Python 客户端chromadb- 向量数据库beautifulsoup4- 网络爬虫(或网页抓取)PyPDF2- PDF文本提取
见 requirements.txt 以获取完整列表。
🚧 未来改进计划
- \[ \] 为网页抓取结果添加缓存功能
- \[ \] 支持更多文档格式(DOCX、TXT)
- \[ \] 用于持久化对话历史的数据库
- \[ \] 语音输入/输出
- \[ \] 网页界面(Gradio/Streamlit)
- \[ \] 多语言支持
- \[ \] 与大学日历集成
- \[ \] 学生认证系统
为BMSCE学生倾心打造
