TensorsLab Image Generation
Overview
This skill enables AI-powered image generation through TensorsLab's API, supporting both text-to-image and image-to-image workflows. The agent enhances user prompts with detailed visual descriptions before calling the API, ensuring high-quality outputs.
Authentication Check
Before any image generation, verify the API key is configured:
CODEBLOCK0
If not set, display this friendly message:
CODEBLOCK1
Models
| Model | Description | Best For |
|---|
| seedreamv45 | Latest enhanced model | General purpose, highest quality |
| seedreamv4 |
Standard model | Fast generation, good quality |
|
zimage | Alternative model | Specific artistic styles |
Default: INLINECODE0
Workflow
For additional scenarios beyond basic generation (avatar generation, watermark removal, object erasure, face replacement), see references/scenarios.md.
1. Text-to-Image Generation
User request: "画一个在月球上吃热狗的宇航员"
Agent processing:
- 1. Extract the core subject and action
- Enhance prompt with details (lighting, composition, style, atmosphere)
- Call API with enriched prompt
- Monitor progress with heartbeat updates
- Download to INLINECODE1
Example enhanced prompt:
CODEBLOCK2
2. Image-to-Image Generation
User request: "把 cat.png 的背景换成太空" or "参考 sketch.png 渲染成 3D 模型"
Agent processing:
- 1. Extract image file paths (absolute or relative to current directory)
- Enhance prompt with transformation instructions
- Upload source images with prompt
- Monitor and download results
Parameters for image-to-image:
- -
sourceImage: Array of image files (for local upload) - INLINECODE3 : URL of source image
- INLINECODE4 : Description of desired transformation
3. Image Editing (General Purpose)
General-purpose editing for any local image modifications.
User request examples:
- - "把这张图的天空改成日落色"
- "给人物加上墨镜"
- "把头发颜色染成粉色"
Agent processing:
- 1. Extract image file path
- Parse the specific editing instruction (what to change, where)
- Build enhanced prompt with precise editing guidance
- Call API with source image and editing prompt
- Save result to INLINECODE5
Example enhanced prompt:
CODEBLOCK3
For avatar generation, watermark removal, object erasure, and face replacement scenarios, see references/scenarios.md.
4. Resolution Options
Supported formats:
- - Aspect ratios:
9:16, 16:9, 3:4, 4:3, 1:1, 2:3, INLINECODE12 - Resolution levels:
2K, INLINECODE14 - Specific dimensions:
WxH format (e.g., 2048x2048, 1920x1080)
- Constraint: Total pixels must be between 3,686,400 and 16,777,216
Using the Script
Execute the Python script directly:
CODEBLOCK4
Task Status Flow
| Status | Code | Meaning |
|---|
| Queued | 1 | Task waiting in queue |
| Processing |
2 | Currently generating |
| Completed | 3 | Done, images ready |
| Failed | 4 | Error occurred |
Error Handling
Translate API errors to user-friendly messages:
| Error Code | Meaning | User Message |
|---|
| 9000 | Insufficient credits | "亲,积分用完啦,请前往 https://tensorai.tensorslab.com"/ 充值" |
| 9999 |
General error | Show the specific error message |
Output
All images are saved to output directory with naming pattern:
- - Default:
./tensorslab_output/ (current working directory) - Custom: Use
--output-dir or -o to specify a different path - Naming:
{task_id}_{index}.{ext} - e.g., INLINECODE22
After completion, inform user:
CODEBLOCK5
Resources
- - scripts/tensorslabimage.py: Main API client with full CLI support
- references/apireference.md: Detailed API documentation
- references/scenarios.md: Advanced usage scenarios (avatar generation, watermark removal, object erasure, face replacement)
TensorsLab 图像生成
概述
该技能通过 TensorsLab 的 API 实现 AI 驱动的图像生成,支持文生图和图生图工作流。智能体在调用 API 前会使用详细的视觉描述增强用户提示词,确保高质量输出。
身份验证检查
在生成任何图像之前,请确认 API 密钥已配置:
bash
仅检查变量是否存在,不输出完整值
[ -n $TENSORSLAB
APIKEY ] && echo ✅ API 密钥已设置 || echo ❌ TENSORSLAB
APIKEY 未设置
如果未设置,显示以下友好提示:
您好!要生成高质量的内容,您需要先进行简单的配置:
- 1. 访问 https://tensorai.tensorslab.com/ 登录并订阅。
- 在控制台中获取您的专属 API Key。
- 将其保存为环境变量:
- Windows (PowerShell): $env:TENSORSLAB
APIKEY=您的Key
- Mac/Linux: export TENSORSLAB
APIKEY=您的Key
模型
| 模型 | 描述 | 最佳用途 |
|---|
| seedreamv45 | 最新增强模型 | 通用用途,最高质量 |
| seedreamv4 |
标准模型 | 快速生成,质量良好 |
|
zimage | 替代模型 | 特定艺术风格 |
默认值:seedreamv4
工作流
对于基本生成之外的额外场景(头像生成、水印去除、物体擦除、面部替换),请参阅 references/scenarios.md。
1. 文生图生成
用户请求:画一个在月球上吃热狗的宇航员
智能体处理流程:
- 1. 提取核心主体和动作
- 用细节增强提示词(光照、构图、风格、氛围)
- 使用丰富后的提示词调用 API
- 通过心跳更新监控进度
- 下载到 ./tensorslab_output/
增强提示词示例:
一名宇航员坐在月球表面,吃着带芥末的热狗,
电影级光照,背景可见地球,高度细节化,
照片级真实感,8k 质量,低太阳角度形成的戏剧性阴影
2. 图生图生成
用户请求:把 cat.png 的背景换成太空 或 参考 sketch.png 渲染成 3D 模型
智能体处理流程:
- 1. 提取图像文件路径(绝对路径或相对于当前目录的路径)
- 用转换指令增强提示词
- 上传源图像及提示词
- 监控并下载结果
图生图参数:
- - sourceImage:图像文件数组(用于本地上传)
- imageUrl:源图像的 URL
- prompt:所需转换的描述
3. 图像编辑(通用用途)
用于任何本地图像修改的通用编辑。
用户请求示例:
- - 把这张图的天空改成日落色
- 给人物加上墨镜
- 把头发颜色染成粉色
智能体处理流程:
- 1. 提取图像文件路径
- 解析具体的编辑指令(修改什么、在哪里修改)
- 构建带有精确编辑指导的增强提示词
- 使用源图像和编辑提示词调用 API
- 将结果保存到 ./tensorslab_output/
增强提示词示例:
将天空改为日落色调,带有温暖的橙色和粉色渐变,
匹配现有的光照条件和大气透视,
在地平线处无缝融合
关于头像生成、水印去除、物体擦除和面部替换场景,请参阅 references/scenarios.md。
4. 分辨率选项
支持的格式:
- - 宽高比:9:16、16:9、3:4、4:3、1:1、2:3、3:2
- 分辨率级别:2K、4K
- 特定尺寸:WxH 格式(例如 2048x2048、1920x1080)
- 约束条件:总像素数必须在 3,686,400 到 16,777,216 之间
使用脚本
直接执行 Python 脚本:
bash
文生图
python scripts/tensorslab_image.py 月球上的一只猫
指定分辨率
python scripts/tensorslab_image.py 山间日落 --resolution 16:9
图生图
python scripts/tensorslab_image.py 水彩风格 --source cat.png
指定模型
python scripts/tensorslab_image.py 赛博朋克城市 --model seedreamv45
自定义输出目录
python scripts/tensorslab
image.py 美丽风景 --output-dir ./myimages
任务状态流程
2 | 正在生成 |
| 已完成 | 3 | 完成,图像已就绪 |
| 失败 | 4 | 发生错误 |
错误处理
将 API 错误转换为用户友好提示:
| 错误代码 | 含义 | 用户提示 |
|---|
| 9000 | 积分不足 | 亲,积分用完啦,请前往 https://tensorai.tensorslab.com 充值 |
| 9999 |
一般错误 | 显示具体错误信息 |
输出
所有图像保存到输出目录,命名规则如下:
- - 默认:./tensorslaboutput/(当前工作目录)
- 自定义:使用 --output-dir 或 -o 指定不同路径
- 命名:{taskid}{index}.{ext} - 例如 abcd1234567890_0.png
完成后,通知用户:
🎉 您的图片处理完毕!已存放于 ./tensorslab_output/{filename}
资源
- - scripts/tensorslabimage.py:支持完整 CLI 功能的主 API 客户端
- references/apireference.md:详细 API 文档
- references/scenarios.md:高级使用场景(头像生成、水印去除、物体擦除、面部替换)