alemonjs-aichat 1.0.10 → 1.0.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/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- ## 安装
2
+ ## 1.安装
3
3
 
4
4
  ### yarn安装方式(推荐)
5
5
 
@@ -19,14 +19,14 @@ https://gitee.com/suancaixianyu/alemonjs-aichat.git
19
19
  release
20
20
  ```
21
21
 
22
- ## 配置`alemon.config.yaml`
22
+ ## 2.配置`alemon.config.yaml`
23
23
  在配置中添加该插件, 使用`ALemonDesk`只需要启用插件即可
24
24
  ``` yaml
25
25
  app:
26
26
  - 'alemonjs-aichat'
27
27
  ```
28
28
 
29
- ## 配置redis
29
+ ## 3.配置redis
30
30
  `alemon.config.yaml`
31
31
  ``` yaml
32
32
  redis:
@@ -36,5 +36,20 @@ redis:
36
36
 
37
37
  ```
38
38
 
39
- ## 使用
40
- 指令`/ai帮助`查看使用方法
39
+ ## 4.使用
40
+
41
+ 需要先使用`#添加ai`,配置一个ai后才能使用对话功能
42
+
43
+ |指令|作用|
44
+ |---|---|
45
+ |#添加ai|添加一个ai, 重名时更新|
46
+ |#切换ai|切换一个ai配置并保留当前对话|
47
+ |#开启对话|在当前位置启用ai聊天|
48
+ |#ai配置|显示当前使用的配置|
49
+ |#添加提示词|添加一个提示词|
50
+ |#提示词列表|查看当前配置的所有提示词|
51
+ |#切换提示词|切换一个提示词并保留当前对话|
52
+ |#清空对话|清空当前对话并保留好感度|
53
+ |#开启好感度|好感度会影响回复时的语气|
54
+ |#好感度|查看自己的好感度|
55
+ |#ai帮助|查看更多指令|
package/lib/config.js CHANGED
@@ -213,7 +213,7 @@ const tools = [
213
213
  type: "function",
214
214
  function: {
215
215
  name: "StableDiffusionImageToPrompt",
216
- description: "使用 Stable Diffusion 将图片转换为提示词",
216
+ description: "使用 Stable Diffusion 将图片转换为提示词, 仅供绘图时使用, 其他场景请勿使用",
217
217
  parameters: {
218
218
  type: "object",
219
219
  properties: {
@@ -98,6 +98,22 @@ var mw = onMiddleware(selects, async (event, next) => {
98
98
  nickname: event.value.toUser.nickname,
99
99
  user_id: event.value.toUser.id,
100
100
  }; // 机器人信息
101
+ event["raw_message"] = event.value.content
102
+ .map((item) => {
103
+ if (item.type === "text") {
104
+ return item.data.text;
105
+ }
106
+ else if (item.type === "image") {
107
+ return `[CQ:image,${item.data.url}]`;
108
+ }
109
+ else if (item.type === "at") {
110
+ return `[CQ:at,qq=${item.data.id}]`;
111
+ }
112
+ else {
113
+ return `[${item.type.toUpperCase()}]`;
114
+ }
115
+ })
116
+ .join("");
101
117
  }
102
118
  console.log("处理后的事件", JSON.stringify(event, null, 2));
103
119
  // 常用于兼容其他框架或增强event功能
@@ -8,7 +8,8 @@ const regular$2 = /(\/|#)ai列表$/i;
8
8
  const regular$3 = /(\/|#)提示词列表$/i;
9
9
  const regular$4 = /(\/|#)清空对话$/i;
10
10
  const regular$5 = /(\/|#)清空(所有|全部)对话$/i;
11
- const regular = Regular.or(regular$1, regular$2, regular$3, regular$4, regular$5);
11
+ const get = /(\/|#)get (.+)$/i;
12
+ const regular = Regular.or(regular$1, regular$2, regular$3, regular$4, regular$5, get);
12
13
  var res = onResponse(selects, async (e, next) => {
13
14
  // 创建
14
15
  const [message] = useMessage(e);
@@ -38,6 +39,23 @@ var res = onResponse(selects, async (e, next) => {
38
39
  await clearAIChatHistory();
39
40
  message.send(format(Text("所有对话已清空")));
40
41
  }
42
+ // get请求一个地址
43
+ if (get.test(e.msg)) {
44
+ const match = e.msg.match(get);
45
+ if (!match) {
46
+ message.send(format(Text("格式错误,请按照 格式:/get <url> 进行请求")));
47
+ return;
48
+ }
49
+ const [, , url] = match;
50
+ try {
51
+ const res = await fetch(url);
52
+ const text = await res.text();
53
+ message.send(format(Text(`GET ${url} 的响应:\n${text}`)));
54
+ }
55
+ catch (error) {
56
+ message.send(format(Text(`请求 ${url} 失败:${error}`)));
57
+ }
58
+ }
41
59
  next();
42
60
  });
43
61
 
@@ -27,7 +27,7 @@ var res = onResponse(selects, async (e, next) => {
27
27
  const historyMessages = await getAIChatHistory(e.guid);
28
28
  const affections = await getAffectionLevelAll(e.guid);
29
29
  const imgs = [];
30
- let rawMessage = e.value.raw_message || e.msg;
30
+ let rawMessage = e.value.raw_message || e.raw_message || e.msg;
31
31
  // 好感度开关
32
32
  const affectionIsOpen = (await redis.get(`ai:affection:switch:${e.guid}`)) || "1";
33
33
  const botName = e.bot.nickname || "小咸鱼";
@@ -41,6 +41,7 @@ var res = onResponse(selects, async (e, next) => {
41
41
  如果你在使用画图工具后需要回复图片, 可在消息中追加image_url, 例如:
42
42
  [{'assistant':'画好啦','image_url':'图片地址'}]
43
43
  注意:图片地址必须是接口返回的完整地址, 通常是相对路径
44
+ 注意:你的回复中除了json必要的双引号之外, 不要再添加多余的双引号, 否则会导致解析失败, 需要在回复内容中使用单引号来表示字符串, 例如: [{"assistant":"这是一个'引号'的例子"}]
44
45
  ` +
45
46
  (affectionIsOpen === "1"
46
47
  ? `当你认为对方在示好或骂你时,可添加{affections:数字}表示好感度变化,你可以根据好感度来适当改变回复语气.
@@ -209,8 +210,10 @@ var res = onResponse(selects, async (e, next) => {
209
210
  }
210
211
  }
211
212
  // 如果没有工具调用,处理最终回复
212
- const reply = res.choices?.[0]?.message?.content?.trim().replace(/'/g, '"') || "";
213
+ let reply = res.choices?.[0]?.message?.content?.trim().replace(/'/g, '"') || "";
213
214
  log("AI回复内容:", reply);
215
+ // 修复assistant字段中多余的双引号
216
+ reply = reply.replace(/(?<="assistant":")(.*?)(?="[,}])/, (match) => match.replace(/"/g, "'"));
214
217
  // 提取好感变化, 使用incrementAffectionLevel更新好感
215
218
  if (affectionIsOpen === "1") {
216
219
  let affectionUpdated = false;
package/lib/s3.js CHANGED
@@ -44,7 +44,7 @@ const uploadImageToR2 = async (source, key) => {
44
44
  // 1. 处理不同来源 → 统一得到 Buffer + contentType + fileName
45
45
  if (source.startsWith("http://") || source.startsWith("https://")) {
46
46
  // 远程 URL
47
- const response = await fetch(source);
47
+ const response = await fetch(source.replace("!/fwfh/368x238", ""));
48
48
  if (!response.ok)
49
49
  throw new Error(`下载图片失败: ${response.statusText}`);
50
50
  buffer = Buffer.from(await response.arrayBuffer());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alemonjs-aichat",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "alemonjs-aichat",
5
5
  "author": "suancaixianyu",
6
6
  "license": "MIT",
@@ -45,11 +45,6 @@
45
45
  "type": "gitee",
46
46
  "url": "https://gitee.com/suancaixianyu/alemonjs-aichat.git"
47
47
  },
48
- "files": [
49
- "lib/**/*",
50
- "public/**/*",
51
- "config/**/*"
52
- ],
53
48
  "keywords": [
54
49
  "alemonjs"
55
50
  ],
@@ -77,4 +72,4 @@
77
72
  "mime-types": "^3.0.2",
78
73
  "openai": "^6.16.0"
79
74
  }
80
- }
75
+ }