更新 VolcesImage 类,添加默认参数和模型类型定义
This commit is contained in:
@@ -1,3 +1,11 @@
|
|||||||
|
export const models = [
|
||||||
|
'doubao-seedream-4-0-250828',
|
||||||
|
'doubao-seedream-3-0-t2i-250415',
|
||||||
|
'doubao-seededit-3-0-i2i-250628'
|
||||||
|
] as const;
|
||||||
|
|
||||||
|
export type VolcesImageModel = (typeof models)[number];
|
||||||
|
|
||||||
export class VolcesImage {
|
export class VolcesImage {
|
||||||
apiUrl = 'https://ark.cn-beijing.volces.com/api/v3/images/generations';
|
apiUrl = 'https://ark.cn-beijing.volces.com/api/v3/images/generations';
|
||||||
apiKey: string;
|
apiKey: string;
|
||||||
@@ -7,6 +15,27 @@ export class VolcesImage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async generateImage(data: VolcesImageRequest): Promise<VolcesImageResponse> {
|
async generateImage(data: VolcesImageRequest): Promise<VolcesImageResponse> {
|
||||||
|
if (!data.model) {
|
||||||
|
data.model = models[0]; // 默认模型
|
||||||
|
}
|
||||||
|
if (data.stream === undefined) {
|
||||||
|
data.stream = false; // 默认不使用流式返回
|
||||||
|
}
|
||||||
|
if (data.response_format === undefined) {
|
||||||
|
data.response_format = 'url'; // 默认返回图片URL
|
||||||
|
}
|
||||||
|
if (data.size === undefined) {
|
||||||
|
data.size = '2K'; // 默认生成2K图片
|
||||||
|
}
|
||||||
|
if (data.watermark === undefined) {
|
||||||
|
data.watermark = false; // 默认不添加水印
|
||||||
|
}
|
||||||
|
if (data.sequential_image_generation === undefined) {
|
||||||
|
data.sequential_image_generation = 'auto'; // 默认自动处理连续图像生成
|
||||||
|
}
|
||||||
|
if (data.sequential_image_generation === 'auto' && !data.sequential_image_generation_options) {
|
||||||
|
data.sequential_image_generation_options = { max_images: 1 }; // 默认最多生成1张连续图像
|
||||||
|
}
|
||||||
const res = await fetch(this.apiUrl, {
|
const res = await fetch(this.apiUrl, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -27,6 +56,7 @@ export type VolcesImageRequest = {
|
|||||||
sequential_image_generation_options?: {
|
sequential_image_generation_options?: {
|
||||||
max_images?: number;
|
max_images?: number;
|
||||||
};
|
};
|
||||||
|
guidance_scale?: number; // 0-10,模型输出结果与prompt的一致程度,即生成图像的自由度;值越大,模型自由度越小,与用户输入的提示词相关性越强
|
||||||
response_format?: 'url' | 'base64';
|
response_format?: 'url' | 'base64';
|
||||||
size?: string; // 如 "2K"
|
size?: string; // 如 "2K"
|
||||||
stream?: boolean;
|
stream?: boolean;
|
||||||
@@ -42,4 +72,39 @@ export type VolcesImageResponse = {
|
|||||||
status: string;
|
status: string;
|
||||||
message?: string;
|
message?: string;
|
||||||
[key: string]: any;
|
[key: string]: any;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const size = [
|
||||||
|
{
|
||||||
|
name: '1:1',
|
||||||
|
value: '2048x2048'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '4:3',
|
||||||
|
value: '2304x1728'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '3:4',
|
||||||
|
value: '1728x2304'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '16:9',
|
||||||
|
value: '2560x1440'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '9:16',
|
||||||
|
value: '1440x2560'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '3:2',
|
||||||
|
value: '2496x1664'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '2:3',
|
||||||
|
value: '1664x2496'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: '21:9',
|
||||||
|
value: '3024x1296'
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user