AI聊天机器人与剧作家集成
使用FastAPI后端和Streamlit前端构建的现代聊天机器人应用程序,由Google Vertex AI Gemini模型提供支持,并集成了Playwright MCP服务器支持。
特性
- 人工智能聊天机器人:由Google Vertex AI Gemini 2.0 Flash驱动的交互式聊天界面
- 剧作家整合:支持MCP服务器的测试代理和脚本生成端点
- 现代用户界面:基于Streamlit的干净前端,带有实时状态指示器
- 生产就绪:全面的错误处理、日志记录和输入验证
先决条件
- Python 3.8+
- 启用Vertex AI API的谷歌云项目
- Node.js和npm(用于Playwright MCP服务器)
安装
- 克隆存储库:
git clone
cd mcp_projects- 安装后端依赖项:
cd backend
pip install fastapi uvicorn vertexai python-dotenv pydantic- 安装前端依赖项:
cd ../frontend
pip install streamlit requests python-dotenv配置
创建一个 .env 项目根目录或相应目录中的文件:
后端环境变量
GOOGLE_GENAI_USE_VERTEXAI=true
GOOGLE_CLOUD_PROJECT=your-project-id
GOOGLE_CLOUD_LOCATION=us-central1
CORS_ALLOWED_ORIGINS=http://localhost:8501前端环境变量
GOOGLE_GENAI_USE_VERTEXAI=true
CHATBACKEND_URL=http://localhost:8090/chat
BACKEND_BASE_URL=http://localhost:8090用法
启动后端服务器
cd backend
python main.py后端将于启动 http://localhost:8090
启动前端应用程序
cd frontend
streamlit run app.py前端将在 http://localhost:8501
项目结构
mcp_projects/
├── backend/
│ ├── main.py # FastAPI backend server
│ └── mcp.json # MCP server configuration
├── frontend/
│ └── app.py # Streamlit frontend application
└── README.mdAPI终点
聊天端点
- 发布
/chat - 请求:
{"message": "your message", "context": "optional context"} - 答复:
{"response": "AI generated response"}
剧作家测试代理
- 发布
/playwright/test-agent - 请求:
{"prompt": "test scenario"} - 答复:
{"status": "success", "summary": "...", "steps": [...], "logs": [...]}
剧作家剧本生成
- 发布
/playwright/script-agent - 请求:
{"prompt": "script description"} - 答复:
{"status": "success", "summary": "...", "script": "..."}
许可证
本项目按原样提供,用于演示目的。
