🔧 注册助理
基于人工智能构建的注册系统 MCP(模型上下文协议) 工具, 快速API,以及 溪流此应用程序允许用户注册新用户,并使用与AI助手的自然语言交互查看现有注册。
🌟 特性
- 自然语言接口:与人工智能助手聊天以管理注册
- 用户注册:添加具有姓名、电子邮件和出生日期的新用户
- 数据验证:对所有输入字段进行全面验证
- 查看注册信息:显示所有注册用户
- 防止重复:阻止使用现有电子邮件地址注册
- 实时聊天界面:基于Streamlit的交互式用户界面
- RESTful API:带有自动文档的FastAPI后端
🏗️ 建筑
┌─────────────────┐ ┌──────────────┐ ┌─────────────────┐
│ Streamlit │────│ FastAPI │────│ MCP Tools │
│ Frontend │ │ HTTP API │ │ (Business │
│ (app.py) │ │ (api.py) │ │ Logic) │
└─────────────────┘ └──────────────┘ └─────────────────┘
│ │ │
│ │ │
┌────▼────┐ ┌─────▼─────┐ ┌─────▼─────┐
│ OpenAI │ │ Pydantic │ │ CSV │
│ API │ │ Validation│ │ Storage │
└─────────┘ └───────────┘ └───────────┘📁 项目结构
registration-assistant/
├── README.md # Project documentation
├── requirements.txt # Python dependencies
├── .env # Environment variables (create this)
├── user_registrations.csv # Data storage (auto-created)
│
├── app.py # Streamlit frontend application
├── api.py # FastAPI HTTP endpoints
├── main.py # FastMCP server (alternative)
├── manager.py # Registration business logic
├── validator.py # Input validation utilities
│
└── tools/ # MCP Tools directory
├── __init__.py
├── add_registrations.py # Add registration tool
└── get_all_registrations.py # Get all registrations tool🚀 快速开始
先决条件
- Python 3.8+
- OpenAI API密钥
安装
- 克隆存储库
git clone
cd registration-assistant- 安装依赖项
pip install -r requirements.txt- 创建环境文件
# Create .env file
echo "OPENAI_API_KEY=your_openai_api_key_here" > .env- 启动FastAPI服务器
# Option 1: Direct run
python api.py
# Option 2: Using uvicorn (recommended)
uvicorn api:app --reload --host 127.0.0.1 --port 8000- 启动Streamlit应用程序 (在新航站楼)
streamlit run app.py- 访问应用程序
- Streamlit应用程序: http://localhost:8501 - FastAPI文档: http://127.0.0.1:8000/docs - FastAPI API: http://127.0.0.1:8000
📋 需求
创建一个 requirements.txt 文件包含:
streamlit>=1.28.0
fastapi>=0.104.0
uvicorn>=0.24.0
openai>=1.3.0
httpx>=0.25.0
python-dotenv>=1.0.0
loguru>=0.7.0
pydantic>=2.0.0
mcp>=0.1.0
fastmcp>=0.1.0🎯 用法
使用聊天界面
- 注册新用户:
"Register John Doe with email john@example.com, DOB 1990-01-15"- 查看所有注册:
"Show all registrations"
"List all users"
"Display registered users"- 自然语言查询:
"Add a new user named Jane Smith with email jane@test.com born on 1985-06-20"
"I want to register someone"
"Can you show me who's registered?"直接使用API
添加注册
curl -X POST "http://127.0.0.1:8000/add_registration" \
-H "Content-Type: application/json" \
-d '{
"name": "John Doe",
"email": "john@example.com",
"dob": "1990-01-15"
}'获取所有注册信息
curl -X GET "http://127.0.0.1:8000/get_all_registrations"🔧 配置
环境变量
创建一个 .env 项目根目录中的文件:
OPENAI_API_KEY=your_openai_api_key_here数据存储
- 格式:CSV文件(
user_registrations.csv) - 位置:项目根目录
- 自动创建:文件在首次注册时自动创建
- 领域:姓名、电子邮件、出生日期、注册日期
🙏 致谢
- OpenAI 用于ChatGPT API
- 溪流 优秀的前端框架
- 快速API 用于高性能API框架
- MCP协议 工具集成标准
______________________________________________________________________
