AI校园助手

一个基于Mistral 7B和MCP架构的AI校园助手,为学生提供实时校园新闻、通知查询及学术文档搜索服务。

  • by krsaisharan18
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 krsaisharan18/RAG-MCP-QA-System-BMSCE

使用说明

🎓 BMSE助理

一个友好的人工智能聊天机器人,适用于BMS工程学院的学生,使用模型上下文协议(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+
  • 奥拉玛 具有以下型号:
    • 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

🚀 安装

  1. 克隆存储库
git clone <your-repo-url>
cd bmsce-assistant
  1. 安装 Python 依赖项
pip install -r requirements.txt
  1. 设置矢量数据库 (可选,用于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?

退出

键入以下任何一项以退出:

  • quit
  • exit
  • bye
  • goodbye
  • 或按 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():从BMSE网站上抓取新闻和事件
  • get_college_notifications():取消大学通知
  • query_knowledge_base(query_text, n_results=3):查询ChromaDB矢量存储

2.MCP客户端(client.py)

  • 连接到MCP服务器
  • 使用Mistral 7B:
    • 解释用户查询
    • 选择合适的工具
    • 生成自然、友好的响应
  • 提供对话界面

3.网络爬虫(web_scrap.py)

  • 删除BMSE网站(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 其他Olama车型
  • 提示:编辑不同个性的系统提示

调整块大小

在 vector_db.py:

chunks = split_text(pdf_text, chunk_size=1000, overlap=100)

🤝 运作原理

  1. 用户提问 → 发送到 client.py
  2. Mistral分析 查询并决定使用哪个工具
  3. 客户调用工具 在MCP服务器上(main.py)
  4. 服务器执行 工具:
    • 新闻/通知的网络抓取
    • 知识库查询的矢量搜索
  5. 返回原始数据 给客户
  6. Mistral格式 将数据转化为自然反应
  7. 用户看到友好的答案 🎉

🐛 故障排除

“未连接到服务器”错误

  • 确保两者都 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 list

ChromaDB错误

  • 删除 chroma_storage 文件夹并重新运行 vector_db.py
  • 确保项目目录中存在PDF文件

Web抓取失败

  • 检查你的网络连接
  • 验证BMSE网站是否可访问
  • 网站结构可能已更改(中的更新选择器 web_scrap.py)

📝 依赖项

关键库:

  • fastmcp -MCP服务器框架
  • mcp -MCP客户端SDK
  • ollama -Ollama Python客户端
  • chromadb -矢量数据库
  • beautifulsoup4 -网络抓取
  • PyPDF2 -PDF文本提取

看 requirements.txt 查看完整列表。

🚧 未来的增强功能

  • []为网页抓取结果添加缓存
  • []支持更多文档格式(DOCX、TXT)
  • []持久对话历史数据库
  • []语音输入/输出
  • []Web界面(Gradio/Streamlit)
  • []多语言支持
  • []与大学日历集成
  • []学生身份验证系统

制作❤️ BMSE学生