This commit is contained in:
jonathang4 2025-12-13 10:27:09 +08:00
parent af4abb772e
commit ee875ac5c2
2 changed files with 132 additions and 187 deletions

View File

@ -50,7 +50,8 @@ export async function generateImages(
try {
const model = getModel(_model);
const isV4 = _model.startsWith('jimeng-4');
const currentVersion = isV4 ? '3.3.7' : DRAFT_VERSION;
// const currentVersion = isV4 ? '3.3.7' : DRAFT_VERSION;
const currentVersion = DRAFT_VERSION;
const resolutionType = isV4 ? '2k' : '1k';
logger.info(`使用模型: ${_model} 映射模型: ${model} ${width}x${height} 精细度: ${sampleStrength}`);
@ -59,11 +60,39 @@ export async function generateImages(
await receiveCredit(refreshToken);
const componentId = util.uuid();
const draftContent = {
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: {
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,
min_features: [],
is_from_tsn: true,
version: currentVersion,
main_component_id: componentId,
@ -72,17 +101,8 @@ export async function generateImages(
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(),
@ -105,69 +125,22 @@ export async function generateImages(
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(
"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;
if (!historyId)
throw new APIException(EX.API_IMAGE_GENERATION_FAILED, "记录ID不存在");

View File

@ -786,17 +786,46 @@ export class TaskPollingService {
// 4.x 模型特殊参数
const isV4 = model.startsWith('jimeng-4');
const currentVersion = isV4 ? '3.3.7' : "3.0.2";
// const currentVersion = isV4 ? '3.3.7' : "3.0.2";
const currentVersion = "3.0.2";
const resolutionType = isV4 ? '2k' : '1k';
const componentId = this.generateUUID();
const submitId = this.generateUUID();
const draftContent = {
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: {
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",
min_features: [],
is_from_tsn: true,
version: currentVersion,
main_component_id: componentId,
@ -805,17 +834,8 @@ export class TaskPollingService {
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(),
@ -838,71 +858,23 @@ export class TaskPollingService {
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(
"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;
if (!historyId) {
throw new Error('Failed to get history_record_id from image generation API');