koishi-plugin-chatluna-long-memory 1.2.6 → 1.2.8
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.cjs +42 -51
- package/lib/index.mjs +38 -47
- package/lib/plugins/tool.d.ts +12 -12
- package/lib/utils/layer.d.ts +1 -1
- package/package.json +5 -5
package/lib/index.cjs
CHANGED
|
@@ -57,7 +57,7 @@ __export(index_exports, {
|
|
|
57
57
|
name: () => name
|
|
58
58
|
});
|
|
59
59
|
module.exports = __toCommonJS(index_exports);
|
|
60
|
-
var
|
|
60
|
+
var import_koishi2 = require("koishi");
|
|
61
61
|
var import_chat = require("koishi-plugin-chatluna/services/chat");
|
|
62
62
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
63
63
|
|
|
@@ -66,7 +66,7 @@ var import_koishi_plugin_chatluna2 = require("koishi-plugin-chatluna");
|
|
|
66
66
|
var import_chains = require("koishi-plugin-chatluna/chains");
|
|
67
67
|
|
|
68
68
|
// src/utils/layer.ts
|
|
69
|
-
var
|
|
69
|
+
var import_vectorstores = require("koishi-plugin-chatluna/llm-core/vectorstores");
|
|
70
70
|
|
|
71
71
|
// src/utils/similarity.ts
|
|
72
72
|
var import_jieba_wasm = require("jieba-wasm");
|
|
@@ -522,6 +522,13 @@ var VectorStoreMemoryLayer = class extends BaseMemoryRetrievalLayer {
|
|
|
522
522
|
this.vectorStore = this.retriever.vectorStore;
|
|
523
523
|
}
|
|
524
524
|
async retrieveMemory(searchContent) {
|
|
525
|
+
if (!this.vectorStore) {
|
|
526
|
+
logger2?.warn("Vector store not initialized");
|
|
527
|
+
return;
|
|
528
|
+
}
|
|
529
|
+
if (!this.vectorStore.checkActive(false)) {
|
|
530
|
+
await this.initialize();
|
|
531
|
+
}
|
|
525
532
|
let memory = await this.retriever.invoke(searchContent);
|
|
526
533
|
if (this.config.longMemoryTFIDFThreshold > 0) {
|
|
527
534
|
memory = filterSimilarMemoryByBM25(
|
|
@@ -548,7 +555,7 @@ var VectorStoreMemoryLayer = class extends BaseMemoryRetrievalLayer {
|
|
|
548
555
|
await this.vectorStore.addDocuments(
|
|
549
556
|
memories.map(enhancedMemoryToDocument)
|
|
550
557
|
);
|
|
551
|
-
if (this.vectorStore instanceof
|
|
558
|
+
if (this.vectorStore instanceof import_vectorstores.ChatLunaSaveableVectorStore) {
|
|
552
559
|
logger2?.debug("saving vector store");
|
|
553
560
|
try {
|
|
554
561
|
await this.vectorStore.save();
|
|
@@ -561,12 +568,15 @@ var VectorStoreMemoryLayer = class extends BaseMemoryRetrievalLayer {
|
|
|
561
568
|
if (!this.vectorStore) {
|
|
562
569
|
return;
|
|
563
570
|
}
|
|
571
|
+
if (!this.vectorStore.checkActive(false)) {
|
|
572
|
+
await this.initialize();
|
|
573
|
+
}
|
|
564
574
|
await this.vectorStore.delete({ deleteAll: true });
|
|
565
575
|
}
|
|
566
576
|
async deleteMemories(memoryIds) {
|
|
567
577
|
if (typeof this.vectorStore.delete === "function") {
|
|
568
578
|
await this.vectorStore.delete({ ids: memoryIds });
|
|
569
|
-
if (this.vectorStore instanceof
|
|
579
|
+
if (this.vectorStore instanceof import_vectorstores.ChatLunaSaveableVectorStore) {
|
|
570
580
|
await this.vectorStore.save();
|
|
571
581
|
}
|
|
572
582
|
logger2?.debug(`Deleted ${memoryIds.length} expired memories`);
|
|
@@ -608,7 +618,7 @@ async function createVectorStoreRetriever(ctx, config, longMemoryId) {
|
|
|
608
618
|
const [platform, model] = (0, import_count_tokens.parseRawModelName)(
|
|
609
619
|
ctx.chatluna.config.defaultEmbeddings
|
|
610
620
|
);
|
|
611
|
-
const embeddingModel = await ctx.chatluna.createEmbeddings(platform, model);
|
|
621
|
+
const embeddingModel = await ctx.chatluna.createEmbeddings(platform, model).then((model2) => model2.value);
|
|
612
622
|
const vectorStore = await ctx.chatluna.platform.createVectorStore(
|
|
613
623
|
ctx.chatluna.config.defaultVectorStore,
|
|
614
624
|
{
|
|
@@ -907,7 +917,7 @@ async function generateNewQuestion(ctx, config, chatHistory, question) {
|
|
|
907
917
|
const [platform, modelName] = (0, import_count_tokens2.parseRawModelName)(
|
|
908
918
|
config.longMemoryExtractModel
|
|
909
919
|
);
|
|
910
|
-
const model = await ctx.chatluna.createChatModel(platform, modelName);
|
|
920
|
+
const model = await ctx.chatluna.createChatModel(platform, modelName).then((model2) => model2.value);
|
|
911
921
|
const prompt = `
|
|
912
922
|
Given the following conversation history and the user's question, generate a new search query that will help retrieve relevant information from a long-term memory database. The search query should be concise and focused on the key information needs.
|
|
913
923
|
|
|
@@ -943,10 +953,7 @@ async function extractMemoriesFromChat(ctx, config, chatInterface, chatHistory)
|
|
|
943
953
|
const [platform, modelName] = (0, import_count_tokens2.parseRawModelName)(
|
|
944
954
|
config.longMemoryExtractModel
|
|
945
955
|
);
|
|
946
|
-
const model = await ctx.chatluna.createChatModel(
|
|
947
|
-
platform,
|
|
948
|
-
modelName
|
|
949
|
-
);
|
|
956
|
+
const model = await ctx.chatluna.createChatModel(platform, modelName).then((model2) => model2.value);
|
|
950
957
|
const extractMemory = /* @__PURE__ */ __name(async () => {
|
|
951
958
|
const result = await model.invoke(input);
|
|
952
959
|
logger2?.debug(`Long memory extract model result: ${result.content}`);
|
|
@@ -1166,26 +1173,11 @@ function apply3(ctx, config) {
|
|
|
1166
1173
|
__name(apply3, "apply");
|
|
1167
1174
|
|
|
1168
1175
|
// src/plugins/config.ts
|
|
1169
|
-
var
|
|
1170
|
-
var import_types4 = require("koishi-plugin-chatluna/llm-core/platform/types");
|
|
1176
|
+
var import_schema = require("koishi-plugin-chatluna/utils/schema");
|
|
1171
1177
|
async function apply4(ctx, config) {
|
|
1172
|
-
|
|
1173
|
-
ctx.schema.set("model", import_koishi.Schema.union(getModelNames(service)));
|
|
1174
|
-
});
|
|
1175
|
-
ctx.on("chatluna/model-removed", (service) => {
|
|
1176
|
-
ctx.schema.set("model", import_koishi.Schema.union(getModelNames(service)));
|
|
1177
|
-
});
|
|
1178
|
-
ctx.schema.set("model", import_koishi.Schema.union(getModelNames(ctx.chatluna.platform)));
|
|
1178
|
+
(0, import_schema.modelSchema)(ctx);
|
|
1179
1179
|
}
|
|
1180
1180
|
__name(apply4, "apply");
|
|
1181
|
-
function getModelNames(service) {
|
|
1182
|
-
const models = service.getAllModels(import_types4.ModelType.llm).map((m) => import_koishi.Schema.const(m));
|
|
1183
|
-
if (models.length < 1) {
|
|
1184
|
-
models.push(import_koishi.Schema.const("无"));
|
|
1185
|
-
}
|
|
1186
|
-
return models;
|
|
1187
|
-
}
|
|
1188
|
-
__name(getModelNames, "getModelNames");
|
|
1189
1181
|
|
|
1190
1182
|
// src/plugins/delete_memory.ts
|
|
1191
1183
|
var import_koishi_plugin_chatluna4 = require("koishi-plugin-chatluna");
|
|
@@ -1377,7 +1369,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1377
1369
|
selector(history) {
|
|
1378
1370
|
return true;
|
|
1379
1371
|
},
|
|
1380
|
-
|
|
1372
|
+
createTool(params) {
|
|
1381
1373
|
return new MemorySearchTool(ctx, params);
|
|
1382
1374
|
}
|
|
1383
1375
|
});
|
|
@@ -1385,7 +1377,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1385
1377
|
selector(history) {
|
|
1386
1378
|
return true;
|
|
1387
1379
|
},
|
|
1388
|
-
|
|
1380
|
+
createTool(params) {
|
|
1389
1381
|
return new MemoryAddTool(ctx, params);
|
|
1390
1382
|
}
|
|
1391
1383
|
});
|
|
@@ -1393,7 +1385,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1393
1385
|
selector(history) {
|
|
1394
1386
|
return true;
|
|
1395
1387
|
},
|
|
1396
|
-
|
|
1388
|
+
createTool(params) {
|
|
1397
1389
|
return new MemoryDeleteTool(ctx, params);
|
|
1398
1390
|
}
|
|
1399
1391
|
});
|
|
@@ -1424,7 +1416,7 @@ var MemorySearchTool = class extends import_tools.StructuredTool {
|
|
|
1424
1416
|
async _call(input, _, config) {
|
|
1425
1417
|
try {
|
|
1426
1418
|
const result = await this.ctx.chatluna_long_memory.retrieveMemory(
|
|
1427
|
-
config.
|
|
1419
|
+
config.configurable.conversationId,
|
|
1428
1420
|
input.content,
|
|
1429
1421
|
input.layer != null ? input.layer.map(
|
|
1430
1422
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1489,7 +1481,7 @@ var MemoryAddTool = class extends import_tools.StructuredTool {
|
|
|
1489
1481
|
};
|
|
1490
1482
|
});
|
|
1491
1483
|
await this.ctx.chatluna_long_memory.addMemories(
|
|
1492
|
-
config.
|
|
1484
|
+
config.configurable.conversationId,
|
|
1493
1485
|
enhancedMemories,
|
|
1494
1486
|
input.layer != null ? input.layer.map(
|
|
1495
1487
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1544,7 +1536,7 @@ var MemoryDeleteTool = class extends import_tools.StructuredTool {
|
|
|
1544
1536
|
async _call(input, _, config) {
|
|
1545
1537
|
try {
|
|
1546
1538
|
await this.ctx.chatluna_long_memory.deleteMemories(
|
|
1547
|
-
config.
|
|
1539
|
+
config.configurable.conversationId,
|
|
1548
1540
|
input.memoryIds,
|
|
1549
1541
|
input.layer != null ? input.layer.map(
|
|
1550
1542
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1592,8 +1584,8 @@ async function plugins(ctx, parent, plugin) {
|
|
|
1592
1584
|
__name(plugins, "plugins");
|
|
1593
1585
|
|
|
1594
1586
|
// src/service/memory.ts
|
|
1595
|
-
var
|
|
1596
|
-
var ChatLunaLongMemoryService = class extends
|
|
1587
|
+
var import_koishi = require("koishi");
|
|
1588
|
+
var ChatLunaLongMemoryService = class extends import_koishi.Service {
|
|
1597
1589
|
constructor(ctx, config) {
|
|
1598
1590
|
super(ctx, "chatluna_long_memory", true);
|
|
1599
1591
|
this.ctx = ctx;
|
|
@@ -1703,7 +1695,6 @@ function apply9(ctx, config) {
|
|
|
1703
1695
|
false
|
|
1704
1696
|
);
|
|
1705
1697
|
ctx.on("ready", async () => {
|
|
1706
|
-
plugin.registerToService();
|
|
1707
1698
|
ctx.plugin(ChatLunaLongMemoryService, config);
|
|
1708
1699
|
ctx.inject(["chatluna_long_memory"], (ctx2) => {
|
|
1709
1700
|
ctx2.on("ready", async () => {
|
|
@@ -1713,23 +1704,23 @@ function apply9(ctx, config) {
|
|
|
1713
1704
|
});
|
|
1714
1705
|
}
|
|
1715
1706
|
__name(apply9, "apply");
|
|
1716
|
-
var Config7 =
|
|
1717
|
-
|
|
1718
|
-
longMemoryInterval:
|
|
1719
|
-
longMemoryNewQuestionSearch:
|
|
1720
|
-
longMemorySimilarity:
|
|
1721
|
-
longMemoryTFIDFThreshold:
|
|
1722
|
-
longMemoryDuplicateCheck:
|
|
1723
|
-
longMemoryDuplicateThreshold:
|
|
1724
|
-
longMemoryLayer:
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1707
|
+
var Config7 = import_koishi2.Schema.intersect([
|
|
1708
|
+
import_koishi2.Schema.object({
|
|
1709
|
+
longMemoryInterval: import_koishi2.Schema.number().default(3).min(1).max(10),
|
|
1710
|
+
longMemoryNewQuestionSearch: import_koishi2.Schema.boolean().default(false),
|
|
1711
|
+
longMemorySimilarity: import_koishi2.Schema.percent().min(0).max(1).step(0.01).default(0.3),
|
|
1712
|
+
longMemoryTFIDFThreshold: import_koishi2.Schema.percent().min(0).max(1).step(0.01).default(0),
|
|
1713
|
+
longMemoryDuplicateCheck: import_koishi2.Schema.boolean().default(true),
|
|
1714
|
+
longMemoryDuplicateThreshold: import_koishi2.Schema.percent().min(0).max(1).step(0.01).default(0.8),
|
|
1715
|
+
longMemoryLayer: import_koishi2.Schema.array(
|
|
1716
|
+
import_koishi2.Schema.union([
|
|
1717
|
+
import_koishi2.Schema.const("Global"),
|
|
1718
|
+
import_koishi2.Schema.const("Preset"),
|
|
1719
|
+
import_koishi2.Schema.const("Preset_User"),
|
|
1720
|
+
import_koishi2.Schema.const("User")
|
|
1730
1721
|
])
|
|
1731
1722
|
).role("checkbox").default(["Preset_User"]),
|
|
1732
|
-
longMemoryExtractModel:
|
|
1723
|
+
longMemoryExtractModel: import_koishi2.Schema.dynamic("model").default("无")
|
|
1733
1724
|
})
|
|
1734
1725
|
]).i18n({
|
|
1735
1726
|
"zh-CN": require_zh_CN_schema(),
|
package/lib/index.mjs
CHANGED
|
@@ -20,7 +20,7 @@ var require_en_US_schema = __commonJS({
|
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
// src/index.ts
|
|
23
|
-
import { Schema
|
|
23
|
+
import { Schema } from "koishi";
|
|
24
24
|
import { ChatLunaPlugin } from "koishi-plugin-chatluna/services/chat";
|
|
25
25
|
import { createLogger } from "koishi-plugin-chatluna/utils/logger";
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ import { logger as logger3 } from "koishi-plugin-chatluna";
|
|
|
29
29
|
import { ChainMiddlewareRunStatus } from "koishi-plugin-chatluna/chains";
|
|
30
30
|
|
|
31
31
|
// src/utils/layer.ts
|
|
32
|
-
import { ChatLunaSaveableVectorStore } from "koishi-plugin-chatluna/llm-core/
|
|
32
|
+
import { ChatLunaSaveableVectorStore } from "koishi-plugin-chatluna/llm-core/vectorstores";
|
|
33
33
|
|
|
34
34
|
// src/utils/similarity.ts
|
|
35
35
|
import { cut } from "jieba-wasm";
|
|
@@ -485,6 +485,13 @@ var VectorStoreMemoryLayer = class extends BaseMemoryRetrievalLayer {
|
|
|
485
485
|
this.vectorStore = this.retriever.vectorStore;
|
|
486
486
|
}
|
|
487
487
|
async retrieveMemory(searchContent) {
|
|
488
|
+
if (!this.vectorStore) {
|
|
489
|
+
logger2?.warn("Vector store not initialized");
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (!this.vectorStore.checkActive(false)) {
|
|
493
|
+
await this.initialize();
|
|
494
|
+
}
|
|
488
495
|
let memory = await this.retriever.invoke(searchContent);
|
|
489
496
|
if (this.config.longMemoryTFIDFThreshold > 0) {
|
|
490
497
|
memory = filterSimilarMemoryByBM25(
|
|
@@ -524,6 +531,9 @@ var VectorStoreMemoryLayer = class extends BaseMemoryRetrievalLayer {
|
|
|
524
531
|
if (!this.vectorStore) {
|
|
525
532
|
return;
|
|
526
533
|
}
|
|
534
|
+
if (!this.vectorStore.checkActive(false)) {
|
|
535
|
+
await this.initialize();
|
|
536
|
+
}
|
|
527
537
|
await this.vectorStore.delete({ deleteAll: true });
|
|
528
538
|
}
|
|
529
539
|
async deleteMemories(memoryIds) {
|
|
@@ -571,7 +581,7 @@ async function createVectorStoreRetriever(ctx, config, longMemoryId) {
|
|
|
571
581
|
const [platform, model] = parseRawModelName(
|
|
572
582
|
ctx.chatluna.config.defaultEmbeddings
|
|
573
583
|
);
|
|
574
|
-
const embeddingModel = await ctx.chatluna.createEmbeddings(platform, model);
|
|
584
|
+
const embeddingModel = await ctx.chatluna.createEmbeddings(platform, model).then((model2) => model2.value);
|
|
575
585
|
const vectorStore = await ctx.chatluna.platform.createVectorStore(
|
|
576
586
|
ctx.chatluna.config.defaultVectorStore,
|
|
577
587
|
{
|
|
@@ -873,7 +883,7 @@ async function generateNewQuestion(ctx, config, chatHistory, question) {
|
|
|
873
883
|
const [platform, modelName] = parseRawModelName2(
|
|
874
884
|
config.longMemoryExtractModel
|
|
875
885
|
);
|
|
876
|
-
const model = await ctx.chatluna.createChatModel(platform, modelName);
|
|
886
|
+
const model = await ctx.chatluna.createChatModel(platform, modelName).then((model2) => model2.value);
|
|
877
887
|
const prompt = `
|
|
878
888
|
Given the following conversation history and the user's question, generate a new search query that will help retrieve relevant information from a long-term memory database. The search query should be concise and focused on the key information needs.
|
|
879
889
|
|
|
@@ -909,10 +919,7 @@ async function extractMemoriesFromChat(ctx, config, chatInterface, chatHistory)
|
|
|
909
919
|
const [platform, modelName] = parseRawModelName2(
|
|
910
920
|
config.longMemoryExtractModel
|
|
911
921
|
);
|
|
912
|
-
const model = await ctx.chatluna.createChatModel(
|
|
913
|
-
platform,
|
|
914
|
-
modelName
|
|
915
|
-
);
|
|
922
|
+
const model = await ctx.chatluna.createChatModel(platform, modelName).then((model2) => model2.value);
|
|
916
923
|
const extractMemory = /* @__PURE__ */ __name(async () => {
|
|
917
924
|
const result = await model.invoke(input);
|
|
918
925
|
logger2?.debug(`Long memory extract model result: ${result.content}`);
|
|
@@ -1132,26 +1139,11 @@ function apply3(ctx, config) {
|
|
|
1132
1139
|
__name(apply3, "apply");
|
|
1133
1140
|
|
|
1134
1141
|
// src/plugins/config.ts
|
|
1135
|
-
import {
|
|
1136
|
-
import { ModelType } from "koishi-plugin-chatluna/llm-core/platform/types";
|
|
1142
|
+
import { modelSchema } from "koishi-plugin-chatluna/utils/schema";
|
|
1137
1143
|
async function apply4(ctx, config) {
|
|
1138
|
-
ctx
|
|
1139
|
-
ctx.schema.set("model", Schema.union(getModelNames(service)));
|
|
1140
|
-
});
|
|
1141
|
-
ctx.on("chatluna/model-removed", (service) => {
|
|
1142
|
-
ctx.schema.set("model", Schema.union(getModelNames(service)));
|
|
1143
|
-
});
|
|
1144
|
-
ctx.schema.set("model", Schema.union(getModelNames(ctx.chatluna.platform)));
|
|
1144
|
+
modelSchema(ctx);
|
|
1145
1145
|
}
|
|
1146
1146
|
__name(apply4, "apply");
|
|
1147
|
-
function getModelNames(service) {
|
|
1148
|
-
const models = service.getAllModels(ModelType.llm).map((m) => Schema.const(m));
|
|
1149
|
-
if (models.length < 1) {
|
|
1150
|
-
models.push(Schema.const("无"));
|
|
1151
|
-
}
|
|
1152
|
-
return models;
|
|
1153
|
-
}
|
|
1154
|
-
__name(getModelNames, "getModelNames");
|
|
1155
1147
|
|
|
1156
1148
|
// src/plugins/delete_memory.ts
|
|
1157
1149
|
import { logger as logger6 } from "koishi-plugin-chatluna";
|
|
@@ -1343,7 +1335,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1343
1335
|
selector(history) {
|
|
1344
1336
|
return true;
|
|
1345
1337
|
},
|
|
1346
|
-
|
|
1338
|
+
createTool(params) {
|
|
1347
1339
|
return new MemorySearchTool(ctx, params);
|
|
1348
1340
|
}
|
|
1349
1341
|
});
|
|
@@ -1351,7 +1343,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1351
1343
|
selector(history) {
|
|
1352
1344
|
return true;
|
|
1353
1345
|
},
|
|
1354
|
-
|
|
1346
|
+
createTool(params) {
|
|
1355
1347
|
return new MemoryAddTool(ctx, params);
|
|
1356
1348
|
}
|
|
1357
1349
|
});
|
|
@@ -1359,7 +1351,7 @@ async function apply8(ctx, config, plugin) {
|
|
|
1359
1351
|
selector(history) {
|
|
1360
1352
|
return true;
|
|
1361
1353
|
},
|
|
1362
|
-
|
|
1354
|
+
createTool(params) {
|
|
1363
1355
|
return new MemoryDeleteTool(ctx, params);
|
|
1364
1356
|
}
|
|
1365
1357
|
});
|
|
@@ -1390,7 +1382,7 @@ var MemorySearchTool = class extends StructuredTool {
|
|
|
1390
1382
|
async _call(input, _, config) {
|
|
1391
1383
|
try {
|
|
1392
1384
|
const result = await this.ctx.chatluna_long_memory.retrieveMemory(
|
|
1393
|
-
config.
|
|
1385
|
+
config.configurable.conversationId,
|
|
1394
1386
|
input.content,
|
|
1395
1387
|
input.layer != null ? input.layer.map(
|
|
1396
1388
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1455,7 +1447,7 @@ var MemoryAddTool = class extends StructuredTool {
|
|
|
1455
1447
|
};
|
|
1456
1448
|
});
|
|
1457
1449
|
await this.ctx.chatluna_long_memory.addMemories(
|
|
1458
|
-
config.
|
|
1450
|
+
config.configurable.conversationId,
|
|
1459
1451
|
enhancedMemories,
|
|
1460
1452
|
input.layer != null ? input.layer.map(
|
|
1461
1453
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1510,7 +1502,7 @@ var MemoryDeleteTool = class extends StructuredTool {
|
|
|
1510
1502
|
async _call(input, _, config) {
|
|
1511
1503
|
try {
|
|
1512
1504
|
await this.ctx.chatluna_long_memory.deleteMemories(
|
|
1513
|
-
config.
|
|
1505
|
+
config.configurable.conversationId,
|
|
1514
1506
|
input.memoryIds,
|
|
1515
1507
|
input.layer != null ? input.layer.map(
|
|
1516
1508
|
(layer) => MemoryRetrievalLayerType[layer.toUpperCase()]
|
|
@@ -1669,7 +1661,6 @@ function apply9(ctx, config) {
|
|
|
1669
1661
|
false
|
|
1670
1662
|
);
|
|
1671
1663
|
ctx.on("ready", async () => {
|
|
1672
|
-
plugin.registerToService();
|
|
1673
1664
|
ctx.plugin(ChatLunaLongMemoryService, config);
|
|
1674
1665
|
ctx.inject(["chatluna_long_memory"], (ctx2) => {
|
|
1675
1666
|
ctx2.on("ready", async () => {
|
|
@@ -1679,23 +1670,23 @@ function apply9(ctx, config) {
|
|
|
1679
1670
|
});
|
|
1680
1671
|
}
|
|
1681
1672
|
__name(apply9, "apply");
|
|
1682
|
-
var Config7 =
|
|
1683
|
-
|
|
1684
|
-
longMemoryInterval:
|
|
1685
|
-
longMemoryNewQuestionSearch:
|
|
1686
|
-
longMemorySimilarity:
|
|
1687
|
-
longMemoryTFIDFThreshold:
|
|
1688
|
-
longMemoryDuplicateCheck:
|
|
1689
|
-
longMemoryDuplicateThreshold:
|
|
1690
|
-
longMemoryLayer:
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1673
|
+
var Config7 = Schema.intersect([
|
|
1674
|
+
Schema.object({
|
|
1675
|
+
longMemoryInterval: Schema.number().default(3).min(1).max(10),
|
|
1676
|
+
longMemoryNewQuestionSearch: Schema.boolean().default(false),
|
|
1677
|
+
longMemorySimilarity: Schema.percent().min(0).max(1).step(0.01).default(0.3),
|
|
1678
|
+
longMemoryTFIDFThreshold: Schema.percent().min(0).max(1).step(0.01).default(0),
|
|
1679
|
+
longMemoryDuplicateCheck: Schema.boolean().default(true),
|
|
1680
|
+
longMemoryDuplicateThreshold: Schema.percent().min(0).max(1).step(0.01).default(0.8),
|
|
1681
|
+
longMemoryLayer: Schema.array(
|
|
1682
|
+
Schema.union([
|
|
1683
|
+
Schema.const("Global"),
|
|
1684
|
+
Schema.const("Preset"),
|
|
1685
|
+
Schema.const("Preset_User"),
|
|
1686
|
+
Schema.const("User")
|
|
1696
1687
|
])
|
|
1697
1688
|
).role("checkbox").default(["Preset_User"]),
|
|
1698
|
-
longMemoryExtractModel:
|
|
1689
|
+
longMemoryExtractModel: Schema.dynamic("model").default("无")
|
|
1699
1690
|
})
|
|
1700
1691
|
]).i18n({
|
|
1701
1692
|
"zh-CN": require_zh_CN_schema(),
|
package/lib/plugins/tool.d.ts
CHANGED
|
@@ -15,10 +15,10 @@ export declare class MemorySearchTool extends StructuredTool {
|
|
|
15
15
|
layer: z.ZodArray<z.ZodUnion<[z.ZodLiteral<"user">, z.ZodLiteral<"preset_user">, z.ZodLiteral<"preset">, z.ZodLiteral<"global">]>, "many">;
|
|
16
16
|
}, "strip", z.ZodTypeAny, {
|
|
17
17
|
content?: string;
|
|
18
|
-
layer?: ("
|
|
18
|
+
layer?: ("user" | "preset_user" | "preset" | "global")[];
|
|
19
19
|
}, {
|
|
20
20
|
content?: string;
|
|
21
|
-
layer?: ("
|
|
21
|
+
layer?: ("user" | "preset_user" | "preset" | "global")[];
|
|
22
22
|
}>;
|
|
23
23
|
constructor(ctx: Context, params: CreateToolParams);
|
|
24
24
|
/** @ignore */
|
|
@@ -35,28 +35,28 @@ export declare class MemoryAddTool extends StructuredTool {
|
|
|
35
35
|
type: z.ZodNativeEnum<typeof MemoryType>;
|
|
36
36
|
importance: z.ZodNumber;
|
|
37
37
|
}, "strip", z.ZodTypeAny, {
|
|
38
|
-
importance?: number;
|
|
39
|
-
type?: MemoryType;
|
|
40
38
|
content?: string;
|
|
41
|
-
}, {
|
|
42
|
-
importance?: number;
|
|
43
39
|
type?: MemoryType;
|
|
40
|
+
importance?: number;
|
|
41
|
+
}, {
|
|
44
42
|
content?: string;
|
|
43
|
+
type?: MemoryType;
|
|
44
|
+
importance?: number;
|
|
45
45
|
}>, "many">;
|
|
46
46
|
layer: z.ZodArray<z.ZodUnion<[z.ZodLiteral<"user">, z.ZodLiteral<"preset_user">, z.ZodLiteral<"preset">, z.ZodLiteral<"global">]>, "many">;
|
|
47
47
|
}, "strip", z.ZodTypeAny, {
|
|
48
|
-
layer?: ("
|
|
48
|
+
layer?: ("user" | "preset_user" | "preset" | "global")[];
|
|
49
49
|
memories?: {
|
|
50
|
-
importance?: number;
|
|
51
|
-
type?: MemoryType;
|
|
52
50
|
content?: string;
|
|
51
|
+
type?: MemoryType;
|
|
52
|
+
importance?: number;
|
|
53
53
|
}[];
|
|
54
54
|
}, {
|
|
55
|
-
layer?: ("
|
|
55
|
+
layer?: ("user" | "preset_user" | "preset" | "global")[];
|
|
56
56
|
memories?: {
|
|
57
|
-
importance?: number;
|
|
58
|
-
type?: MemoryType;
|
|
59
57
|
content?: string;
|
|
58
|
+
type?: MemoryType;
|
|
59
|
+
importance?: number;
|
|
60
60
|
}[];
|
|
61
61
|
}>;
|
|
62
62
|
constructor(ctx: Context, params: CreateToolParams);
|
package/lib/utils/layer.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Config } from '..';
|
|
2
2
|
import { VectorStoreRetriever } from '@langchain/core/vectorstores';
|
|
3
|
-
import { ChatLunaSaveableVectorStore } from 'koishi-plugin-chatluna/llm-core/
|
|
3
|
+
import { ChatLunaSaveableVectorStore } from 'koishi-plugin-chatluna/llm-core/vectorstores';
|
|
4
4
|
import { Context } from 'koishi';
|
|
5
5
|
import { EnhancedMemory, MemoryRetrievalLayerInfo, MemoryRetrievalLayerType } from '../types';
|
|
6
6
|
interface MemoryRetrievalLayer {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-long-memory",
|
|
3
3
|
"description": "long memory for chatluna",
|
|
4
|
-
"version": "1.2.
|
|
4
|
+
"version": "1.2.8",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -63,20 +63,20 @@
|
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"koishi": "^4.18.7",
|
|
66
|
-
"koishi-plugin-chatluna": "^1.3.0-alpha.
|
|
66
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.42"
|
|
67
67
|
},
|
|
68
68
|
"resolutions": {
|
|
69
69
|
"@langchain/core": "0.3.62",
|
|
70
|
-
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.
|
|
70
|
+
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
71
71
|
},
|
|
72
72
|
"overrides": {
|
|
73
73
|
"@langchain/core": "0.3.62",
|
|
74
|
-
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.
|
|
74
|
+
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
75
75
|
},
|
|
76
76
|
"pnpm": {
|
|
77
77
|
"overrides": {
|
|
78
78
|
"@langchain/core": "0.3.62",
|
|
79
|
-
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.
|
|
79
|
+
"js-tiktoken": "npm:@dingyi222666/js-tiktoken@^1.0.21"
|
|
80
80
|
}
|
|
81
81
|
},
|
|
82
82
|
"koishi": {
|