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,39 +59,11 @@ export async function generateImages(
|
|||||||
await receiveCredit(refreshToken);
|
await receiveCredit(refreshToken);
|
||||||
|
|
||||||
const componentId = util.uuid();
|
const componentId = util.uuid();
|
||||||
const { aigc_data } = await request(
|
const draftContent = {
|
||||||
"post",
|
|
||||||
"/mweb/v1/aigc_draft/generate",
|
|
||||||
refreshToken,
|
|
||||||
{
|
|
||||||
params: {
|
|
||||||
babi_param: encodeURIComponent(
|
|
||||||
JSON.stringify({
|
|
||||||
scenario: "image_video_generation",
|
|
||||||
feature_key: "aigc_to_image",
|
|
||||||
feature_entrance: "to_image",
|
|
||||||
feature_entrance_detail: "to_image-" + model,
|
|
||||||
})
|
|
||||||
),
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
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",
|
type: "draft",
|
||||||
id: util.uuid(),
|
id: util.uuid(),
|
||||||
min_version: DRAFT_VERSION,
|
min_version: DRAFT_VERSION,
|
||||||
|
min_features: [],
|
||||||
is_from_tsn: true,
|
is_from_tsn: true,
|
||||||
version: currentVersion,
|
version: currentVersion,
|
||||||
main_component_id: componentId,
|
main_component_id: componentId,
|
||||||
@ -100,8 +72,17 @@ export async function generateImages(
|
|||||||
type: "image_base_component",
|
type: "image_base_component",
|
||||||
id: componentId,
|
id: componentId,
|
||||||
min_version: DRAFT_VERSION,
|
min_version: DRAFT_VERSION,
|
||||||
|
gen_type: 1,
|
||||||
generate_type: "generate",
|
generate_type: "generate",
|
||||||
aigc_mode: "workbench",
|
aigc_mode: "workbench",
|
||||||
|
metadata: {
|
||||||
|
type: "",
|
||||||
|
id: util.uuid(),
|
||||||
|
created_platform: 3,
|
||||||
|
created_platform_version: "",
|
||||||
|
created_time_in_ms: Date.now().toString(),
|
||||||
|
created_did: ""
|
||||||
|
},
|
||||||
abilities: {
|
abilities: {
|
||||||
type: "",
|
type: "",
|
||||||
id: util.uuid(),
|
id: util.uuid(),
|
||||||
@ -124,22 +105,69 @@ export async function generateImages(
|
|||||||
width,
|
width,
|
||||||
resolution_type: resolutionType,
|
resolution_type: resolutionType,
|
||||||
},
|
},
|
||||||
|
intelligent_ratio: false
|
||||||
},
|
},
|
||||||
history_option: {
|
history_option: {
|
||||||
type: "",
|
type: "",
|
||||||
id: util.uuid(),
|
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: {
|
http_common_info: {
|
||||||
aid: Number(DEFAULT_ASSISTANT_ID),
|
aid: Number(DEFAULT_ASSISTANT_ID),
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
logger.info(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`);
|
||||||
|
|
||||||
|
const { aigc_data } = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/aigc_draft/generate",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
babi_param: encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
scenario: "image_video_generation",
|
||||||
|
feature_key: "aigc_to_image",
|
||||||
|
feature_entrance: "to_image",
|
||||||
|
feature_entrance_detail: "to_image-" + model,
|
||||||
|
})
|
||||||
|
),
|
||||||
},
|
},
|
||||||
|
data: payloadData,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
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,39 +792,11 @@ export class TaskPollingService {
|
|||||||
const componentId = this.generateUUID();
|
const componentId = this.generateUUID();
|
||||||
const submitId = this.generateUUID();
|
const submitId = this.generateUUID();
|
||||||
|
|
||||||
const { aigc_data } = await request(
|
const draftContent = {
|
||||||
"post",
|
|
||||||
"/mweb/v1/aigc_draft/generate",
|
|
||||||
refreshToken,
|
|
||||||
{
|
|
||||||
params: {
|
|
||||||
babi_param: encodeURIComponent(
|
|
||||||
JSON.stringify({
|
|
||||||
scenario: "image_video_generation",
|
|
||||||
feature_key: "aigc_to_image",
|
|
||||||
feature_entrance: "to_image",
|
|
||||||
feature_entrance_detail: "to_image-" + mappedModel,
|
|
||||||
})
|
|
||||||
),
|
|
||||||
},
|
|
||||||
data: {
|
|
||||||
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",
|
type: "draft",
|
||||||
id: this.generateUUID(),
|
id: this.generateUUID(),
|
||||||
min_version: "3.0.2",
|
min_version: "3.0.2",
|
||||||
|
min_features: [],
|
||||||
is_from_tsn: true,
|
is_from_tsn: true,
|
||||||
version: currentVersion,
|
version: currentVersion,
|
||||||
main_component_id: componentId,
|
main_component_id: componentId,
|
||||||
@ -833,8 +805,17 @@ export class TaskPollingService {
|
|||||||
type: "image_base_component",
|
type: "image_base_component",
|
||||||
id: componentId,
|
id: componentId,
|
||||||
min_version: "3.0.2",
|
min_version: "3.0.2",
|
||||||
|
gen_type: 1,
|
||||||
generate_type: "generate",
|
generate_type: "generate",
|
||||||
aigc_mode: "workbench",
|
aigc_mode: "workbench",
|
||||||
|
metadata: {
|
||||||
|
type: "",
|
||||||
|
id: this.generateUUID(),
|
||||||
|
created_platform: 3,
|
||||||
|
created_platform_version: "",
|
||||||
|
created_time_in_ms: Date.now().toString(),
|
||||||
|
created_did: ""
|
||||||
|
},
|
||||||
abilities: {
|
abilities: {
|
||||||
type: "",
|
type: "",
|
||||||
id: this.generateUUID(),
|
id: this.generateUUID(),
|
||||||
@ -857,23 +838,71 @@ export class TaskPollingService {
|
|||||||
width,
|
width,
|
||||||
resolution_type: resolutionType,
|
resolution_type: resolutionType,
|
||||||
},
|
},
|
||||||
|
intelligent_ratio: false
|
||||||
},
|
},
|
||||||
history_option: {
|
history_option: {
|
||||||
type: "",
|
type: "",
|
||||||
id: this.generateUUID(),
|
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: {
|
http_common_info: {
|
||||||
aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"),
|
aid: Number(process.env.DEFAULT_ASSISTANT_ID || "513695"),
|
||||||
},
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
taskLog(`Jimeng Request Payload: ${JSON.stringify(payloadData)}`);
|
||||||
|
|
||||||
|
const { aigc_data } = await request(
|
||||||
|
"post",
|
||||||
|
"/mweb/v1/aigc_draft/generate",
|
||||||
|
refreshToken,
|
||||||
|
{
|
||||||
|
params: {
|
||||||
|
babi_param: encodeURIComponent(
|
||||||
|
JSON.stringify({
|
||||||
|
scenario: "image_video_generation",
|
||||||
|
feature_key: "aigc_to_image",
|
||||||
|
feature_entrance: "to_image",
|
||||||
|
feature_entrance_detail: "to_image-" + mappedModel,
|
||||||
|
})
|
||||||
|
),
|
||||||
},
|
},
|
||||||
|
data: payloadData,
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
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