debug: add detailed logging for scene fusion API response
This commit is contained in:
parent
f60ced8d29
commit
150b146f91
@ -250,6 +250,9 @@ async function callAlibabaImageAPI(
|
|||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
|
|
||||||
|
// 打印完整响应用于调试
|
||||||
|
console.log(`[SceneFusion][${modelId}] Full API Response:`, JSON.stringify(data, null, 2));
|
||||||
|
|
||||||
if (!response.ok || data.code) {
|
if (!response.ok || data.code) {
|
||||||
console.error("[SceneFusion] API Error Response:", JSON.stringify(data, null, 2));
|
console.error("[SceneFusion] API Error Response:", JSON.stringify(data, null, 2));
|
||||||
throw new Error(data.message || (data.code ? `Error ${data.code}: ${data.message}` : `API request failed: ${response.status}`));
|
throw new Error(data.message || (data.code ? `Error ${data.code}: ${data.message}` : `API request failed: ${response.status}`));
|
||||||
@ -258,19 +261,40 @@ async function callAlibabaImageAPI(
|
|||||||
// 提取生成的图片 URL
|
// 提取生成的图片 URL
|
||||||
const choices = data.output?.choices;
|
const choices = data.output?.choices;
|
||||||
if (!choices || choices.length === 0) {
|
if (!choices || choices.length === 0) {
|
||||||
|
console.error("[SceneFusion] No choices in response, output:", data.output);
|
||||||
throw new Error("No images in response");
|
throw new Error("No images in response");
|
||||||
}
|
}
|
||||||
|
|
||||||
const imageContent = choices[0]?.message?.content;
|
const imageContent = choices[0]?.message?.content;
|
||||||
|
console.log(`[SceneFusion] Image content array:`, JSON.stringify(imageContent, null, 2));
|
||||||
|
|
||||||
if (!imageContent || imageContent.length === 0) {
|
if (!imageContent || imageContent.length === 0) {
|
||||||
throw new Error("No image content in response");
|
throw new Error("No image content in response");
|
||||||
}
|
}
|
||||||
|
|
||||||
const generatedImageUrl = imageContent[0]?.image;
|
// 遍历所有内容项,找到 image 类型的
|
||||||
|
let generatedImageUrl: string | undefined;
|
||||||
|
for (const item of imageContent) {
|
||||||
|
if (item.image) {
|
||||||
|
generatedImageUrl = item.image;
|
||||||
|
console.log(`[SceneFusion] Found image URL in content item`);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!generatedImageUrl) {
|
if (!generatedImageUrl) {
|
||||||
|
console.error("[SceneFusion] No image URL found in content:", imageContent);
|
||||||
throw new Error("No image URL in response");
|
throw new Error("No image URL in response");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 检查返回的图片 URL 是否与输入相同(可能是 API 返回了原图)
|
||||||
|
if (generatedImageUrl === productImageUrl || generatedImageUrl === sceneImageUrl) {
|
||||||
|
console.warn(`[SceneFusion] ⚠️ WARNING: API returned same URL as input!`);
|
||||||
|
console.warn(`[SceneFusion] - Generated URL: ${generatedImageUrl}`);
|
||||||
|
console.warn(`[SceneFusion] - Product URL: ${productImageUrl}`);
|
||||||
|
console.warn(`[SceneFusion] - Scene URL: ${sceneImageUrl}`);
|
||||||
|
}
|
||||||
|
|
||||||
console.log("[SceneFusion] Generated image URL:", generatedImageUrl.substring(0, 100) + "...");
|
console.log("[SceneFusion] Generated image URL:", generatedImageUrl.substring(0, 100) + "...");
|
||||||
return generatedImageUrl;
|
return generatedImageUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user