koishi-plugin-satori-ai 1.0.2 → 1.0.4

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.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { Context, segment, Element, Session, Next, Fragment } from 'koishi';
2
2
  import { Sat } from './type';
3
- export declare const usage = "\u4F7F\u7528\u8BF4\u660E\u89C1\u63D2\u4EF6\u4E3B\u9875";
4
3
  type ChatCallback = (session: Session, session_of_id: Sat.Msg[]) => Promise<string>;
5
4
  declare module 'koishi' {
6
5
  interface Context {
package/lib/index.js CHANGED
@@ -40,8 +40,7 @@ var require_zh = __commonJS({
40
40
  // src/index.tsx
41
41
  var src_exports = {};
42
42
  __export(src_exports, {
43
- default: () => src_default,
44
- usage: () => usage
43
+ default: () => src_default
45
44
  });
46
45
  module.exports = __toCommonJS(src_exports);
47
46
  var import_koishi2 = require("koishi");
@@ -121,10 +120,9 @@ var Sat = class extends import_koishi.Service {
121
120
  // src/index.tsx
122
121
  var fs = __toESM(require("fs"));
123
122
  var path = __toESM(require("path"));
124
- var usage = `使用说明见插件主页`;
125
123
  var name = "satori-ai";
126
124
  var logger = new import_koishi2.Logger(name);
127
- var debug = 0;
125
+ var debug = 1;
128
126
  var SAt = class extends Sat {
129
127
  static {
130
128
  __name(this, "SAt");
@@ -234,7 +232,7 @@ var SAt = class extends Sat {
234
232
  return session.text("commands.sat.messages.duplicate-dialogue");
235
233
  }
236
234
  this.personality["人格"][0].content += "\n这是刚刚的对话内容:{\n" + recentDialogues.map((msg) => `${msg.role}: ${msg.content}`).join("\n") + "\n}";
237
- const charactersToRemove = ["的", "一", "是", "了", "什", "么", "我", "谁", "不", "人", "在", "他", "有", "这", "个", "上", "们", "来", "到", "时", "大", "地", "为", "子", "中", "你", "说", "生", "国", "年", "着", "就", "那", "和", "要", "她", "出", "也", "得", "里", "后", "自", "以", "会"];
235
+ const charactersToRemove = ["的", "一", "是", "了", "什", "么", "我", "谁", "不", "人", "在", "他", "有", "这", "个", "上", "们", "来", "到", "时", "大", "地", "为", "子", "中", "你", "说", "生", "国", "年", "着", "就", "那", "和", "要", "她", "出", "也", "得", "里", "后", "自", "以", "会", "id=", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
238
236
  const filePath = path.join(this.pluginConfig.dataDir, "dialogues", `${session.userId}.txt`);
239
237
  const notExists = await isTargetIdExists(this.ctx, session.userId);
240
238
  let tmp;
@@ -242,10 +240,11 @@ var SAt = class extends Sat {
242
240
  const user = await this.ctx.database.get("p_system", { userid: session.userId });
243
241
  tmp = (user[0].usersname + prompt).split("");
244
242
  } else {
245
- tmp = prompt.split("");
243
+ tmp = (session.username + prompt).split("");
246
244
  }
247
245
  const keywords = tmp.filter((word) => !charactersToRemove.includes(word));
248
246
  const fs2 = require("fs");
247
+ const USERID = [session.userId];
249
248
  let sortedMatches = searchKeywordsInFile(filePath, keywords);
250
249
  if (sortedMatches.length > 0) {
251
250
  this.personality["人格"][0].content += appendTopMatches(JSON.parse(fs2.readFileSync(filePath, "utf-8")), sortedMatches, 10, "这是你可能用到的较久之前的对话内容:");
@@ -260,13 +259,13 @@ var SAt = class extends Sat {
260
259
  }
261
260
  sortedMatches = searchKeywordsInFile(commonSenseFilePath, keywords);
262
261
  if (sortedMatches.length > 0) {
263
- this.personality["人格"][0].content += appendTopMatches(commonSenseContent, sortedMatches, 5, "这是你需要知道的信息:");
262
+ this.personality["人格"][0].content += appendTopMatches(commonSenseContent, sortedMatches, 10, "这是你需要知道的信息:");
264
263
  if (sortedMatches.length > 4) {
265
264
  for (let i = 0; i < 5; i++) {
266
265
  const matchContent = commonSenseContent[sortedMatches[i].index].content.split("").filter((word) => !charactersToRemove.includes(word));
267
266
  const reSortedMatches = searchKeywordsInFile(commonSenseFilePath, matchContent);
268
267
  if (reSortedMatches.length > 0) {
269
- this.personality["人格"][0].content += appendTopMatches(commonSenseContent, reSortedMatches, 3, `这是第${i + 1}条信息的补充信息:`);
268
+ this.personality["人格"][0].content += appendTopMatches(commonSenseContent, reSortedMatches, 3, `这是第${i + 1}条信息的补充信息:`, 1);
270
269
  }
271
270
  }
272
271
  }
@@ -293,44 +292,40 @@ var SAt = class extends Sat {
293
292
  level = levels[0];
294
293
  this.personality["人格"][0].content += `
295
294
  ${this.pluginConfig.prompt_0}
296
- 我的名字: ${user[0].usersname}`;
295
+ `;
297
296
  } else if (favorability < this.pluginConfig.favorability_div_2) {
298
297
  level = levels[1];
299
298
  this.personality["人格"][0].content += `
300
299
  ${this.pluginConfig.prompt_1}
301
- 我的名字: ${user[0].usersname}`;
300
+ `;
302
301
  } else if (favorability < this.pluginConfig.favorability_div_3) {
303
302
  level = levels[2];
304
303
  this.personality["人格"][0].content += `
305
304
  ${this.pluginConfig.prompt_2}
306
- 我的名字: ${user[0].usersname}`;
305
+ `;
307
306
  } else if (favorability < this.pluginConfig.favorability_div_4) {
308
307
  level = levels[3];
309
308
  this.personality["人格"][0].content += `
310
309
  ${this.pluginConfig.prompt_3}
311
- 我的名字: ${user[0].usersname}`;
310
+ `;
312
311
  } else {
313
312
  level = levels[4];
314
- const isPrivate = session.channelId.match(new RegExp("private", "g"))?.includes("private");
315
- if (isPrivate) {
316
- this.personality["人格"][0].content += `
313
+ this.personality["人格"][0].content += `
317
314
  ${this.pluginConfig.prompt_4}
318
315
  `;
319
- } else {
320
- this.personality["人格"][0].content += `
321
- ${this.pluginConfig.prompt_3}
322
- `;
323
- }
324
- this.personality["人格"][0].content += `我的名字: ${user[0].usersname}`;
325
316
  }
326
- logger.info(`名字: ${user[0].usersname}, 关系: ${level}`);
317
+ this.personality["人格"][0].content += `发言者的名字: ${session.username},发言者的id:${session.userId}`;
318
+ logger.info(`名字: ${session.username}, 关系: ${level}`);
327
319
  } else {
328
320
  this.personality["人格"][0].content += `
329
321
  ${this.pluginConfig.prompt_1}
330
- 我的名字: ${session.username}`;
322
+ 发言者的名字: ${session.username},发言者的id:${session.userId}`;
331
323
  logger.info(`名字: ${session.username}, 关系: 陌生`);
332
324
  }
333
325
  }
326
+ sortedMatches = searchKeywordsInFile(commonSenseFilePath, USERID);
327
+ if (sortedMatches.length > 0)
328
+ this.personality["人格"][0].content += appendTopMatches(commonSenseContent, sortedMatches, 1, "这是发言者的真实身份:");
334
329
  if (debug)
335
330
  logger.info(this.personality["人格"][0].content.slice(-1500));
336
331
  return await this.chat(censored_prompt, session.userId, session);
@@ -425,7 +420,6 @@ var SAt = class extends Sat {
425
420
  this.channelDialogues[channelId] = [];
426
421
  }
427
422
  this.channelDialogues[channelId].push({ "role": session.username, "content": msg });
428
- this.channelDialogues[channelId].push({ "role": "回复", "content": message });
429
423
  if (this.channelDialogues[channelId].length > this.pluginConfig.message_max_length) {
430
424
  this.channelDialogues[channelId].shift();
431
425
  }
@@ -537,8 +531,8 @@ function searchKeywordsInFile(filePath, keywords) {
537
531
  return sortedMatches;
538
532
  }
539
533
  __name(searchKeywordsInFile, "searchKeywordsInFile");
540
- function appendTopMatches(dialogues, sortedMatches, topN, prefix) {
541
- const topMatches = sortedMatches.slice(0, topN);
534
+ function appendTopMatches(dialogues, sortedMatches, topN, prefix, begin = 0) {
535
+ const topMatches = sortedMatches.slice(begin, topN);
542
536
  const personalityContent = `
543
537
  ${prefix}{
544
538
  ` + topMatches.map((item) => dialogues[item.index].content).join("\n") + "\n}";
@@ -567,7 +561,3 @@ async function getTimeOfDay() {
567
561
  }
568
562
  __name(getTimeOfDay, "getTimeOfDay");
569
563
  var src_default = SAt;
570
- // Annotate the CommonJS export names for ESM import in node:
571
- 0 && (module.exports = {
572
- usage
573
- });
package/lib/type.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Context, Dict, Schema, Service } from 'koishi';
2
+ export declare const usage = "\u4F7F\u7528\u8BF4\u660E\u89C1\u63D2\u4EF6\u4E3B\u9875";
2
3
  export declare class Sat extends Service {
3
4
  static inject: {
4
5
  required: string[];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-satori-ai",
3
- "description": "适用于satori的ai对话",
4
- "version": "1.0.2",
3
+ "description": "适用于satori的ai对话,具有长期记忆、常识写入和好感度功能,请务必使用最新版本",
4
+ "version": "1.0.4",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "types": "lib/index.d.ts",
@@ -32,7 +32,7 @@
32
32
  "koishi": "^4.17.10"
33
33
  },
34
34
  "koishi": {
35
- "description": "觉bot的ai聊天",
35
+ "description": "适用于satori的ai对话",
36
36
  "browser": true
37
37
  }
38
38
  }