1
This commit is contained in:
parent
4e3365d9d5
commit
af4abb772e
@ -257,6 +257,9 @@ export async function uploadFile(
|
|||||||
export function checkResult(result: AxiosResponse) {
|
export function checkResult(result: AxiosResponse) {
|
||||||
const { ret, errmsg, data } = result.data;
|
const { ret, errmsg, data } = result.data;
|
||||||
if (!_.isFinite(Number(ret))) return result.data;
|
if (!_.isFinite(Number(ret))) return result.data;
|
||||||
|
if (ret !== '0') {
|
||||||
|
logger.error(`[Jimeng API Error] ret=${ret}, errmsg=${errmsg}, data=${JSON.stringify(data)}`);
|
||||||
|
}
|
||||||
if (ret === '0') return data;
|
if (ret === '0') return data;
|
||||||
if (ret === '5000')
|
if (ret === '5000')
|
||||||
throw new APIException(EX.API_IMAGE_GENERATION_INSUFFICIENT_POINTS, `[无法生成图像]: 即梦积分可能不足,${errmsg}`);
|
throw new APIException(EX.API_IMAGE_GENERATION_INSUFFICIENT_POINTS, `[无法生成图像]: 即梦积分可能不足,${errmsg}`);
|
||||||
|
|||||||
@ -59,6 +59,96 @@ export async function generateImages(
|
|||||||
await receiveCredit(refreshToken);
|
await receiveCredit(refreshToken);
|
||||||
|
|
||||||
const componentId = util.uuid();
|
const componentId = util.uuid();
|
||||||
|
const draftContent = {
|
||||||
|
type: "draft",
|
||||||
|
id: util.uuid(),
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
min_features: [],
|
||||||
|
is_from_tsn: true,
|
||||||
|
version: currentVersion,
|
||||||
|
main_component_id: componentId,
|
||||||
|
component_list: [
|
||||||
|
{
|
||||||
|
type: "image_base_component",
|
||||||
|
id: componentId,
|
||||||
|
min_version: DRAFT_VERSION,
|
||||||
|
gen_type: 1,
|
||||||
|
generate_type: "generate",
|
||||||
|
aigc_mode: "workbench",
|
||||||
|
metadata: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
created_platform: 3,
|
||||||
|
created_platform_version: "",
|
||||||
|
created_time_in_ms: Date.now().toString(),
|
||||||
|
created_did: ""
|
||||||
|
},
|
||||||
|
abilities: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
generate: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
core_param: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
model,
|
||||||
|
prompt,
|
||||||
|
negative_prompt: negativePrompt,
|
||||||
|
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
||||||
|
sample_strength: sampleStrength,
|
||||||
|
image_ratio: 1,
|
||||||
|
large_image_info: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
resolution_type: resolutionType,
|
||||||
|
},
|
||||||
|
intelligent_ratio: false
|
||||||
|
},
|
||||||
|
history_option: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
gen_option: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
gen_count: 1,
|
||||||
|
generate_all: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const payloadData = {
|
||||||
|
extend: {
|
||||||
|
root_model: model,
|
||||||
|
template_id: "",
|
||||||
|
},
|
||||||
|
submit_id: util.uuid(),
|
||||||
|
metrics_extra: JSON.stringify({
|
||||||
|
templateId: "0",
|
||||||
|
generateCount: 1,
|
||||||
|
promptSource: "custom",
|
||||||
|
templateSource: "",
|
||||||
|
lastRequestId: "",
|
||||||
|
originRequestId: "",
|
||||||
|
enterFrom: "use_bgimage_prompt",
|
||||||
|
isRegenerate: false,
|
||||||
|
isBoxSelect: false,
|
||||||
|
isCutout: false
|
||||||
|
}),
|
||||||
|
draft_content: JSON.stringify(draftContent),
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.info(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`);
|
||||||
|
|
||||||
const { aigc_data } = await request(
|
const { aigc_data } = await request(
|
||||||
"post",
|
"post",
|
||||||
"/mweb/v1/aigc_draft/generate",
|
"/mweb/v1/aigc_draft/generate",
|
||||||
@ -74,72 +164,10 @@ export async function generateImages(
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
data: {
|
data: payloadData,
|
||||||
extend: {
|
|
||||||
root_model: model,
|
|
||||||
template_id: "",
|
|
||||||
},
|
|
||||||
submit_id: util.uuid(),
|
|
||||||
metrics_extra: JSON.stringify({
|
|
||||||
templateId: "",
|
|
||||||
generateCount: 1,
|
|
||||||
promptSource: "custom",
|
|
||||||
templateSource: "",
|
|
||||||
lastRequestId: "",
|
|
||||||
originRequestId: "",
|
|
||||||
}),
|
|
||||||
draft_content: JSON.stringify({
|
|
||||||
type: "draft",
|
|
||||||
id: util.uuid(),
|
|
||||||
min_version: DRAFT_VERSION,
|
|
||||||
is_from_tsn: true,
|
|
||||||
version: currentVersion,
|
|
||||||
main_component_id: componentId,
|
|
||||||
component_list: [
|
|
||||||
{
|
|
||||||
type: "image_base_component",
|
|
||||||
id: componentId,
|
|
||||||
min_version: DRAFT_VERSION,
|
|
||||||
generate_type: "generate",
|
|
||||||
aigc_mode: "workbench",
|
|
||||||
abilities: {
|
|
||||||
type: "",
|
|
||||||
id: util.uuid(),
|
|
||||||
generate: {
|
|
||||||
type: "",
|
|
||||||
id: util.uuid(),
|
|
||||||
core_param: {
|
|
||||||
type: "",
|
|
||||||
id: util.uuid(),
|
|
||||||
model,
|
|
||||||
prompt,
|
|
||||||
negative_prompt: negativePrompt,
|
|
||||||
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
|
||||||
sample_strength: sampleStrength,
|
|
||||||
image_ratio: 1,
|
|
||||||
large_image_info: {
|
|
||||||
type: "",
|
|
||||||
id: util.uuid(),
|
|
||||||
height,
|
|
||||||
width,
|
|
||||||
resolution_type: resolutionType,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
history_option: {
|
|
||||||
type: "",
|
|
||||||
id: util.uuid(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
http_common_info: {
|
|
||||||
aid: Number(DEFAULT_ASSISTANT_ID),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
logger.info(`Jimeng Response Data: ${JSON.stringify(aigc_data)}`);
|
||||||
const historyId = aigc_data.history_record_id;
|
const historyId = aigc_data.history_record_id;
|
||||||
if (!historyId)
|
if (!historyId)
|
||||||
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");
|
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");
|
||||||
|
|||||||
@ -792,6 +792,96 @@ export class TaskPollingService {
|
|||||||
const componentId = this.generateUUID();
|
const componentId = this.generateUUID();
|
||||||
const submitId = this.generateUUID();
|
const submitId = this.generateUUID();
|
||||||
|
|
||||||
|
const draftContent = {
|
||||||
|
type: "draft",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
min_version: "3.0.2",
|
||||||
|
min_features: [],
|
||||||
|
is_from_tsn: true,
|
||||||
|
version: currentVersion,
|
||||||
|
main_component_id: componentId,
|
||||||
|
component_list: [
|
||||||
|
{
|
||||||
|
type: "image_base_component",
|
||||||
|
id: componentId,
|
||||||
|
min_version: "3.0.2",
|
||||||
|
gen_type: 1,
|
||||||
|
generate_type: "generate",
|
||||||
|
aigc_mode: "workbench",
|
||||||
|
metadata: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
created_platform: 3,
|
||||||
|
created_platform_version: "",
|
||||||
|
created_time_in_ms: Date.now().toString(),
|
||||||
|
created_did: ""
|
||||||
|
},
|
||||||
|
abilities: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
generate: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
core_param: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
model: mappedModel,
|
||||||
|
prompt,
|
||||||
|
negative_prompt,
|
||||||
|
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
||||||
|
sample_strength,
|
||||||
|
image_ratio: 1,
|
||||||
|
large_image_info: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
height,
|
||||||
|
width,
|
||||||
|
resolution_type: resolutionType,
|
||||||
|
},
|
||||||
|
intelligent_ratio: false
|
||||||
|
},
|
||||||
|
history_option: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
gen_option: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
gen_count: 1,
|
||||||
|
generate_all: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const payloadData = {
|
||||||
|
extend: {
|
||||||
|
root_model: mappedModel,
|
||||||
|
template_id: "",
|
||||||
|
},
|
||||||
|
submit_id: submitId,
|
||||||
|
metrics_extra: JSON.stringify({
|
||||||
|
templateId: "0",
|
||||||
|
generateCount: 1,
|
||||||
|
promptSource: "custom",
|
||||||
|
templateSource: "",
|
||||||
|
lastRequestId: "",
|
||||||
|
originRequestId: "",
|
||||||
|
enterFrom: "use_bgimage_prompt",
|
||||||
|
isRegenerate: false,
|
||||||
|
isBoxSelect: false,
|
||||||
|
isCutout: false
|
||||||
|
}),
|
||||||
|
draft_content: JSON.stringify(draftContent),
|
||||||
|
http_common_info: {
|
||||||
|
aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
taskLog(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`);
|
||||||
|
|
||||||
const { aigc_data } = await request(
|
const { aigc_data } = await request(
|
||||||
"post",
|
"post",
|
||||||
"/mweb/v1/aigc_draft/generate",
|
"/mweb/v1/aigc_draft/generate",
|
||||||
@ -807,73 +897,12 @@ export class TaskPollingService {
|
|||||||
})
|
})
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
data: {
|
data: payloadData,
|
||||||
extend: {
|
|
||||||
root_model: mappedModel,
|
|
||||||
template_id: "",
|
|
||||||
},
|
|
||||||
submit_id: submitId,
|
|
||||||
metrics_extra: JSON.stringify({
|
|
||||||
templateId: "",
|
|
||||||
generateCount: 1,
|
|
||||||
promptSource: "custom",
|
|
||||||
templateSource: "",
|
|
||||||
lastRequestId: "",
|
|
||||||
originRequestId: "",
|
|
||||||
}),
|
|
||||||
draft_content: JSON.stringify({
|
|
||||||
type: "draft",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
min_version: "3.0.2",
|
|
||||||
is_from_tsn: true,
|
|
||||||
version: currentVersion,
|
|
||||||
main_component_id: componentId,
|
|
||||||
component_list: [
|
|
||||||
{
|
|
||||||
type: "image_base_component",
|
|
||||||
id: componentId,
|
|
||||||
min_version: "3.0.2",
|
|
||||||
generate_type: "generate",
|
|
||||||
aigc_mode: "workbench",
|
|
||||||
abilities: {
|
|
||||||
type: "",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
generate: {
|
|
||||||
type: "",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
core_param: {
|
|
||||||
type: "",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
model: mappedModel,
|
|
||||||
prompt,
|
|
||||||
negative_prompt,
|
|
||||||
seed: Math.floor(Math.random() * 100000000) + 2500000000,
|
|
||||||
sample_strength,
|
|
||||||
image_ratio: 1,
|
|
||||||
large_image_info: {
|
|
||||||
type: "",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
height,
|
|
||||||
width,
|
|
||||||
resolution_type: resolutionType,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
history_option: {
|
|
||||||
type: "",
|
|
||||||
id: this.generateUUID(),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}),
|
|
||||||
http_common_info: {
|
|
||||||
aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
taskLog(`Jimeng Response Data: ${JSON.stringify(aigc_data)}`);
|
||||||
|
|
||||||
const historyId = aigc_data.history_record_id;
|
const historyId = aigc_data.history_record_id;
|
||||||
if (!historyId) {
|
if (!historyId) {
|
||||||
throw new Error('Failed to get history_record_id from image generation API');
|
throw new Error('Failed to get history_record_id from image generation API');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user