Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

✨ feat: Seedream 4.0 (#9198)

YuTengjing26a743f3bda0
diff --git a/docs/self-hosting/environment-variables/model-provider.mdx b/docs/self-hosting/environment-variables/model-provider.mdx
index 9c201218f48..adbdce62d86 100644
--- a/docs/self-hosting/environment-variables/model-provider.mdx
+++ b/docs/self-hosting/environment-variables/model-provider.mdx
@@ -646,9 +646,9 @@ If you need to use Azure OpenAI to provide model services, you can refer to the
- Type: Optional
- Description: Used to control the FAL model list. Use `+` to add a model, `-` to hide a model, and `model_name=display_name` to customize the display name of a model. Separate multiple entries with commas. The definition syntax follows the same rules as other providers' model lists.
- Default: `-`
-- Example: `-all,+flux/schnell,+flux-pro/kontext=FLUX.1 Kontext [pro]`
+- Example: `-all,+fal-ai/flux/schnell,+fal-ai/flux-pro/kontext=FLUX.1 Kontext [pro]`
-The above example disables all models first, then enables `flux/schnell` and `flux-pro/kontext` (displayed as `FLUX.1 Kontext [pro]`).
+The above example disables all models first, then enables `fal-ai/flux/schnell` and `fal-ai/flux-pro/kontext` (displayed as `FLUX.1 Kontext [pro]`).
## BFL
diff --git a/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx b/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx
index 7f53734c8cc..7691284b8d5 100644
--- a/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx
+++ b/docs/self-hosting/environment-variables/model-provider.zh-CN.mdx
@@ -645,9 +645,9 @@ LobeChat 在部署时提供了丰富的模型服务商相关的环境变量,
- 类型:可选
- 描述:用来控制 FAL 模型列表,使用 `+` 增加一个模型,使用 `-` 来隐藏一个模型,使用 `模型名=展示名` 来自定义模型的展示名,用英文逗号隔开。模型定义语法规则与其他 provider 保持一致。
- 默认值:`-`
-- 示例:`-all,+flux/schnell,+flux-pro/kontext=FLUX.1 Kontext [pro]`
+- 示例:`-all,+fal-ai/flux/schnell,+fal-ai/flux-pro/kontext=FLUX.1 Kontext [pro]`
-上述示例表示先禁用所有模型,再启用 `flux/schnell` 和 `flux-pro/kontext`(显示名为 `FLUX.1 Kontext [pro]`)。
+上述示例表示先禁用所有模型,再启用 `fal-ai/flux/schnell` 和 `fal-ai/flux-pro/kontext`(显示名为 `FLUX.1 Kontext [pro]`)。
## BFL
diff --git a/locales/zh-CN/image.json b/locales/zh-CN/image.json
index f69e30fd1f2..d7082544a87 100644
--- a/locales/zh-CN/image.json
+++ b/locales/zh-CN/image.json
@@ -5,6 +5,9 @@
"lock": "锁定宽高比",
"unlock": "解锁宽高比"
},
+ "cfg": {
+ "label": "引导强度"
+ },
"header": {
"desc": "简单描述,即刻创作",
"title": "绘画"
diff --git a/packages/model-bank/src/aiModels/fal.ts b/packages/model-bank/src/aiModels/fal.ts
index 7e1d31b14fc..e1812a7f474 100644
--- a/packages/model-bank/src/aiModels/fal.ts
+++ b/packages/model-bank/src/aiModels/fal.ts
@@ -40,11 +40,50 @@ export const qwenEditParamsSchema: ModelParamsSchema = {
};
const falImageModels: AIImageModelCard[] = [
+ {
+ description:
+ 'Nano Banana 是 Google 最新、最快、最高效的原生多模态模型,它允许您通过对话生成和编辑图像。',
+ displayName: 'Nano Banana',
+ enabled: true,
+ id: 'fal-ai/nano-banana',
+ parameters: {
+ imageUrls: { default: [], maxCount: 10 },
+ prompt: {
+ default: '',
+ },
+ },
+ pricing: {
+ units: [{ name: 'imageGeneration', rate: 0.039, strategy: 'fixed', unit: 'image' }],
+ },
+ releasedAt: '2025-08-26',
+ type: 'image',
+ },
+ {
+ description:
+ 'Seedream 4.0 图片生成模型由字节跳动 Seed 团队研发,支持文字与图片输入,提供高可控、高质量的图片生成体验。基于文本提示词生成图片。',
+ displayName: 'Seedream 4.0',
+ enabled: true,
+ id: 'fal-ai/bytedance/seedream/v4',
+ parameters: {
+ height: { default: 1024, max: 4096, min: 1024, step: 1 },
+ imageUrls: { default: [], maxCount: 10, maxFileSize: 10 * 1024 * 1024 },
+ prompt: {
+ default: '',
+ },
+ seed: { default: null },
+ width: { default: 1024, max: 4096, min: 1024, step: 1 },
+ },
+ pricing: {
+ units: [{ name: 'imageGeneration', rate: 0.03, strategy: 'fixed', unit: 'image' }],
+ },
+ releasedAt: '2025-09-09',
+ type: 'image',
+ },
{
description: '专注于图像编辑任务的FLUX.1模型,支持文本和图像输入。',
displayName: 'FLUX.1 Kontext [dev]',
enabled: true,
- id: 'flux-kontext/dev',
+ id: 'fal-ai/flux-kontext/dev',
parameters: {
imageUrl: { default: null },
prompt: { default: '' },
@@ -62,7 +101,7 @@ const falImageModels: AIImageModelCard[] = [
'FLUX.1 Kontext [pro] 能够处理文本和参考图像作为输入,无缝实现目标性的局部编辑和复杂的整体场景变换。',
displayName: 'FLUX.1 Kontext [pro]',
enabled: true,
- id: 'flux-pro/kontext',
+ id: 'fal-ai/flux-pro/kontext',
parameters: {
aspectRatio: {
default: '1:1',
@@ -82,7 +121,7 @@ const falImageModels: AIImageModelCard[] = [
description: 'FLUX.1 [schnell] 是一个具有120亿参数的图像生成模型,专注于快速生成高质量图像。',
displayName: 'FLUX.1 Schnell',
enabled: true,
- id: 'flux/schnell',
+ id: 'fal-ai/flux/schnell',
parameters: fluxSchnellParamsSchema,
pricing: {
units: [{ name: 'imageGeneration', rate: 0.003, strategy: 'fixed', unit: 'megapixel' }],
@@ -94,7 +133,7 @@ const falImageModels: AIImageModelCard[] = [
description: 'Flux Krea [dev] 是一个有美学偏好的图像生成模型,目标是生成更加真实、自然的图像。',
displayName: 'FLUX.1 Krea [dev]',
enabled: true,
- id: 'flux/krea',
+ id: 'fal-ai/flux/krea',
parameters: fluxKreaParamsSchema,
pricing: {
units: [{ name: 'imageGeneration', rate: 0.025, strategy: 'fixed', unit: 'megapixel' }],
@@ -106,7 +145,7 @@ const falImageModels: AIImageModelCard[] = [
description: 'Google 提供的高质量的图像生成模型',
displayName: 'Imagen 4',
enabled: true,
- id: 'imagen4/preview',
+ id: 'fal-ai/imagen4/preview',
organization: 'Deepmind',
parameters: {
aspectRatio: {
@@ -127,7 +166,7 @@ const falImageModels: AIImageModelCard[] = [
'Qwen 团队发布的专业图像编辑模型,支持语义编辑和外观编辑,能够精确编辑中英文文字,实现风格转换、对象旋转等高质量图像编辑。',
displayName: 'Qwen Edit',
enabled: true,
- id: 'qwen-image-edit',
+ id: 'fal-ai/qwen-image-edit',
parameters: qwenEditParamsSchema,
pricing: {
units: [{ name: 'imageGeneration', rate: 0.025, strategy: 'fixed', unit: 'image' }],
@@ -140,7 +179,7 @@ const falImageModels: AIImageModelCard[] = [
'Qwen 团队带来的强大生图模型,具有令人印象深刻的中文文字生成能力和多样图片视觉风格。',
displayName: 'Qwen Image',
enabled: true,
- id: 'qwen-image',
+ id: 'fal-ai/qwen-image',
parameters: qwenImageParamsSchema,
pricing: {
units: [{ name: 'imageGeneration', rate: 0.02, strategy: 'fixed', unit: 'megapixel' }],
diff --git a/packages/model-bank/src/aiModels/volcengine.ts b/packages/model-bank/src/aiModels/volcengine.ts
index 9036cde4239..7746e46225d 100644
--- a/packages/model-bank/src/aiModels/volcengine.ts
+++ b/packages/model-bank/src/aiModels/volcengine.ts
@@ -74,8 +74,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 0.8,
- '[32_000, 128_000]': 2.4,
'[128_000, infinity]': 4.8,
+ '[32_000, 128_000]': 2.4,
},
pricingParams: ['textInputRange'],
},
@@ -87,8 +87,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 8,
- '[32_000, 128_000]': 16,
'[128_000, infinity]': 24,
+ '[32_000, 128_000]': 16,
},
pricingParams: ['textInputRange'],
},
@@ -127,8 +127,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 0.8,
- '[32_000, 128_000]': 1.2,
'[128_000, infinity]': 2.4,
+ '[32_000, 128_000]': 1.2,
},
pricingParams: ['textInputRange'],
},
@@ -140,8 +140,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 8,
- '[32_000, 128_000]': 16,
'[128_000, infinity]': 24,
+ '[32_000, 128_000]': 16,
},
pricingParams: ['textInputRange'],
},
@@ -177,8 +177,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 0.8,
- '[32_000, 128_000]': 1.2,
'[128_000, infinity]': 2.4,
+ '[32_000, 128_000]': 1.2,
},
pricingParams: ['textInputRange'],
},
@@ -191,8 +191,8 @@ const doubaoChatModels: AIChatModelCard[] = [
prices: {
'[0, 32_000]_[0, 8192]': 2,
'[0, 32_000]_[8192, infinity]': 8,
- '[32_000, 128_000]_[0, infinity]': 16,
'[128_000, infinity]_[0, infinity]': 24,
+ '[32_000, 128_000]_[0, infinity]': 16,
},
pricingParams: ['textInputRange', 'textOutputRange'],
},
@@ -231,8 +231,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 0.15,
- '[32_000, 128_000]': 0.3,
'[128_000, infinity]': 0.6,
+ '[32_000, 128_000]': 0.3,
},
pricingParams: ['textInputRange'],
},
@@ -244,8 +244,8 @@ const doubaoChatModels: AIChatModelCard[] = [
lookup: {
prices: {
'[0, 32_000]': 1.5,
- '[32_000, 128_000]': 3,
'[128_000, infinity]': 6,
+ '[32_000, 128_000]': 3,
},
pricingParams: ['textInputRange'],
},
@@ -742,11 +742,46 @@ const volcengineImageModels: AIImageModelCard[] = [
},
*/
description:
- 'Doubao图片生成模型由字节跳动 Seed 团队研发,支持文字与图片输入,提供高可控、高质量的图片生成体验。基于文本提示词生成图片。',
- displayName: 'Doubao Seedream 3.0 t2i',
+ 'Seedream 4.0 图片生成模型由字节跳动 Seed 团队研发,支持文字与图片输入,提供高可控、高质量的图片生成体验。基于文本提示词生成图片。',
+ displayName: 'Seedream 4.0',
+ enabled: true,
+ id: 'doubao-seedream-4-0-250828',
+ parameters: {
+ imageUrls: { default: [], maxCount: 10, maxFileSize: 10 * 1024 * 1024 },
+ prompt: {
+ default: '',
+ },
+ size: {
+ default: '1024x1024',
+ enum: [
+ '2048x2048',
+ '2304x1728',
+ '1728x2304',
+ '2560x1440',
+ '1440x2560',
+ '2496x1664',
+ '1664x2496',
+ '3024x1296',
+ ],
+ },
+ },
+ releasedAt: '2025-09-09',
+ type: 'image',
+ },
+ {
+ /*
+ // TODO: AIImageModelCard 不支持 config.deploymentName
+ config: {
+ deploymentName: 'doubao-seedream-3-0-t2i-250415',
+ },
+ */
+ description:
+ 'Seedream 3.0 图片生成模型由字节跳动 Seed 团队研发,支持文字与图片输入,提供高可控、高质量的图片生成体验。基于文本提示词生成图片。',
+ displayName: 'Seedream 3.0 文生图',
enabled: true,
id: 'doubao-seedream-3-0-t2i-250415',
parameters: {
+ cfg: { default: 2.5, max: 10, min: 1, step: 0.1 },
prompt: {
default: '',
},
@@ -768,32 +803,27 @@ const volcengineImageModels: AIImageModelCard[] = [
releasedAt: '2025-04-15',
type: 'image',
},
- /*
// Note: Doubao 图生图模型与文生图模型公用一个 Endpoint,当前如果存在 imageUrl 会切换至 edit endpoint 下
{
- config: {
- deploymentName: 'doubao-seededit-3-0-i2i-250628',
- },
+ // config: {
+ // deploymentName: 'doubao-seededit-3-0-i2i-250628',
+ // },
description:
'Doubao图片生成模型由字节跳动 Seed 团队研发,支持文字与图片输入,提供高可控、高质量的图片生成体验。支持通过文本指令编辑图像,生成图像的边长在512~1536之间。',
- displayName: 'Doubao SeedEdit 3.0 i2i',
+ displayName: 'SeedEdit 3.0 图生图',
enabled: true,
id: 'doubao-seededit-3-0-i2i-250628',
parameters: {
- imageUrl: { default: null },
+ cfg: { default: 5.5, max: 10, min: 1, step: 0.1 },
+ imageUrl: { default: null, maxFileSize: 10 * 1024 * 1024 },
prompt: {
default: '',
},
seed: { default: null },
- size: {
- default: '1024x1024',
- enum: ['1024x1024', '864x1152', '1152x864', '1280x720', '720x1280', '832x1248', '1248x832', '1512x648'],
- },
},
releasedAt: '2025-06-28',
type: 'image',
},
- */
];
export const allModels = [...doubaoChatModels, ...volcengineImageModels];
diff --git a/packages/model-bank/src/standard-parameters/index.ts b/packages/model-bank/src/standard-parameters/index.ts
index 5e12c187e55..1afd2661513 100644
--- a/packages/model-bank/src/standard-parameters/index.ts
+++ b/packages/model-bank/src/standard-parameters/index.ts
@@ -98,6 +98,9 @@ export const ModelParamsMetaSchema = z.object({
default: z.array(z.string()),
description: z.string().optional(),
maxCount: z.number().optional(),
+ /**
+ * The maximum file size in bytes
+ */
maxFileSize: z.number().optional(),
type: z.literal('array').optional(),
})
diff --git a/packages/model-runtime/src/fal/index.test.ts b/packages/model-runtime/src/fal/index.test.ts
index 6e0c9ef0426..a9dd6c98669 100644
--- a/packages/model-runtime/src/fal/index.test.ts
+++ b/packages/model-runtime/src/fal/index.test.ts
@@ -153,6 +153,44 @@ describe('LobeFalAI', () => {
});
});
+ it('should map imageUrls parameter to image_urls', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/image.jpg',
+ width: 512,
+ height: 512,
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'flux/dev',
+ params: {
+ prompt: 'Test with multiple images',
+ imageUrls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ },
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/flux/dev', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Test with multiple images',
+ image_urls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ },
+ });
+ });
+
it('should handle parameters without width and height', async () => {
// Arrange
const mockImageResponse = {
@@ -326,6 +364,342 @@ describe('LobeFalAI', () => {
});
});
+ describe('Parameter filtering', () => {
+ it('should filter out null values', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/image.jpg',
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'flux/dev',
+ params: {
+ prompt: 'Test with null values',
+ imageUrl: null,
+ steps: null,
+ cfg: 7.5,
+ } as any,
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/flux/dev', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Test with null values',
+ guidance_scale: 7.5,
+ },
+ });
+ });
+
+ it('should filter out undefined values', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/image.jpg',
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'flux/dev',
+ params: {
+ prompt: 'Test with undefined values',
+ imageUrl: undefined,
+ steps: undefined,
+ cfg: 5.0,
+ } as any,
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/flux/dev', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Test with undefined values',
+ guidance_scale: 5.0,
+ },
+ });
+ });
+
+ it('should filter out empty arrays', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/image.jpg',
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'flux/dev',
+ params: {
+ prompt: 'Test with empty arrays',
+ imageUrls: [],
+ steps: 20,
+ } as any,
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/flux/dev', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Test with empty arrays',
+ num_inference_steps: 20,
+ },
+ });
+ });
+ });
+
+ describe('Seedream v4 special endpoints', () => {
+ it('should use text-to-image endpoint when no imageUrls provided', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/generated.jpg',
+ width: 1024,
+ height: 1024,
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'bytedance/seedream/v4',
+ params: {
+ prompt: 'A beautiful landscape',
+ width: 1024,
+ height: 1024,
+ },
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith(
+ 'fal-ai/bytedance/seedream/v4/text-to-image',
+ {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'A beautiful landscape',
+ image_size: {
+ width: 1024,
+ height: 1024,
+ },
+ },
+ },
+ );
+ });
+
+ it('should use edit endpoint when imageUrls is provided', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/edited.jpg',
+ width: 1024,
+ height: 1024,
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'bytedance/seedream/v4',
+ params: {
+ prompt: 'Edit this image to add a sunset',
+ imageUrls: ['https://example.com/input.jpg'],
+ width: 1024,
+ height: 1024,
+ },
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/bytedance/seedream/v4/edit', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Edit this image to add a sunset',
+ image_urls: ['https://example.com/input.jpg'],
+ image_size: {
+ width: 1024,
+ height: 1024,
+ },
+ },
+ });
+ });
+
+ it('should use edit endpoint when multiple imageUrls are provided', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/edited.jpg',
+ width: 1024,
+ height: 1024,
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'bytedance/seedream/v4',
+ params: {
+ prompt: 'Combine these images',
+ imageUrls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ width: 1024,
+ height: 1024,
+ },
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/bytedance/seedream/v4/edit', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Combine these images',
+ image_urls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ image_size: {
+ width: 1024,
+ height: 1024,
+ },
+ },
+ });
+ });
+
+ it('should use text-to-image endpoint when imageUrls is empty array', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/generated.jpg',
+ width: 1024,
+ height: 1024,
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'bytedance/seedream/v4',
+ params: {
+ prompt: 'Generate new image',
+ imageUrls: [],
+ width: 1024,
+ height: 1024,
+ } as any,
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith(
+ 'fal-ai/bytedance/seedream/v4/text-to-image',
+ {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Generate new image',
+ image_size: {
+ width: 1024,
+ height: 1024,
+ },
+ },
+ },
+ );
+ });
+
+ it('should handle seedream v4 with other parameters', async () => {
+ // Arrange
+ const mockImageResponse = {
+ requestId: 'test-request-id',
+ data: {
+ images: [
+ {
+ url: 'https://example.com/edited.jpg',
+ },
+ ],
+ },
+ };
+ mockFal.subscribe.mockResolvedValue(mockImageResponse as any);
+
+ const payload: CreateImagePayload = {
+ model: 'bytedance/seedream/v4',
+ params: {
+ prompt: 'Edit with custom settings',
+ imageUrls: ['https://example.com/input.jpg'],
+ steps: 30,
+ cfg: 8.0,
+ },
+ };
+
+ // Act
+ await instance.createImage(payload);
+
+ // Assert
+ expect(mockFal.subscribe).toHaveBeenCalledWith('fal-ai/bytedance/seedream/v4/edit', {
+ input: {
+ enable_safety_checker: false,
+ num_images: 1,
+ prompt: 'Edit with custom settings',
+ image_urls: ['https://example.com/input.jpg'],
+ num_inference_steps: 30,
+ guidance_scale: 8.0,
+ },
+ });
+ });
+ });
+
describe('Edge cases', () => {
it('should handle empty params object', async () => {
// Arrange
diff --git a/packages/model-runtime/src/fal/index.ts b/packages/model-runtime/src/fal/index.ts
index 9bf7e4b9615..1915bd90e2f 100644
--- a/packages/model-runtime/src/fal/index.ts
+++ b/packages/model-runtime/src/fal/index.ts
@@ -32,6 +32,7 @@ export class LobeFalAI implements LobeRuntimeAI {
['steps', 'num_inference_steps'],
['cfg', 'guidance_scale'],
['imageUrl', 'image_url'],
+ ['imageUrls', 'image_urls'],
]);
const defaultInput: Record<string, unknown> = {
@@ -39,10 +40,13 @@ export class LobeFalAI implements LobeRuntimeAI {
num_images: 1,
};
const userInput: Record<string, unknown> = Object.fromEntries(
- (Object.entries(params) as [keyof typeof params, any][]).map(([key, value]) => [
- paramsMap.get(key) ?? key,
- value,
- ]),
+ (Object.entries(params) as [keyof typeof params, any][])
+ .filter(([, value]) => {
+ const isEmptyValue =
+ value === null || value === undefined || (Array.isArray(value) && value.length === 0);
+ return !isEmptyValue;
+ })
+ .map(([key, value]) => [paramsMap.get(key) ?? key, value]),
);
if ('width' in userInput && 'height' in userInput) {
@@ -57,31 +61,36 @@ export class LobeFalAI implements LobeRuntimeAI {
const modelsAcceleratedByDefault = new Set<string>(['flux/krea']);
if (modelsAcceleratedByDefault.has(model)) {
defaultInput['acceleration'] = 'high';
- log('Applied default acceleration=high for model: %s', model);
}
- const endpoint = `fal-ai/${model}`;
- log('Calling fal.subscribe with endpoint: %s and input: %O', endpoint, {
+ // Ensure model has fal-ai/ prefix
+ let endpoint = model.startsWith('fal-ai/') ? model : `fal-ai/${model}`;
+ const hasImageUrls = (params.imageUrls?.length ?? 0) > 0;
+ if (endpoint === 'fal-ai/bytedance/seedream/v4') {
+ endpoint += hasImageUrls ? '/edit' : '/text-to-image';
+ } else if (endpoint === 'fal-ai/nano-banana' && hasImageUrls) {
+ endpoint += '/edit';
+ }
+
+ const finalInput = {
...defaultInput,
...userInput,
- });
+ };
+ log('Calling fal.subscribe with endpoint: %s and input: %O', endpoint, finalInput);
try {
const { data } = await fal.subscribe(endpoint, {
- input: {
- ...defaultInput,
- ...userInput,
- },
+ input: finalInput,
});
const image = (data as FluxDevOutput).images[0];
- log('Received image data: %O', image);
return {
imageUrl: image.url,
...pick(image, ['width', 'height']),
};
} catch (error) {
- if (error instanceof Error && 'status' in error && (error as any).status === 401) {
+ // https://docs.fal.ai/model-apis/errors/
+ if (error instanceof Error && 'status' in error && error.status === 401) {
throw AgentRuntimeError.createError(AgentRuntimeErrorType.InvalidProviderAPIKey, {
error,
});
diff --git a/packages/model-runtime/src/volcengine/createImage.test.ts b/packages/model-runtime/src/volcengine/createImage.test.ts
new file mode 100644
index 00000000000..22cf8e8aa29
--- /dev/null
+++ b/packages/model-runtime/src/volcengine/createImage.test.ts
@@ -0,0 +1,522 @@
+import { beforeEach, describe, expect, it, vi } from 'vitest';
+
+import { CreateImagePayload } from '../types/image';
+import { CreateImageOptions } from '../utils/openaiCompatibleFactory';
+import { createVolcengineImage } from './createImage';
+
+// Mock dependencies
+vi.mock('debug', () => ({
+ default: vi.fn(() => vi.fn()),
+}));
+
+const mockGenerate = vi.fn();
+vi.mock('openai', () => ({
+ default: vi.fn().mockImplementation(() => ({
+ images: {
+ generate: mockGenerate,
+ },
+ })),
+}));
+
+describe('createVolcengineImage', () => {
+ let payload: CreateImagePayload;
+ let options: CreateImageOptions;
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+
+ // Default test payload and options
+ payload = {
+ model: 'doubao-seedream-3-0-t2i',
+ params: {
+ prompt: 'a beautiful landscape',
+ },
+ };
+
+ options = {
+ apiKey: 'test-api-key',
+ provider: 'volcengine',
+ };
+ });
+
+ describe('successful image generation', () => {
+ it('should generate image with URL response format', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/generated-image.jpg',
+ size: '1024x768',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result).toEqual({
+ imageUrl: 'https://example.com/generated-image.jpg',
+ width: 1024,
+ height: 768,
+ });
+ });
+
+ it('should generate image with base64 response format', async () => {
+ const mockBase64 =
+ 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNkYPhfDwAChwGA60e6kgAAAABJRU5ErkJggg==';
+ const mockResponse = {
+ data: [
+ {
+ b64_json: mockBase64,
+ size: '512x512',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result).toEqual({
+ imageUrl: `data:image/jpeg;base64,${mockBase64}`,
+ width: 512,
+ height: 512,
+ });
+ });
+
+ it('should handle response without size information', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/generated-image.jpg',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result).toEqual({
+ imageUrl: 'https://example.com/generated-image.jpg',
+ width: undefined,
+ height: undefined,
+ });
+ });
+ });
+
+ describe('parameter mapping', () => {
+ it('should map cfg parameter to guidance_scale', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ cfg: 7.5,
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ guidance_scale: 7.5,
+ });
+ });
+
+ it('should map imageUrls parameter to image', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ image: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ });
+ });
+
+ it('should map imageUrl parameter to image', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrl: 'https://example.com/input.jpg',
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ image: 'https://example.com/input.jpg',
+ });
+ });
+
+ it('should preserve unmapped parameters', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ seed: 12345,
+ size: '1024x1024',
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ seed: 12345,
+ size: '1024x1024',
+ });
+ });
+ });
+
+ describe('image input handling', () => {
+ it('should preserve image input when array has items', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrls: ['https://example.com/input.jpg'],
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ image: ['https://example.com/input.jpg'],
+ }),
+ );
+ });
+
+ it('should remove image input when array is empty', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrls: [],
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ });
+ });
+
+ it('should remove image input when value is null', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrl: null,
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ });
+ });
+
+ it('should remove image input when value is undefined', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'test prompt',
+ imageUrl: undefined,
+ };
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'test prompt',
+ });
+ });
+ });
+
+ describe('client configuration', () => {
+ it('should use provided baseURL when specified', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ options.baseURL = 'https://custom-endpoint.com/api/v1';
+
+ await createVolcengineImage(payload, options);
+
+ // Verify OpenAI constructor was called with custom baseURL
+ const OpenAI = await import('openai');
+ expect(OpenAI.default).toHaveBeenCalledWith({
+ apiKey: 'test-api-key',
+ baseURL: 'https://custom-endpoint.com/api/v1',
+ });
+ });
+
+ it('should use default baseURL when not provided', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ await createVolcengineImage(payload, options);
+
+ // Verify OpenAI constructor was called with default baseURL
+ const OpenAI = await import('openai');
+ expect(OpenAI.default).toHaveBeenCalledWith({
+ apiKey: 'test-api-key',
+ baseURL: 'https://ark.cn-beijing.volces.com/api/v3',
+ });
+ });
+
+ it('should set watermark to false by default', async () => {
+ const mockResponse = {
+ data: [{ url: 'https://example.com/test.jpg' }],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith(
+ expect.objectContaining({
+ watermark: false,
+ }),
+ );
+ });
+ });
+
+ describe('size extraction', () => {
+ it('should extract dimensions from size string format', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/test.jpg',
+ size: '1920x1080',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result.width).toBe(1920);
+ expect(result.height).toBe(1080);
+ });
+
+ it('should handle malformed size string', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/test.jpg',
+ size: 'invalid-size-format',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result.width).toBeUndefined();
+ expect(result.height).toBeUndefined();
+ });
+
+ it('should handle missing size property', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/test.jpg',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result.width).toBeUndefined();
+ expect(result.height).toBeUndefined();
+ });
+ });
+
+ describe('error handling', () => {
+ it('should throw error when response is null', async () => {
+ mockGenerate.mockResolvedValue(null);
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing or empty data array',
+ );
+ });
+
+ it('should throw error when response.data is missing', async () => {
+ mockGenerate.mockResolvedValue({});
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing or empty data array',
+ );
+ });
+
+ it('should throw error when response.data is not an array', async () => {
+ mockGenerate.mockResolvedValue({
+ data: 'not-an-array',
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing or empty data array',
+ );
+ });
+
+ it('should throw error when response.data is empty array', async () => {
+ mockGenerate.mockResolvedValue({
+ data: [],
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing or empty data array',
+ );
+ });
+
+ it('should throw error when first data item is null', async () => {
+ mockGenerate.mockResolvedValue({
+ data: [null],
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: first data item is null or undefined',
+ );
+ });
+
+ it('should throw error when first data item is undefined', async () => {
+ mockGenerate.mockResolvedValue({
+ data: [undefined],
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: first data item is null or undefined',
+ );
+ });
+
+ it('should throw error when image data has neither url nor b64_json', async () => {
+ mockGenerate.mockResolvedValue({
+ data: [
+ {
+ // Missing both url and b64_json
+ metadata: 'some-metadata',
+ },
+ ],
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing both b64_json and url fields',
+ );
+ });
+
+ it('should throw error when image data has empty url and no b64_json', async () => {
+ mockGenerate.mockResolvedValue({
+ data: [
+ {
+ url: '',
+ // No b64_json field
+ },
+ ],
+ });
+
+ await expect(createVolcengineImage(payload, options)).rejects.toThrow(
+ 'Invalid response: missing both b64_json and url fields',
+ );
+ });
+ });
+
+ describe('complex scenarios', () => {
+ it('should handle all parameter mappings together', async () => {
+ const mockResponse = {
+ data: [
+ {
+ b64_json: 'mock-base64-data',
+ size: '2048x1536',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ payload.params = {
+ prompt: 'complex test prompt',
+ cfg: 5.5,
+ imageUrls: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ seed: 42,
+ size: '1024x1024',
+ };
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(mockGenerate).toHaveBeenCalledWith({
+ model: 'doubao-seedream-3-0-t2i',
+ watermark: false,
+ prompt: 'complex test prompt',
+ guidance_scale: 5.5,
+ image: ['https://example.com/input1.jpg', 'https://example.com/input2.jpg'],
+ seed: 42,
+ size: '1024x1024',
+ });
+
+ expect(result).toEqual({
+ imageUrl: 'data:image/jpeg;base64,mock-base64-data',
+ width: 2048,
+ height: 1536,
+ });
+ });
+
+ it('should prioritize b64_json over url when both are present', async () => {
+ const mockResponse = {
+ data: [
+ {
+ url: 'https://example.com/should-be-ignored.jpg',
+ b64_json: 'base64-data-should-be-used',
+ size: '800x600',
+ },
+ ],
+ };
+ mockGenerate.mockResolvedValue(mockResponse);
+
+ const result = await createVolcengineImage(payload, options);
+
+ expect(result.imageUrl).toBe('data:image/jpeg;base64,base64-data-should-be-used');
+ });
+ });
+});
diff --git a/packages/model-runtime/src/volcengine/createImage.ts b/packages/model-runtime/src/volcengine/createImage.ts
new file mode 100644
index 00000000000..8f6acb74516
--- /dev/null
+++ b/packages/model-runtime/src/volcengine/createImage.ts
@@ -0,0 +1,118 @@
+import createDebug from 'debug';
+import { RuntimeImageGenParamsValue } from 'model-bank';
+import OpenAI from 'openai';
+
+import { CreateImagePayload, CreateImageResponse } from '../types/image';
+import { CreateImageOptions } from '../utils/openaiCompatibleFactory';
+
+const log = createDebug('lobe-image:volcengine');
+
+/**
+ * Volcengine image generation implementation
+ * Based on Volcengine API docs: https://www.volcengine.com/docs/82379/1541523
+ */
+export async function createVolcengineImage(
+ payload: CreateImagePayload,
+ options: CreateImageOptions,
+): Promise<CreateImageResponse> {
+ const { model, params } = payload;
+
+ log('Creating image with Volcengine API - model: %s, params: %O', model, params);
+
+ // Create OpenAI client with Volcengine configuration
+ const client = new OpenAI({
+ apiKey: options.apiKey,
+ baseURL: options.baseURL || 'https://ark.cn-beijing.volces.com/api/v3',
+ });
+
+ // Parameter mapping: imageUrls/imageUrl -> image, cfg -> guidance_scale
+ const paramsMap = new Map<RuntimeImageGenParamsValue, string>([
+ ['imageUrls', 'image'],
+ ['imageUrl', 'image'],
+ ['cfg', 'guidance_scale'],
+ ]);
+
+ const userInput: Record<string, any> = Object.fromEntries(
+ Object.entries(params).map(([key, value]) => [
+ paramsMap.get(key as RuntimeImageGenParamsValue) ?? key,
+ value,
+ ]),
+ );
+
+ // Volcengine supports direct URL or base64, no need to convert to File objects
+ // Check if there is image input
+ const hasImageInput =
+ userInput.image !== null &&
+ userInput.image !== undefined &&
+ (Array.isArray(userInput.image) ? userInput.image.length > 0 : true);
+
+ if (hasImageInput) {
+ log('Image input detected: %O', userInput.image);
+ } else {
+ delete userInput.image;
+ }
+
+ // Build request options
+ const requestOptions = {
+ model,
+ watermark: false, // Default to no watermark
+ ...userInput,
+ };
+
+ log('Volcengine API options: %O', requestOptions);
+
+ // Call Volcengine image generation API
+ const response = await client.images.generate(requestOptions as any);
+
+ log('Volcengine API response: %O', response);
+
+ // Validate response data
+ if (!response || !response.data || !Array.isArray(response.data) || response.data.length === 0) {
+ log('Invalid response: missing data array');
+ throw new Error('Invalid response: missing or empty data array');
+ }
+
+ const imageData = response.data[0];
+ if (!imageData) {
+ log('Invalid response: first data item is null/undefined');
+ throw new Error('Invalid response: first data item is null or undefined');
+ }
+
+ let imageUrl: string;
+ let width: number | undefined;
+ let height: number | undefined;
+
+ // Handle base64 format response
+ if (imageData.b64_json) {
+ const mimeType = 'image/jpeg'; // Volcengine defaults to JPEG format
+ imageUrl = `data:${mimeType};base64,${imageData.b64_json}`;
+ log('Successfully converted base64 to data URL, length: %d', imageUrl.length);
+ }
+ // Handle URL format response
+ else if (imageData.url) {
+ imageUrl = imageData.url;
+ log('Using direct image URL: %s', imageUrl);
+ }
+ // If neither format exists, throw error
+ else {
+ log('Invalid response: missing both b64_json and url fields');
+ throw new Error('Invalid response: missing both b64_json and url fields');
+ }
+
+ // Extract size information (Volcengine specific)
+ const volcengineImageData = imageData as any;
+ if (volcengineImageData.size) {
+ const sizeMatch = volcengineImageData.size.match(/^(\d+)x(\d+)$/);
+ if (sizeMatch) {
+ width = parseInt(sizeMatch[1], 10);
+ height = parseInt(sizeMatch[2], 10);
+ log('Extracted image dimensions: %dx%d', width, height);
+ }
+ }
+
+ return {
+ height,
+ imageUrl,
+ width,
+ };
+}
diff --git a/packages/model-runtime/src/volcengine/index.ts b/packages/model-runtime/src/volcengine/index.ts
index 1f04a848618..57a19fb821b 100644
--- a/packages/model-runtime/src/volcengine/index.ts
+++ b/packages/model-runtime/src/volcengine/index.ts
@@ -1,6 +1,7 @@
import { ModelProvider } from '../types';
import { MODEL_LIST_CONFIGS, processModelList } from '../utils/modelParse';
import { createOpenAICompatibleRuntime } from '../utils/openaiCompatibleFactory';
+import { createVolcengineImage } from './createImage';
const THINKING_MODELS = [
'thinking-vision-pro',
@@ -31,6 +32,7 @@ export const LobeVolcengineAI = createOpenAICompatibleRuntime({
} as any;
},
},
+ createImage: createVolcengineImage,
debug: {
chatCompletion: () => process.env.DEBUG_VOLCENGINE_CHAT_COMPLETION === '1',
},
diff --git a/packages/utils/src/parseModels.test.ts b/packages/utils/src/parseModels.test.ts
index f785e768549..cfd738cd128 100644
--- a/packages/utils/src/parseModels.test.ts
+++ b/packages/utils/src/parseModels.test.ts
@@ -323,29 +323,29 @@ describe('parseModelString', () => {
it('should correctly parse FAL image model ids with slash and custom display names', async () => {
const result = await parseModelString(
'fal',
- '-all,+flux-kontext/dev=KontextDev,+flux-pro/kontext=KontextPro,+flux/schnell=Schnell,+imagen4/preview=Imagen4',
+ '-all,+fal-ai/flux-kontext/dev=KontextDev,+fal-ai/flux-pro/kontext=KontextPro,+fal-ai/flux/schnell=Schnell,+fal-ai/imagen4/preview=Imagen4',
);
expect(result.add).toEqual([
{
- id: 'flux-kontext/dev',
+ id: 'fal-ai/flux-kontext/dev',
displayName: 'KontextDev',
abilities: {},
type: 'image',
},
{
- id: 'flux-pro/kontext',
+ id: 'fal-ai/flux-pro/kontext',
displayName: 'KontextPro',
abilities: {},
type: 'image',
},
{
- id: 'flux/schnell',
+ id: 'fal-ai/flux/schnell',
displayName: 'Schnell',
abilities: {},
type: 'image',
},
{
- id: 'imagen4/preview',
+ id: 'fal-ai/imagen4/preview',
displayName: 'Imagen4',
abilities: {},
type: 'image',
@@ -356,15 +356,18 @@ describe('parseModelString', () => {
});
it('should correctly parse FAL image model ids with slash (no displayName)', async () => {
- const result = await parseModelString('fal', '-all,+flux-kontext/dev,+flux-pro/kontext');
+ const result = await parseModelString(
+ 'fal',
+ '-all,+fal-ai/flux-kontext/dev,+fal-ai/flux-pro/kontext',
+ );
expect(result.add).toEqual([
{
- id: 'flux-kontext/dev',
+ id: 'fal-ai/flux-kontext/dev',
abilities: {},
type: 'image',
},
{
- id: 'flux-pro/kontext',
+ id: 'fal-ai/flux-pro/kontext',
abilities: {},
type: 'image',
},
diff --git a/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/CfgSliderInput.tsx b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/CfgSliderInput.tsx
new file mode 100644
index 00000000000..48adefd45fc
--- /dev/null
+++ b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/CfgSliderInput.tsx
@@ -0,0 +1,11 @@
+import { SliderWithInput } from '@lobehub/ui';
+import { memo } from 'react';
+
+import { useGenerationConfigParam } from '@/store/image/slices/generationConfig/hooks';
+
+const CfgSliderInput = memo(() => {
+ const { value, setValue, min, max } = useGenerationConfigParam('cfg');
+ return <SliderWithInput max={max} min={min} onChange={setValue} value={value} />;
+});
+
+export default CfgSliderInput;
diff --git a/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/StepsSliderInput.tsx b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/StepsSliderInput.tsx
index 1972b693bc7..4b342c42c09 100644
--- a/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/StepsSliderInput.tsx
+++ b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/components/StepsSliderInput.tsx
@@ -3,9 +3,9 @@ import { memo } from 'react';
import { useGenerationConfigParam } from '@/store/image/slices/generationConfig/hooks';
-const SizeSliderInput = memo(() => {
+const StepsSliderInput = memo(() => {
const { value, setValue, min, max } = useGenerationConfigParam('steps');
return <SliderWithInput max={max} min={min} onChange={setValue} value={value} />;
});
-export default SizeSliderInput;
+export default StepsSliderInput;
diff --git a/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx
index e48f2bbcf93..1d68fe0cae3 100644
--- a/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx
+++ b/src/app/[variants]/(main)/image/@menu/features/ConfigPanel/index.tsx
@@ -11,6 +11,7 @@ import { imageGenerationConfigSelectors } from '@/store/image/selectors';
import { useDimensionControl } from '@/store/image/slices/generationConfig/hooks';
import { useImageStore } from '@/store/image/store';
+import CfgSliderInput from './components/CfgSliderInput';
import DimensionControlGroup from './components/DimensionControlGroup';
import ImageConfigSkeleton from './components/ImageConfigSkeleton';
import ImageNum from './components/ImageNum';
@@ -53,6 +54,7 @@ const ConfigPanel = memo(() => {
const isSupportSize = useImageStore(isSupportedParamSelector('size'));
const isSupportSeed = useImageStore(isSupportedParamSelector('seed'));
const isSupportSteps = useImageStore(isSupportedParamSelector('steps'));
+ const isSupportCfg = useImageStore(isSupportedParamSelector('cfg'));
const isSupportImageUrls = useImageStore(isSupportedParamSelector('imageUrls'));
const { showDimensionControl } = useDimensionControl();
@@ -75,6 +77,7 @@ const ConfigPanel = memo(() => {
isSupportSize,
isSupportSeed,
isSupportSteps,
+ isSupportCfg,
isSupportImageUrls,
showDimensionControl,
]);
@@ -164,6 +167,12 @@ const ConfigPanel = memo(() => {
</ConfigItemLayout>
)}
+ {isSupportCfg && (
+ <ConfigItemLayout label={t('config.cfg.label')}>
+ <CfgSliderInput />
+ </ConfigItemLayout>
+ )}
+
{isSupportSeed && (
<ConfigItemLayout label={t('config.seed.label')}>
<SeedNumberInput />
diff --git a/src/locales/default/image.ts b/src/locales/default/image.ts
index 8fe35ca5957..4935cb0410c 100644
--- a/src/locales/default/image.ts
+++ b/src/locales/default/image.ts
@@ -5,6 +5,9 @@ export default {
lock: '锁定宽高比',
unlock: '解锁宽高比',
},
+ cfg: {
+ label: '引导强度',
+ },
header: {
desc: '简单描述,即刻创作',
title: '绘画',
diff --git a/src/server/routers/async/image.ts b/src/server/routers/async/image.ts
index 89396660cb1..0e31c5af021 100644
--- a/src/server/routers/async/image.ts
+++ b/src/server/routers/async/image.ts
@@ -112,7 +112,12 @@ export const imageRouter = router({
log('Starting async image generation: %O', {
generationId,
- imageParams: { height: params.height, steps: params.steps, width: params.width },
+ imageParams: {
+ cfg: params.cfg,
+ height: params.height,
+ steps: params.steps,
+ width: params.width,
+ },
model,
prompt: params.prompt,
provider,