🤖 NexusFlow AI-商业智能助理
使用MCP(模型上下文协议)和本地CSV数据进行销售、库存和分支机构绩效分析的人工智能商业智能。
📊 特性
- 销售分析:跟踪每日/每周/每月的收入、交易和趋势
- 库存管理:监控库存水平、低库存警报和重新订购建议
- 分行业绩:使用经理详细信息比较3个地点的绩效
- AI驱动的洞察:通过MCP工具使用GPT-4进行自然语言查询
🏢 数据源
- 每日销售额:收入、交易、顶级产品(从2025-08-08)
- 库存:库存水平、阈值、供应商(更新于2025-11-06)
- 分支信息:3个地点-Branch_A(市中心),Branch_B(购物中心广场),Shopify(在线)
🚀 快速开始
1.安装依赖项
pip install pandas fastapi uvicorn langchain-openai langchain-mcp-adapters langgraph python-dotenv2.设置环境
创建 .env 文件:
OPENAI_API_KEY=your_openai_api_key_here3.运行API
python app.pyAPI运行于: http://localhost:8000
4.测试API
curl -X POST http://localhost:8000/api/v1/NexusFlow/ask-question \
-H "Content-Type: application/json" \
-d '{"question": "What were our sales yesterday?"}'或者运行测试脚本:
python test_api.py💡 示例问题
- “我们昨天的销售额是多少?”
- “显示需要重新订购的低库存商品”
- “本周哪个部门表现最好?”
- “过去7天我们最畅销的产品是什么?”
- “给我今天的完整业务摘要”
- “我们有多少Product_X库存?”
- “谁管理Branch_B,他们的电子邮件是什么?”
- “比较2025年9月至8月的销售额”
📁 项目结构
MCPNexus-Flow-AI/
├── Data/
│ ├── Daily_Sales.csv # Sales data
│ ├── Inventory.csv # Inventory data
│ └── Branch_Info.csv # Branch details
├── mcp_functions.py # 15 MCP tools for data analysis
├── client.py # AI agent setup
├── app.py # FastAPI server
├── test_api.py # API test script
└── requirements.txt # Dependencies🔧 可用的MCP工具(15)
📊 销售(6工具)
get_sales_today()-今天的收入和交易get_sales_yesterday()-昨天的演出get_sales_by_date_range()-自定义期间分析compare_sales_periods()-期间比较get_top_selling_product()-畅销书get_total_revenue_this_month()-月至今跟踪
📦 库存(4个工具)
get_inventory_by_product()-产品库存查询get_low_stock_items()-补货警报get_all_inventory()-完成库存审计check_product_stock_status()-详细状态及建议
🏢 分支(3个工具)
get_branch_performance_today()-按地点分列的每日业绩compare_branch_performance()-多地点比较get_branch_info()-经理和位置详细信息
📈 报告(2个工具)
get_business_summary_today()-完整的每日仪表板get_weekly_report()-7天综合分析
🌐 API终点
发布 /api/v1/NexusFlow/ask-question
问任何商业智能问题。
请求:
{
"question": "What were our sales yesterday?"
}答复:
{
"answer": "Yesterday's total sales were $8,121 with 126 transactions...",
"status": "success",
"code": 200,
"question": "What were our sales yesterday?"
}获取 / -API信息
获取 /health -健康检查
🎯 交互模式
直接运行客户端以进行交互式CLI:
python client.py📊 数据格式
Daily_Sales.csv
Date,Branch,Revenue,Transactions,Top_Product,Payment_Method
2025-08-08,Branch_A,2091,27,Product_Y,Credit_CardInventory.csv
Product_Name,Branch,Quantity,Threshold,Unit,Last_Updated,Supplier
Product_X,Branch_A,26,31,Units,2025-11-06,Supplier_2Branch_Info.csv
Date,Branch_ID,Branch_Name,Location,Manager_Name,Manager_Email,Daily_Performance
2025-08-28,BR001,Branch_A,Downtown,John_Smith,john@branch-a.com,83%🔑 关键技术
- MCP(模型上下文协议):基于工具的人工智能框架
- FastMCP:Python MCP服务器实现
- LangChain:AI编排
- GPT-4o-mini:OpenAI语言模型
- 熊猫:数据处理
- 快速API:REST API框架
______________________________________________________________________
内置❤️ 使用MCP+AI
