126 lines
4.0 KiB
Markdown
126 lines
4.0 KiB
Markdown
---
|
||
name: gemini-web-generate
|
||
description: "Generate images through Gemini web interface via a Puppeteer CLI. Supports text-to-image, image-to-image (single/multi reference), multi-turn conversations, session management, and download-only mode. Use when: (1) User asks to generate images with Gemini, (2) User says 'Gemini 生图', (3) Image-to-image or style transfer, (4) Continuing an existing Gemini image conversation."
|
||
---
|
||
|
||
# Gemini 网页版生图
|
||
|
||
通过 Puppeteer CLI (`scripts/cli.js`) 驱动浏览器完成 Gemini 网页生图全流程。
|
||
|
||
浏览器由 `browser` 工具管理(CLI 通过 CDP 连接,默认 `http://127.0.0.1:9223`,可通过 `CDP_URL` 环境变量覆盖)。
|
||
|
||
首次使用:
|
||
|
||
```bash
|
||
cd <skill-dir>/scripts && npm install
|
||
```
|
||
|
||
## 快速开始
|
||
|
||
```bash
|
||
node scripts/cli.js generate --prompt "提示词" --mode single
|
||
```
|
||
|
||
CLI 自动完成:打开标签页 → 导航 → 粘贴参考图 → 输入提示词 → 发送 → 等待生成 → 下载到 `scripts/output/originals/` → 关闭标签页(single 模式)。
|
||
|
||
生图完成后将图片移到目标位置,通过 `message` 工具发送。
|
||
|
||
## 所有生图方式
|
||
|
||
### 文生图
|
||
|
||
```bash
|
||
node scripts/cli.js generate --prompt "提示词" --mode single
|
||
```
|
||
|
||
### 图生图
|
||
|
||
```bash
|
||
# 单张参考图
|
||
node scripts/cli.js generate --prompt "提示词" --image /path/to/ref.png --mode single
|
||
|
||
# 多张参考图(逗号分隔,最多 10 张)
|
||
node scripts/cli.js generate --prompt "提示词" --images "/path/a.png,/path/b.png" --mode single
|
||
```
|
||
|
||
参考图路径含空格时,先 cd 到目录再用相对路径。
|
||
|
||
### 从文件或管道读取提示词
|
||
|
||
```bash
|
||
node scripts/cli.js generate --prompt-file /path/to/prompt.txt --mode single
|
||
echo "提示词" | node scripts/cli.js generate --prompt stdin --mode single
|
||
```
|
||
|
||
### 多轮对话
|
||
|
||
```bash
|
||
# 首轮(不加 --mode,保持标签页)
|
||
node scripts/cli.js generate --prompt "画一幅日落"
|
||
|
||
# 续次(不加 --mode)
|
||
node scripts/cli.js generate --session <id> --prompt "加入一艘小船"
|
||
|
||
# 末轮(--mode single 自动关闭)
|
||
node scripts/cli.js generate --session <id> --prompt "最终调整" --mode single
|
||
```
|
||
|
||
### 通过对话链接继续
|
||
|
||
```bash
|
||
node scripts/cli.js generate --chatUrl "https://gemini.google.com/app/xxxx" --prompt "换成水彩风格"
|
||
```
|
||
|
||
### 仅下载已有图片
|
||
|
||
对话已有生成图片时,不加 `--prompt` 直接下载:
|
||
|
||
```bash
|
||
node scripts/cli.js generate --chatUrl "https://gemini.google.com/app/xxxx" --mode single
|
||
```
|
||
|
||
## 结果处理
|
||
|
||
### 成功
|
||
|
||
图片在 `scripts/output/originals/`。移到目标位置后发送。
|
||
|
||
### 超时或失败
|
||
|
||
```bash
|
||
node scripts/cli.js status --session <id> --wait
|
||
```
|
||
|
||
| 状态 | 处理 |
|
||
|:---|:---|
|
||
| `done` | `node scripts/cli.js download --session <id>` |
|
||
| `generating` | 继续等待 |
|
||
| `error` | 报告错误,调整提示词重试 |
|
||
|
||
加 `--screenshot` 可在出错/超时时自动截图辅助诊断。
|
||
|
||
## 会话管理
|
||
|
||
```bash
|
||
node scripts/cli.js sessions # 列出活跃会话
|
||
node scripts/cli.js find_session --chatUrl "<url>" --open # 找回丢失的 session
|
||
node scripts/cli.js close --session <id> # 关闭会话
|
||
node scripts/cli.js download --session <id> # 下载已生成图片
|
||
node scripts/cli.js status --session <id> [--wait] # 检查状态
|
||
```
|
||
|
||
## generate 参数参考
|
||
|
||
| 参数 | 说明 | 默认值 |
|
||
|:---|:---|:---|
|
||
| `--prompt` | 提示词。`"stdin"` 从标准输入读取 | 必填(与 `--chatUrl` 共用时可省略,进入纯下载模式) |
|
||
| `--prompt-file` | 从文件读取提示词 | - |
|
||
| `--image` | 单张参考图 | - |
|
||
| `--images` | 多张参考图,逗号分隔,最多 10 张 | - |
|
||
| `--session` | 复用已有会话 ID | - |
|
||
| `--chatUrl` | Gemini 对话链接 | - |
|
||
| `--mode` | `single` 生成后关闭标签页 / `multi` 保持打开 | `multi` |
|
||
| `--timeout` | 生成超时(毫秒) | 300000 |
|
||
| `--download-timeout` | 下载超时(毫秒) | 120000 |
|
||
| `--screenshot` | 出错/超时时自动截图 | 关闭 |
|