Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions modules/tool/packages/seedream/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { defineTool } from '@tool/type';
import { FlowNodeInputTypeEnum, WorkflowIOValueTypeEnum } from '@tool/type/fastgpt';
import { ToolTypeEnum } from '@tool/type/tool';

export default defineTool({
name: {
'zh-CN': 'Seedream 4.0 绘图',
en: 'Seedream Image Generation Model'
},
courseUrl: 'https://www.volcengine.com/docs/82379/1541523',
type: ToolTypeEnum.multimodal,
description: {
'zh-CN': '豆包 Seedream 4.0 图片生成模型',
en: 'Seedream Image Generation Model'
},
toolDescription: 'Seedream 4.0 图片生成模型',
secretInputConfig: [
{
key: 'apiKey',
label: 'API Key',
description: '豆包Seedream 4.0 图片生成模型',
required: true,
inputType: 'secret'
}
],
versionList: [
{
value: '0.1.0',
description: 'Default version',
inputs: [
{
key: 'model',
label: '模型',
renderTypeList: [FlowNodeInputTypeEnum.select],
valueType: WorkflowIOValueTypeEnum.string,
description: '模型',
defaultValue: 'doubao-seedream-4-0-250828',
list: [{ label: 'Doubao-Seedream-4.0', value: 'doubao-seedream-4-0-250828' }],
required: true
},
{
key: 'prompt',
label: '提示词',
renderTypeList: [FlowNodeInputTypeEnum.input, FlowNodeInputTypeEnum.reference],
valueType: WorkflowIOValueTypeEnum.string,
description: '用于生成图像的提示词,支持中英文。',
toolDescription: '用于生成图像的提示词,支持中英文。',
required: true
},
{
key: 'size',
label: '生成图像的尺寸信息',
renderTypeList: [FlowNodeInputTypeEnum.select],
valueType: WorkflowIOValueTypeEnum.string,
description: '生成图像的尺寸信息',
defaultValue: '1:1',
list: [
{ label: '1:1', value: '2048x2048' },
{ label: '4:3', value: '2304x1728' },
{ label: '3:4', value: '1728x2304' },
{ label: '16:9', value: '2560x1440' },
{ label: '9:16', value: '1440x2560' },
{ label: '3:2', value: '2496x1664' },
{ label: '2:3', value: '1664x2496' },
{ label: '21:9', value: '3024x1296' }
],
required: false
},
{
key: 'seed',
label: '随机种子',
renderTypeList: [FlowNodeInputTypeEnum.numberInput],
valueType: WorkflowIOValueTypeEnum.number,
description: '随机数种子, 用于控制模型生成内容的随机性',
min: -1,
max: 2147483647,
defaultValue: -1,
required: false
}
],
outputs: [
{
valueType: WorkflowIOValueTypeEnum.string,
key: 'image',
label: '生成的图片链接',
description: '生成的图片链接',
required: true
}
]
}
]
});
10 changes: 10 additions & 0 deletions modules/tool/packages/seedream/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import config from './config';
import { InputType, OutputType, tool as toolCb } from './src';
import { exportTool } from '@tool/utils/tool';

export default exportTool({
toolCb,
InputType,
OutputType,
config
});
Binary file added modules/tool/packages/seedream/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions modules/tool/packages/seedream/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@fastgpt-plugins/tool-seedream",
"module": "index.ts",
"type": "module",
"scripts": {
"build": "bun ../../../../scripts/build.ts"
},
"devDependencies": {
"@types/bun": "latest"
},
"peerDependencies": {
"typescript": "^5.0.0"
},
"dependencies": {
"zod": "^3.24.2"
}
}
54 changes: 54 additions & 0 deletions modules/tool/packages/seedream/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { z } from 'zod';
import { POST } from '@tool/utils/request';

export const InputType = z.object({
apiKey: z.string().describe('Doubao Seedream API Key'),
model: z.string().nonempty().describe('model name'),
prompt: z.string().nonempty().describe('describe the desired image content'),
size: z.string().optional().describe('aspect ratio of the generated content'),
seed: z.number().optional().describe('Random seed to control the randomness of model generation')
});

export const OutputType = z.object({
image: z.string().describe('generated image URL')
});

type SeedreamResponse = {
data: {
url: string;
}[];
};

export async function tool({
apiKey,
model,
prompt,
size,
seed
}: z.infer<typeof InputType>): Promise<z.infer<typeof OutputType>> {
const url = 'https://ark.cn-beijing.volces.com/api/v3/images/generations';

const { data } = await POST<SeedreamResponse>(
url,
{
model,
prompt,
size,
seed
},
{
headers: {
Authorization: `Bearer ${apiKey}`,
'Content-Type': 'application/json'
}
}
);
const image_url = data?.data?.[0]?.url;
if (!image_url) {
return Promise.reject('Failed to generate image');
}

return {
image: image_url
};
}
8 changes: 8 additions & 0 deletions modules/tool/packages/seedream/test/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { expect, test } from 'vitest';
import tool from '..';

test(async () => {
expect(tool.name).toBeDefined();
expect(tool.description).toBeDefined();
expect(tool.cb).toBeDefined();
});