圖像生成
Hermes Agent 可以使用 FAL.ai 的 FLUX 2 Pro 模型,通過 Clarity Upscaler 實現自動 2 倍超分辨率放大,從而生成高質量的圖像。
設置
獲取 FAL API 密鑰
- 訪問 fal.ai 註冊賬號
- 從您的儀表板生成 API 密鑰
配置密鑰
# 添加到“0”
FAL_KEY=your-fal-api-key-here
安裝客戶端庫
pip install fal-client
信息
當設置 FAL_KEY 後,圖像生成工具將自動可用。無需額外配置工具集。
工作原理
當您要求 Hermes 生成圖像時:
- 生成 — 您的提示詞將發送至 FLUX 2 Pro 模型(
fal-ai/flux-2-pro) - 超分辨率放大 — 生成的圖像將自動使用 Clarity Upscaler(
fal-ai/clarity-upscaler)進行 2 倍放大 - 交付 — 返回超分辨率後的圖像 URL
如果超分辨率因任何原因失敗,將自動回退至原始分辨率圖像。
使用方法
只需要求 Hermes 創建圖像:
Generate an image of a serene mountain landscape with cherry blossoms
Create a portrait of a wise old owl perched on an ancient tree branch
Make me a futuristic cityscape with flying cars and neon lights
參數
image_generate_tool 接受以下參數:
| 參數 | 默認值 | 範圍 | 說明 |
|---|---|---|---|
prompt | (必需) | — | 所需圖像的文字描述 |
aspect_ratio | "landscape" | landscape, square, portrait | 圖像寬高比 |
num_inference_steps | 50 | 1–100 | 去噪步數(越多 = 質量越高,速度越慢) |
guidance_scale | 4.5 | 0.1–20.0 | 與提示詞的貼合程度 |
num_images | 1 | 1–4 | 生成圖像的數量 |
output_format | "png" | png, jpeg | 圖像文件格式 |
seed | (隨機) | 任意整數 | 用於結果可復現的隨機種子 |
寬高比
該工具使用簡化的寬高比名稱,映射到 FLUX 2 Pro 的圖像尺寸:
| 寬高比 | 映射至 | 適用場景 |
|---|---|---|
landscape | landscape_16_9 | 壁紙、橫幅、場景圖 |
square | square_hd | 頭像、社交媒體帖子 |
portrait | portrait_16_9 | 角色藝術、手機壁紙 |
提示
您也可以直接使用原始的 FLUX 2 Pro 尺寸預設:square_hd、square、portrait_4_3、portrait_16_9、landscape_4_3、landscape_16_9。還支持最大 2048x2048 的自定義尺寸。
自動超分辨率放大
每張生成的圖像都會自動使用 FAL.ai 的 Clarity Upscaler 進行 2 倍放大,設置如下:
| 設置 | 值 |
|---|---|
| 放大倍數 | 2x |
| 創造性 | 0.35 |
| 相似度 | 0.6 |
| 引導尺度 | 4 |
| 推理步數 | 18 |
| 正面提示詞 | "masterpiece, best quality, highres" + 您的原始提示詞 |
| 負面提示詞 | "(worst quality, low quality, normal quality:2)" |
超分辨率放大器在保留原始構圖的同時增強細節和分辨率。如果超分辨率失敗(網絡問題、速率限制等),將自動返回原始分辨率圖像。
示例提示詞
以下是一些可嘗試的有效提示詞:
A candid street photo of a woman with a pink bob and bold eyeliner
Modern architecture building with glass facade, sunset lighting
Abstract art with vibrant colors and geometric patterns
Portrait of a wise old owl perched on ancient tree branch
Futuristic cityscape with flying cars and neon lights
調試
啟用圖像生成的調試日誌:
export IMAGE_TOOLS_DEBUG=true
調試日誌將保存至 ./logs/image_tools_debug_<session_id>.json,包含每次生成請求的詳細信息、參數、耗時及任何錯誤。
安全設置
圖像生成工具默認禁用安全檢查(safety_tolerance: 5,最寬鬆設置)。此配置在代碼級別完成,用戶不可調整。
平臺交付
生成的圖像根據平臺不同,交付方式也不同:
| 平臺 | 交付方式 |
|---|---|
| CLI | 以 Markdown 格式打印圖像 URL  — 點擊可在瀏覽器中打開 |
| Telegram | 以圖片消息發送,提示詞作為標題 |
| Discord | 圖像嵌入消息中 |
| Slack | 消息中包含圖像 URL(Slack 會自動展開) |
| 以媒體消息發送圖像 | |
| 其他平臺 | 圖像 URL 以純文本形式發送 |
Agent 在響應中使用 MEDIA:<url> 語法,平臺適配器會將其轉換為適當格式。
限制
- 需要 FAL API 密鑰 — 圖像生成將產生 FAL.ai 賬戶上的 API 費用
- 無圖像編輯功能 — 僅支持文生圖,不支持修復或圖生圖
- 基於 URL 的交付 — 圖像以臨時的 FAL.ai URL 返回,不會本地保存。URL 通常在數小時後過期
- 超分辨率增加延遲 — 自動 2 倍放大步驟會增加處理時間
- 每請求最多 4 張圖像 —
num_images上限為 4