关于 sn-image-base
这是 SenseNova-Skills 的基础层技能,提供图像生成、编辑、识别和文本优化命令行工具。它直接调用后端服务,不对输入进行预处理。
主要功能
- 01根据提示词生成图像
- 02编辑一张或多张参考图像
- 03使用 VLM 分析多张图像
- 04使用 LLM 优化文本
- 05通过命令行或环境变量配置服务
- 06以文本或 JSON 返回结果
适用场景
- 01根据文本提示生成图像
- 02使用参考图像编辑图像
- 03通过视觉模型分析图像内容
- 04使用 LLM 优化文本
安装
复制下面的命令,在终端中运行。
npx skills add https:/ / github.com/ opensensenova/ sensenova-skills --skill sn-image-base安装后在 Claude Code 中输入/sn-image-base确认已加载。
包含的文件
除 SKILL.md 外,安装时一起下载的参考资料和脚本。
.gitattributes.gitignoreREADME_CN.mdREADME.mdrequirements.txtreferences/api_spec.mdscripts/.python-versionextract_json.pypyproject.tomlruff.tomlsn_agent_runner.pyscripts/sn_image_base/__init__.pyconfigs.pyexceptions.pyscripts/sn_image_base/generation/__init__.pynano_banana.pyopenai_image.pysensenova.pyscripts/sn_image_base/generation/core/__init__.pyclient_base.pyscripts/sn_image_base/llm/__init__.pyanthropic_adapter.pychat_completions_adapter.pyllm_adapter.pyscripts/sn_image_base/utils/__init__.pyerror_utils.pyhttpx_client.pyscripts/sn_image_base/vlm/__init__.pyutils.pyvlm_adapter.py详细介绍
sn-image-base
依赖安装
pip install -r requirements.txt
概述
sn-image-base 是 SenseNova-Skills 项目的基础层技能(第 0 层),提供四种底层工具:
sn-image-generate:图像生成(调用 text-to-image-no-enhance API)sn-image-edit:使用 SenseNova U1.5 Lite 编辑图像(调用/images/edits)sn-image-recognize:图像识别(使用 VLM 分析图像内容)sn-text-optimize:文本优化(使用 LLM 处理文本)
此技能不会执行任何输入预处理,只调用后端服务并返回结果。
工具列表
sn-image-generate
调用 text-to-image-no-enhance API 的图像生成工具。
--prompt 为必填项;其他参数均为可选项:
| 参数 | 类型 | 默认值 | 描述 |
|---|---|---|---|
--prompt | string | 必填 | 图像生成提示词 |
--negative-prompt | string | "" | 负向提示词 |
--image-size | string | 2k | 图像尺寸预设(不区分大小写)。建议使用 2k。sensenova-u1.5-lite 支持 4k;其他 SenseNova 图像模型可能会拒绝该值。其他值 → status=failed。 |
--aspect-ratio | string | 16:9 | 宽高比,例如 1:1、16:9、9:16 |
--seed | int | None | 用于实现可复现生成的随机种子 |
--unet-name | string | None | 指定 UNet 模型名称 |
--api-key | string | SN_IMAGE_GEN_API_KEY -> SN_API_KEY | API 密钥(CLI 参数优先;如果均为空,则引发 MissingApiKeyError) |
--base-url | string | SN_IMAGE_GEN_BASE_URL -> SN_BASE_URL | API 基础 URL(CLI 参数优先) |
--poll-interval | float | 5.0 | 轮询间隔(秒) |
--timeout | float | 300.0 | 超时时间(秒) |
--insecure | flag | False | 禁用 TLS 验证 |
--save-path | Path | 自动生成 | 保存路径 |
SenseNova 图像请求默认会显式发送 watermark=false。支持 sensenova-u1-fast 和 sensenova-u1.5-lite;U1.5 Lite 还支持原生 4K 输出。目前,无水印功能处于免费公开测试阶段,之后可能会改为付费功能。
sn-image-edit
通过 /images/edits 端点使用 SenseNova U1.5 Lite 编辑一张或多张参考图像。本地路径会转换为 Data URL;HTTP(S) URL 和 Data URL 会直接传递。
python scripts/sn_agent_runner.py sn-image-edit \
--prompt "Change the background to a snowy mountain" \
--images source.png reference.png \
--save-path edited.png
编辑请求使用官方默认值:n=1、size=auto、watermark=false、prompt_extend=true 和 response_format=url。
sn-image-recognize
使用 VLM(视觉语言模型)分析图像内容的图像识别工具。支持输入多张图像。
--images 和 --user-prompt(或 --user-prompt-path)为必填项。其他参数均采用三级默认值(CLI > 环境变量 > 内置默认值):
| 参数 | 类型 | 内置默认值 | 环境变量 | 描述 |
|---|---|---|---|---|
--api-key | string | 无硬编码默认值 | SN_VISION_API_KEY -> SN_CHAT_API_KEY -> SN_API_KEY | 聊天运行时 API 密钥;如果均未设置,则引发 MissingApiKeyError |
--base-url | string | SN_CHAT_BASE_URL 默认值 | SN_VISION_BASE_URL -> SN_CHAT_BASE_URL -> SN_BASE_URL | 视觉服务提供方的基础 URL;未设置时回退到共享聊天/全局服务提供方 |
--model | string | sensenova-6.8-flash-lite | SN_VISION_MODEL -> SN_CHAT_MODEL | 支持视觉功能的模型名称 |
--vlm-type | string | openai-completions | SN_VISION_TYPE -> SN_CHAT_TYPE | 聊天协议类型覆盖值 |
--user-prompt-path | string | None | - | 本地文件路径,与 --user-prompt 互斥 |
--system-prompt-path | string | None | - | 本地文件路径,与 --system-prompt 互斥 |
--vlm-type 的可用值:
openai-completions:兼容 OpenAI 的/v1/chat/completions接口anthropic-messages:Anthropic Messages/v1/messages接口
sn-text-optimize
用于优化文本内容的文本优化工具,使用 LLM(语言模型)。不接受图像输入。
必须提供 --user-prompt(或 --user-prompt-path)。所有其他参数采用三级默认值(CLI > 环境变量 > 内置默认值):
| 参数 | 类型 | 内置默认值 | 环境变量 | 说明 |
|---|---|---|---|---|
--api-key | 字符串 | 无硬编码默认值 | SN_TEXT_API_KEY -> SN_CHAT_API_KEY -> SN_API_KEY | 聊天运行时 API 密钥;若均未设置,则引发 MissingApiKeyError |
--base-url | 字符串 | SN_CHAT_BASE_URL 默认值 | SN_TEXT_BASE_URL -> SN_CHAT_BASE_URL -> SN_BASE_URL | 文本提供方基础 URL;回退到共享聊天/全局提供方 |
--model | 字符串 | sensenova-6.8-flash-lite | SN_TEXT_MODEL -> SN_CHAT_MODEL | 文本模型名称 |
--llm-type | 字符串 | openai-completions | SN_TEXT_TYPE -> SN_CHAT_TYPE | 聊天协议类型覆盖值 |
--user-prompt-path | 字符串 | None | - | 本地文件路径,与 --user-prompt 互斥 |
--system-prompt-path | 字符串 | None | - | 本地文件路径,与 --system-prompt 互斥 |
--llm-type 的可用值:
openai-completions:兼容 OpenAI 的/v1/chat/completions接口anthropic-messages:Anthropic Messages/v1/messages接口
VLM 与 LLM
| 工具 | 模型类型 | 图像输入 | 接口类型参数 |
|---|---|---|---|
sn-image-recognize | VLM(视觉语言模型) | 是,支持多张图像 | --vlm-type |
sn-text-optimize | LLM(语言模型) | 否,仅支持文本 | --llm-type |
用法
所有工具均通过统一的 sn_agent_runner.py 入口点调用:
# Image generation (only prompt required; api-key/base-url have defaults)
python scripts/sn_agent_runner.py sn-image-generate \
--prompt "..."
# Image generation (override base-url)
python scripts/sn_agent_runner.py sn-image-generate \
--prompt "..." \
--base-url "https://custom-endpoint.com/v1"
# Image generation (explicitly override api-key)
python scripts/sn_agent_runner.py sn-image-generate \
--prompt "..." \
--api-key "sk-xxx"
# Image recognition (VLM) - minimal call (uses built-in Sensenova defaults)
python scripts/sn_agent_runner.py sn-image-recognize \
--user-prompt "Describe the image" \
--images "path/to/image.png"
# Image recognition (VLM) - override to Anthropic Claude API compatible (messages interface)
python scripts/sn_agent_runner.py sn-image-recognize \
--user-prompt "Describe the image" \
--images "path/to/image.png" \
--api-key "sk-ant-xxx" \
--base-url "https://api.anthropic.com" \
--model "claude-sonnet-4-6" \
--vlm-type "anthropic-messages"
# Text optimization (LLM) - minimal call (uses built-in Sensenova defaults)
python scripts/sn_agent_runner.py sn-text-optimize \
--user-prompt "Optimize the text: ..."
# Text optimization (LLM) - override to Anthropic Claude API compatible (messages interface)
python scripts/sn_agent_runner.py sn-text-optimize \
--user-prompt "Optimize the text: ..." \
--api-key "sk-ant-xxx" \
--base-url "https://api.anthropic.com" \
--model "claude-sonnet-4-6" \
--llm-type "anthropic-messages"
默认参数行为
sn-image-generate 的身份验证参数具有以下默认行为:
| 参数 | 默认值 | 覆盖方式 | 说明 |
|---|---|---|---|
--base-url | SN_IMAGE_GEN_BASE_URL -> SN_BASE_URL | --base-url "..." | CLI 参数优先 |
--api-key | SN_IMAGE_GEN_API_KEY -> SN_API_KEY | --api-key "..." | CLI 参数优先;若所有值均为空,则引发 MissingApiKeyError |
sn-image-recognize 和 sn-text-optimize 的优先级为:CLI 参数 > 工具专用环境变量 > 共享 SN_CHAT_* 环境变量 > 全局 SN_* 环境变量 > 内置默认值。
| 参数 | 内置默认值 | 视觉环境变量 | 文本环境变量 |
|---|---|---|---|
--api-key | 无(必须提供) | SN_VISION_API_KEY -> SN_CHAT_API_KEY -> SN_API_KEY | SN_TEXT_API_KEY -> SN_CHAT_API_KEY -> SN_API_KEY |
--base-url | https://token.sensenova.cn/v1 | SN_VISION_BASE_URL -> SN_CHAT_BASE_URL -> SN_BASE_URL | SN_TEXT_BASE_URL -> SN_CHAT_BASE_URL -> SN_BASE_URL |
--model | sensenova-6.8-flash-lite | SN_VISION_MODEL -> SN_CHAT_MODEL | SN_TEXT_MODEL -> SN_CHAT_MODEL |
--vlm-type / --llm-type | openai-completions | SN_VISION_TYPE -> SN_CHAT_TYPE | SN_TEXT_TYPE -> SN_CHAT_TYPE |
api_key 的解析顺序(从高到低):CLI --api-key > 工具专用密钥(SN_VISION_API_KEY/SN_TEXT_API_KEY)> SN_CHAT_API_KEY > SN_API_KEY。若均未设置,则引发 MissingApiKeyError。
只有 --api-key 必须通过 CLI 或环境变量提供;基础 URL、模型和接口类型均有共享的聊天默认值。
Agent 配置集成
Agent 可自动从 openclaw.json 读取参数,无需手动输入:
| CLI 参数 | openclaw.json 字段 | 示例 |
|---|---|---|
--base-url | providers.<name>.baseUrl | https://api.anthropic.com |
--llm-type | providers.<name>.api | anthropic-messages / openai-completions |
--vlm-type | providers.<name>.api | anthropic-messages / openai-completions |
--model | providers.<name>.models[].id | claude-sonnet-4-6 |
--api-key | providers.<name>.apiKey 或环境变量 | sk-cp-... |
注意:--llm-type 和 --vlm-type 共用同一个 providers.<name>.api 字段,分别供 LLM 和 VLM 工具使用。
provider.api 与接口类型的映射关系:
| api 值 | 对应的 --llm-type / --vlm-type | 端点路径 |
|---|---|---|
anthropic-messages | anthropic-messages | /v1/messages |
openai-completions | openai-completions | /v1/chat/completions |
openai-responses | (未来扩展) | /responses |
base-url 与接口类型的映射关系
不同的 API 类型对 base-url 格式有不同要求:
| 类型 | --llm-type / --vlm-type | 推荐的 base-url | 代码追加的路径 | 最终 URL 示例 |
|---|---|---|---|---|
| LLM | openai-completions | https://token.sensenova.cn/v1 | /chat/completions | https://token.sensenova.cn/v1/chat/completions |
| LLM | anthropic-messages | https://api.anthropic.com/v1 | /messages | https://api.anthropic.com/v1/messages |
| VLM | openai-completions | https://token.sensenova.cn/v1 | /chat/completions | https://token.sensenova.cn/v1/chat/completions |
| VLM | anthropic-messages | https://api.anthropic.com/v1 | /messages | https://api.anthropic.com/v1/messages |
注意:
- 推荐的聊天 base URL 应包含提供商 API 版本路径,例如
/v1。 - 为兼容起见,如果配置的聊天 base URL 不含路径,运行器会追加
/v1/chat/completions或/v1/messages。 - 如果配置的聊天 base URL 已包含
/v1等路径,运行器只会追加/chat/completions或/messages。 - 有些提供商使用
/v1以外的版本化路径,例如 Gemini 的/v1beta/openai。
输出格式
所有工具都支持两种输出格式:
--output-format text(默认):输出纯文本结果--output-format json:输出 JSON,其中包含status和elapsed_seconds(运行时间,单位为秒,四舍五入到小数点后 2 位)
sn-image-recognize 和 sn-text-optimize 的 JSON 输出还包含 model、base_url 和 interface_type,用于验证实际生效的运行时配置:
{
"status": "ok",
"result": "...",
"model": "sensenova-6.8-flash-lite",
"base_url": "https://token.sensenova.cn/v1",
"interface_type": "openai-completions",
"elapsed_seconds": 1.23
}
失败时:
{
"status": "failed",
"error": "error message",
"elapsed_seconds": 0.05
}
输入/输出规范
详情请参阅 references/api_spec.md。