koishi-plugin-aka-ai-generator 0.7.11 → 0.7.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +22 -9
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -105,15 +105,17 @@ async function downloadImageAsBase64(ctx, url, timeout, logger, maxSize = 10 * 1
|
|
|
105
105
|
}
|
|
106
106
|
if (mimeType === "image/gif") {
|
|
107
107
|
try {
|
|
108
|
-
logger.debug("检测到 GIF 图片,正在转换为
|
|
108
|
+
logger.debug("检测到 GIF 图片,正在转换为 PNG", { url });
|
|
109
109
|
const image = await import_jimp.default.read(buffer);
|
|
110
|
-
const
|
|
111
|
-
const
|
|
112
|
-
logger.info("GIF 已转换为
|
|
110
|
+
const pngBuffer = await image.getBufferAsync(import_jimp.default.MIME_PNG);
|
|
111
|
+
const pngBase64 = pngBuffer.toString("base64");
|
|
112
|
+
logger.info("GIF 已转换为 PNG", {
|
|
113
113
|
originalSize: buffer.length,
|
|
114
|
-
newSize:
|
|
114
|
+
newSize: pngBuffer.length,
|
|
115
|
+
width: image.getWidth(),
|
|
116
|
+
height: image.getHeight()
|
|
115
117
|
});
|
|
116
|
-
return { data:
|
|
118
|
+
return { data: pngBase64, mimeType: "image/png" };
|
|
117
119
|
} catch (conversionError) {
|
|
118
120
|
logger.warn("GIF 转换失败,尝试原样发送", { error: conversionError?.message });
|
|
119
121
|
}
|
|
@@ -626,10 +628,21 @@ function parseGeminiResponse(response, logger) {
|
|
|
626
628
|
safetyRatings: candidate.safetyRatings
|
|
627
629
|
});
|
|
628
630
|
if (candidate.finishReason === "SAFETY" || candidate.finishReason === "RECITATION") {
|
|
629
|
-
|
|
631
|
+
let msg = `内容被阻止: ${candidate.finishReason},可能包含不安全的内容`;
|
|
632
|
+
if (candidate.finishMessage) {
|
|
633
|
+
msg += ` (详细信息: ${candidate.finishMessage})`;
|
|
634
|
+
}
|
|
635
|
+
throw new Error(msg);
|
|
630
636
|
}
|
|
631
|
-
if (candidate.finishReason !== "MAX_TOKENS") {
|
|
632
|
-
|
|
637
|
+
if (candidate.finishReason === "IMAGE_OTHER" || candidate.finishReason !== "MAX_TOKENS" && candidate.finishReason !== "STOP") {
|
|
638
|
+
let msg = `生成失败: ${candidate.finishReason}`;
|
|
639
|
+
if (candidate.finishMessage) {
|
|
640
|
+
msg += `,原因: ${candidate.finishMessage}`;
|
|
641
|
+
}
|
|
642
|
+
logger?.warn("Gemini 生成未完成", { finishReason: candidate.finishReason, finishMessage: candidate.finishMessage });
|
|
643
|
+
if (!candidate.content || !candidate.content.parts || candidate.content.parts.length === 0) {
|
|
644
|
+
throw new Error(msg);
|
|
645
|
+
}
|
|
633
646
|
}
|
|
634
647
|
}
|
|
635
648
|
if (candidate.content && candidate.content.parts) {
|