dsh-imagegen: Image Generation Plugin for DSH

DSH 里的模型调用通常遵循聊天协议。guaihub provider 走的是 api: anthropic-messages,即便声明了图片模型也只回文字。中转站本身有 POST /v1/images/generations 接口,这个插件直接打那个接口,跟网页版 Studio 用的是同一套后端。

插件定位

dsh-imagegen 是由 dong2007-png 维护的模型推理插件。它直接调用 New API 中转站(如 guaihub)的 OpenAI 风格接口生成图片,支持将图片显示在对话工具卡片中,同时支持落盘到工作区。

核心能力

插件提供以下工具:

  1. generate_image:文字生成图片。支持参数包括 prompt、model、size、n、quality、background、save_path。
  2. list_image_models:从 GET /v1/models 接口过滤出可用的图片模型名。

安装

使用插件管理器安装本地 bundle:

plugin_manager(action="install_bundle", target="file:<你本地的 clone 路径>/dsh-imagegen")

安装后,依赖会写入 ~/.dsh/profiles/desktop/package.json,bundle 会追加到 dsh.profile.bundles,包实体会放入 ~/.dsh/profiles/desktop/node_modules/dsh-imagegen,且支持热加载。

配置

默认配置指向 guaihub 中转站,密钥通过 DSH 的 credentials 服务解析(进程 env → provider 托管存储 → .env)。

在 DSH 插件配置界面或 cordis.patch.yml 中可覆盖配置:

- id: dsh-imagegen
  config:
    defaultModel: gpt-image-2.5-flare
    outputDir: images/gen

配置项说明:

  • baseURL:中转站地址(默认 https://guaihub.com)。
  • apiKeyEnv:密钥名(默认 GUAIHUB_API_KEY)。
  • defaultModel:默认图片模型(默认 gpt-image-2)。
  • defaultSize:默认尺寸(默认 1024x1024)。
  • outputDir:落盘目录(相对会话工作目录,默认 images)。
  • saveFiles:是否写入磁盘(默认 true)。
  • timeoutMs:请求超时(默认 300000)。

典型用法

在 DSH 对话中直接调用 generate_image 工具。也可以使用仓库自带的 CLI 脚本 cli/gen.mjs:

node $cli -p "一只赛博朋克猫,霓虹雨夜" -o images/cat.png
node $cli --list
node $cli --edit in.png -p "把背景换成海边"

注意事项

  1. 文件系统权限:写盘使用宿主进程里的 node:fs,不经过 DSH 的 fs 沙箱与文件版本观测。
  2. 依赖处理:pnpm 对 file: 依赖是复制而不是软链。
  3. 更新同步:改完源码后,需要把 ~/dsh/dsh-imagegen 重新 install_bundle 一次,或者手动复制 lib/index.js 到 ~/.dsh/profiles/desktop/node_modules/dsh-imagegen/lib/。
  4. 网络问题:github.com 的 releases/raw 在某些网络下直连不通,可改用第三方镜像。

许可证

基于 MIT License 发布。

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye