AI聊天机器人集成Playwright

一个基于FastAPI后端和Streamlit前端的现代聊天机器人应用,集成了Google Vertex AI Gemini模型和Playwright MCP服务器支持。

  • by surath1
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 surath1/google_adk_playwright

使用说明

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服务器)

安装

  1. 克隆存储库:
git clone <repository-url>
cd mcp_projects
  1. 安装后端依赖项:
cd backend
pip install fastapi uvicorn vertexai python-dotenv pydantic
  1. 安装前端依赖项:
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.md

API终点

聊天端点

  • 发布 /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": "..."}

许可证

本项目按原样提供,用于演示目的。