finish api and docs validation fixes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
# API 图片修改 Agent 调用说明
|
||||
# API 图片绘制及修改 Agent 调用说明
|
||||
|
||||
本服务提供一个本地 HTTP API,用于让其他 Agent、脚本或自动化系统上传已有图片/文档,并按文字指令生成或修改图片。
|
||||
本服务提供一个本地 HTTP API,用于让其他 Agent、脚本或自动化系统按文字指令绘制图片,或上传已有图片/文档并进一步修改、分析。
|
||||
|
||||
默认地址:
|
||||
|
||||
@@ -120,6 +120,18 @@ curl -X POST http://localhost:3002/api/edit-image \
|
||||
|
||||
调用方可以直接使用 `images[0].dataUrl` 预览图片,或把 `images[0].data` 解码保存为 PNG 文件。
|
||||
|
||||
## 纯文字绘制图片
|
||||
|
||||
不上传图片时,直接用 `prompt` 生成新图片:
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:3002/api/generate \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "Authorization: Bearer YOUR_LONG_RANDOM_API_TOKEN" \
|
||||
-H "x-gemini-api-key: YOUR_GEMINI_API_KEY" \
|
||||
-d "{\"prompt\":\"画一个蓝天白云下的极简风景插画\",\"imageSize\":\"1K\",\"aspectRatio\":\"1:1\"}"
|
||||
```
|
||||
|
||||
## JSON/Base64 方式修改图片
|
||||
|
||||
如果 Agent 已经拿到了图片 base64,可以不用 multipart:
|
||||
@@ -101,7 +101,7 @@ curl -X POST http://localhost:3002/api/analyze-document \
|
||||
|
||||
API auth is required by default. For local-only development, you can set `API_AUTH_DISABLED=true`, but do not use that on a LAN or server.
|
||||
|
||||
For Agent-facing image editing instructions, see `API图片修改-Agent.md`.
|
||||
For Agent-facing image generation and editing instructions, see `API图片绘制及修改-Agent.md`.
|
||||
|
||||
## Docker Compose Deploy
|
||||
|
||||
|
||||
@@ -198,7 +198,7 @@ function uploadedFileToPart(file: Express.Multer.File): GeminiPart {
|
||||
return {
|
||||
inlineData: {
|
||||
data: file.buffer.toString('base64'),
|
||||
mimeType: file.mimetype || 'application/octet-stream',
|
||||
mimeType: inferMimeType(file),
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -219,6 +219,30 @@ function normalizeTextInput(value: unknown) {
|
||||
return value == null ? '' : String(value);
|
||||
}
|
||||
|
||||
function inferMimeType(file: Express.Multer.File) {
|
||||
if (file.mimetype && file.mimetype !== 'application/octet-stream') {
|
||||
return file.mimetype;
|
||||
}
|
||||
|
||||
const ext = path.extname(file.originalname || '').toLowerCase();
|
||||
const mimeByExt: Record<string, string> = {
|
||||
'.png': 'image/png',
|
||||
'.jpg': 'image/jpeg',
|
||||
'.jpeg': 'image/jpeg',
|
||||
'.webp': 'image/webp',
|
||||
'.gif': 'image/gif',
|
||||
'.pdf': 'application/pdf',
|
||||
'.txt': 'text/plain',
|
||||
'.md': 'text/plain',
|
||||
'.csv': 'text/csv',
|
||||
'.json': 'application/json',
|
||||
'.html': 'text/html',
|
||||
'.htm': 'text/html',
|
||||
};
|
||||
|
||||
return mimeByExt[ext] || 'application/octet-stream';
|
||||
}
|
||||
|
||||
async function buildParts(body: GenerateRequest, files: Express.Multer.File[] = []) {
|
||||
const prompt = normalizeTextInput(body.prompt || body.instruction).trim();
|
||||
if (!prompt) {
|
||||
|
||||
@@ -83,13 +83,13 @@ docker compose -f docker_compose.yaml up -d --build --force-recreate
|
||||
```yaml
|
||||
ports:
|
||||
- "4001:3000"
|
||||
- "4002:3002"
|
||||
- "4000:3002"
|
||||
```
|
||||
|
||||
修改后访问地址变为:
|
||||
|
||||
- 前端页面:`http://目标机器IP:4001`
|
||||
- API:`http://目标机器IP:4002`
|
||||
- API:`http://目标机器IP:4000`
|
||||
|
||||
如果修改了前端宿主机端口,也建议同步修改 `.env.local`:
|
||||
|
||||
@@ -184,7 +184,7 @@ APP_URL="http://192.168.31.5:3000"
|
||||
```yaml
|
||||
ports:
|
||||
- "4001:3000"
|
||||
- "4002:3002"
|
||||
- "4000:3002"
|
||||
```
|
||||
|
||||
容器内端口右侧保持不变。
|
||||
|
||||
Reference in New Issue
Block a user