koishi-plugin-best-cave 2.7.28 → 2.7.29
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 +36 -31
- package/package.json +3 -3
package/lib/index.js
CHANGED
|
@@ -1270,40 +1270,45 @@ var AIManager = class {
|
|
|
1270
1270
|
async analyze(caves, mediaBuffers) {
|
|
1271
1271
|
const mediaMap = mediaBuffers ? new Map(mediaBuffers.map((m) => [m.fileName, m.buffer])) : void 0;
|
|
1272
1272
|
const analysisPromises = caves.map(async (cave) => {
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1273
|
+
try {
|
|
1274
|
+
const combinedText = cave.elements.filter((el) => el.type === "text" && el.content).map((el) => el.content).join("\n");
|
|
1275
|
+
const imageElements = await Promise.all(
|
|
1276
|
+
cave.elements.filter((el) => el.type === "image" && el.file).map(async (el) => {
|
|
1277
|
+
try {
|
|
1278
|
+
const buffer = mediaMap?.get(el.file) ?? await this.fileManager.readFile(el.file);
|
|
1279
|
+
const mimeType = path3.extname(el.file).toLowerCase() === ".png" ? "image/png" : "image/jpeg";
|
|
1280
|
+
return {
|
|
1281
|
+
type: "image_url",
|
|
1282
|
+
image_url: { url: `data:${mimeType};base64,${buffer.toString("base64")}` }
|
|
1283
|
+
};
|
|
1284
|
+
} catch (error) {
|
|
1285
|
+
this.logger.warn(`读取文件(${el.file})失败:`, error);
|
|
1286
|
+
return null;
|
|
1287
|
+
}
|
|
1288
|
+
})
|
|
1289
|
+
);
|
|
1290
|
+
const images = imageElements.filter(Boolean);
|
|
1291
|
+
if (!combinedText.trim() && images.length === 0) return null;
|
|
1292
|
+
const contentForAI = [];
|
|
1293
|
+
if (combinedText.trim()) contentForAI.push({ type: "text", text: `请分析以下内容:
|
|
1293
1294
|
|
|
1294
1295
|
${combinedText}` });
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1296
|
+
contentForAI.push(...images);
|
|
1297
|
+
const userMessage = { role: "user", content: contentForAI };
|
|
1298
|
+
const response = await this.requestAI([userMessage], this.ANALYSIS_SYSTEM_PROMPT);
|
|
1299
|
+
if (response) {
|
|
1300
|
+
return {
|
|
1301
|
+
cave: cave.id,
|
|
1302
|
+
keywords: response.keywords || [],
|
|
1303
|
+
description: response.description || "",
|
|
1304
|
+
rating: Math.max(0, Math.min(100, response.rating || 0))
|
|
1305
|
+
};
|
|
1306
|
+
}
|
|
1307
|
+
return null;
|
|
1308
|
+
} catch (error) {
|
|
1309
|
+
this.logger.error(`分析回声洞(${cave.id})失败:`, error);
|
|
1310
|
+
return null;
|
|
1305
1311
|
}
|
|
1306
|
-
return null;
|
|
1307
1312
|
});
|
|
1308
1313
|
const results = await Promise.all(analysisPromises);
|
|
1309
1314
|
return results.filter((result) => !!result);
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-best-cave",
|
|
3
3
|
"description": "功能强大、高度可定制的回声洞插件。支持丰富的媒体类型、内容查重、AI分析、人工审核、用户昵称、数据迁移以及本地/S3 双重文件存储后端。",
|
|
4
|
-
"version": "2.7.
|
|
4
|
+
"version": "2.7.29",
|
|
5
5
|
"contributors": [
|
|
6
6
|
"Yis_Rime <yis_rime@outlook.com>"
|
|
7
7
|
],
|
|
8
|
-
"homepage": "https://github.com/
|
|
8
|
+
"homepage": "https://github.com//Koishi-Plugin/best-cave",
|
|
9
9
|
"repository": {
|
|
10
10
|
"type": "git",
|
|
11
|
-
"url": "git+https://github.com/
|
|
11
|
+
"url": "git+https://github.com//Koishi-Plugin/best-cave.git"
|
|
12
12
|
},
|
|
13
13
|
"main": "lib/index.js",
|
|
14
14
|
"typings": "lib/index.d.ts",
|