ai_service/docs/接口文档.md
2025-07-05 04:24:43 +08:00

127 lines
2.5 KiB
Markdown

# AI海报生成系统 API文档
## 系统架构
```
前端 → FastAPI(8000) → ComfyUI(101.201.50.90:8188)
Vue代码 + PSD文件
```
## API端点
### 1. 健康检查
**GET** `/health`
```json
{
"status": "healthy",
"timestamp": "2025-01-02T20:30:00"
}
```
### 2. 生成海报
**POST** `/api/generate-poster`
**请求**:
```json
{
"user_input": "端午节海报,传统风格",
"session_id": "可选"
}
```
**响应**:
```json
{
"status": "success",
"message": "海报生成完成",
"data": {
"vue_code": "完整Vue组件代码",
"suggestions": {
"layer5_logo_content": {
"text": "主办方",
"color": "#000000"
},
"layer6_title_content": {
"content": "端午安康",
"font_name": "SimHei",
"color": "#7E0C6E"
},
"layer7_subtitle_content": {
"content": "粽叶飘香,龙舟竞渡",
"font_name": "Microsoft YaHei",
"color": "#000000"
}
},
"analysis_result": {
"main_theme": "端午节祝福",
"width": 1080,
"height": 1920,
"keywords": ["端午节", "传统", "荷花"]
},
"file_size_mb": 5.93,
"generated_images": 2
},
"session_id": "会话ID"
}
```
### 3. 文件下载
**GET** `/api/download/{file_type}?session_id={session_id}`
参数: `file_type` = `vue` | `psd` | `json`
### 4. 会话状态
**GET** `/api/status/{session_id}`
```json
{
"session_id": "会话ID",
"files": {
"vue_file": true,
"psd_file": true,
"content_file": true
},
"folder": "会话文件夹路径"
}
```
## 使用示例
### JavaScript
```javascript
const response = await fetch('http://localhost:8000/api/generate-poster', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_input: "春节海报,红色背景" })
});
const result = await response.json();
if (result.status === 'success') {
// 下载文件
const url = `http://localhost:8000/api/download/psd?session_id=${result.session_id}`;
window.open(url);
}
```
### Python
```python
import requests
response = requests.post('http://localhost:8000/api/generate-poster',
json={"user_input": "端午节海报,传统风格"})
result = response.json()
if result["status"] == "success":
session_id = result["session_id"]
# 下载PSD文件
psd_url = f"http://localhost:8000/api/download/psd?session_id={session_id}"
psd_response = requests.get(psd_url)
with open("poster.psd", "wb") as f:
f.write(psd_response.content)
```