AI 提示词管理平台 - 一个统一的提示词管理系统,帮助用户高效录入、管理、分享和调用AI提示词。
AI Prompt Manager 是一个全栈Web应用,旨在解决以下问题:
- 提示词缺乏统一管理,难以查找和复用
- 缺乏版本控制和协作机制
- 与API集成不够紧密,调用效率低
- 提示词录入:支持单条和批量录入(CSV/Excel),提供实时预览
- 提示词管理:增删改查、分类、标签、搜索、版本控制
- 分享功能:私有分享(权限控制)和公开分享(浏览、点赞、下载)
- API集成:提供调用接口,支持变量动态填充
AiPromoteManager/
├── backend/ # 后端 FastAPI 项目
│ ├── app/
│ │ ├── api/ # API 路由层
│ │ │ ├── api_v1/ # V1 版本API
│ │ │ │ ├── endpoints/ # 具体业务端点
│ │ │ │ └── api.py # 路由聚合
│ │ │ └── deps.py # 依赖注入
│ │ ├── core/ # 核心配置
│ │ │ ├── config.py # 应用配置
│ │ │ └── security.py # 安全认证
│ │ ├── crud/ # 数据库操作层
│ │ ├── db/ # 数据库配置
│ │ ├── models/ # SQLAlchemy 模型
│ │ └── schemas/ # Pydantic 数据模型
│ ├── alembic/ # 数据库迁移
│ ├── main.py # FastAPI 应用入口
│ ├── requirements.txt # Python 依赖
│ └── Dockerfile # 后端容器配置
├── frontend/ # 前端 Vue.js 项目
│ ├── src/
│ │ ├── assets/ # 静态资源
│ │ ├── components/ # Vue 组件
│ │ ├── router/ # 路由配置
│ │ ├── stores/ # Pinia 状态管理
│ │ ├── types/ # TypeScript 类型定义
│ │ ├── utils/ # 工具函数
│ │ └── views/ # 页面组件
│ ├── package.json # npm 配置
│ ├── vite.config.ts # Vite 配置
│ └── Dockerfile # 前端容器配置
└── docs/ # 文档目录
后端技术栈
- 框架: FastAPI 0.104.1
- 数据库: MySQL 8.0+ (主数据存储)
- 缓存: Redis (缓存层)
- ORM: SQLAlchemy 2.0.23
- 认证: JWT + PassLib
- 数据库迁移: Alembic 1.12.1
- ASGI服务器: Uvicorn 0.24.0
前端技术栈
- 框架: Vue.js 3.5.13 + TypeScript
- 构建工具: Vite 6.0.5
- 路由: Vue Router 4.5.0
- 状态管理: Pinia 2.3.0
- UI框架: Tailwind CSS 3.4.17 + Headless UI
- HTTP客户端: Axios 1.7.9
- 富文本编辑: md-editor-v3 5.2.2
数据库设计
users- 用户表categories- 分类表(支持多级分类)tags- 标签表prompts- 提示词表versions- 版本控制表shares- 分享表prompt_tag- 提示词标签关联表
- Python 3.8+
- Node.js 16+
- MySQL 8.0+
- Redis (可选,用于缓存)
git clone <repository-url>
cd AiPromoteManager# 进入后端目录
cd backend
# 创建虚拟环境
python -m venv venv
# 激活虚拟环境
# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate
# 安装依赖
pip install -r requirements.txt# 创建数据库
mysql -u root -p < init.sql
# 运行数据库迁移
alembic upgrade head在 backend 目录下创建 .env 文件:
# 数据库配置
MYSQL_HOST=localhost
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=your_password
MYSQL_DB=ai_prompt_manager
# Redis配置
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0
# JWT配置
SECRET_KEY=your-super-secret-key-change-in-production
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=1440cd backend
uvicorn main:app --host 0.0.0.0 --port 8000 --reloadAPI文档访问:http://localhost:8000/docs
# 进入前端目录
cd frontend
# 安装依赖
npm install
# 启动开发服务器
npm run dev前端应用访问:http://localhost:5173
# 构建后端镜像
cd backend
docker build -t ai-prompt-manager-backend .
# 运行后端容器
docker run -d \
--name ai-prompt-backend \
-p 8000:8000 \
-e MYSQL_HOST=your_mysql_host \
-e MYSQL_PASSWORD=your_password \
ai-prompt-manager-backend# 构建前端镜像
cd frontend
docker build -t ai-prompt-manager-frontend .
# 运行前端容器
docker run -d \
--name ai-prompt-frontend \
-p 80:80 \
ai-prompt-manager-frontend创建 docker-compose.yml 文件:
version: '3.8'
services:
mysql:
image: mysql:8.0
container_name: ai-prompt-mysql
environment:
MYSQL_ROOT_PASSWORD: your_password
MYSQL_DATABASE: ai_prompt_manager
ports:
- "3306:3306"
volumes:
- mysql_data:/var/lib/mysql
- ./backend/init.sql:/docker-entrypoint-initdb.d/init.sql
redis:
image: redis:alpine
container_name: ai-prompt-redis
ports:
- "6379:6379"
backend:
build: ./backend
container_name: ai-prompt-backend
ports:
- "8000:8000"
environment:
- MYSQL_HOST=mysql
- MYSQL_PASSWORD=your_password
- REDIS_HOST=redis
depends_on:
- mysql
- redis
frontend:
build: ./frontend
container_name: ai-prompt-frontend
ports:
- "80:80"
depends_on:
- backend
volumes:
mysql_data:启动所有服务:
docker-compose up -dVS Code 调试配置 (.vscode/launch.json):
{
"version": "0.2.0",
"configurations": [
{
"name": "FastAPI Debug",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/backend/main.py",
"module": "uvicorn",
"args": [
"main:app",
"--host", "0.0.0.0",
"--port", "8000",
"--reload"
],
"cwd": "${workspaceFolder}/backend",
"console": "integratedTerminal",
"env": {
"PYTHONPATH": "${workspaceFolder}/backend"
}
}
]
}import logging
# 配置日志
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
# 在代码中使用
logger.debug("Debug message")
logger.info("Info message")# 查看数据库迁移历史
alembic history
# 创建新的迁移文件
alembic revision --autogenerate -m "migration description"
# 回滚到指定版本
alembic downgrade <revision_id>安装 Vue DevTools 浏览器扩展进行组件调试。
在 src/utils/request.ts 中配置请求拦截器:
// 请求拦截器
request.interceptors.request.use(
(config) => {
console.log('Request:', config)
return config
}
)
// 响应拦截器
request.interceptors.response.use(
(response) => {
console.log('Response:', response)
return response
}
)在 vite.config.ts 中配置代理和调试选项:
export default defineConfig({
plugins: [vue()],
server: {
port: 5173,
proxy: {
'/api': {
target: 'http://localhost:8000',
changeOrigin: true,
configure: (proxy, _options) => {
proxy.on('error', (err, _req, _res) => {
console.log('proxy error', err);
});
proxy.on('proxyReq', (proxyReq, req, _res) => {
console.log('Sending Request to the Target:', req.method, req.url);
});
proxy.on('proxyRes', (proxyRes, req, _res) => {
console.log('Received Response from the Target:', proxyRes.statusCode, req.url);
});
},
}
}
}
})-
认证相关
POST /api/v1/auth/login- 用户登录POST /api/v1/auth/register- 用户注册
-
提示词管理
GET /api/v1/prompts/- 获取提示词列表POST /api/v1/prompts/- 创建提示词GET /api/v1/prompts/{id}- 获取提示词详情PUT /api/v1/prompts/{id}- 更新提示词DELETE /api/v1/prompts/{id}- 删除提示词
-
分类管理
GET /api/v1/categories/- 获取分类列表POST /api/v1/categories/- 创建分类
-
标签管理
GET /api/v1/tags/- 获取标签列表POST /api/v1/tags/- 创建标签
-
分享功能
POST /api/v1/shares/- 创建分享链接GET /api/v1/shares/{token}- 访问分享内容
完整API文档访问:http://localhost:8000/docs
cd backend
# 运行所有测试
pytest
# 运行特定测试文件
pytest tests/test_prompts.py
# 生成测试覆盖率报告
pytest --cov=app tests/cd frontend
# 运行单元测试
npm run test
# 运行 e2e 测试
npm run test:e2e错误: sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError)
解决方案:
- 检查 MySQL 服务是否启动
- 验证数据库连接配置
- 确认防火墙设置
错误: ECONNREFUSED 127.0.0.1:8000
解决方案:
- 确认后端服务已启动
- 检查
vite.config.ts代理配置 - 验证端口占用情况
错误: Docker build failed
解决方案:
- 检查 Dockerfile 语法
- 确认基础镜像可用
- 检查网络连接和镜像源
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 创建 Pull Request
本项目采用 MIT 许可证 - 查看 LICENSE 文件了解详情。
如果你有任何问题或建议,请通过以下方式联系:
- 创建 Issue
- 发送邮件到 [your-email@example.com]
- 加入我们的社区讨论
快速链接