wechaty-web-panel 1.6.31 → 1.6.33

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.
Files changed (30) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/src/botInstance/dify.js +5 -7
  3. package/dist/cjs/src/botInstance/gpt4v.d.ts +5 -0
  4. package/dist/cjs/src/botInstance/gpt4v.js +35 -0
  5. package/dist/cjs/src/botInstance/officialOpenAi.d.ts +4 -1
  6. package/dist/cjs/src/botInstance/officialOpenAi.js +21 -12
  7. package/dist/cjs/src/botInstance/sdk/chatGPT4V.d.ts +17 -0
  8. package/dist/cjs/src/botInstance/sdk/chatGPT4V.js +96 -0
  9. package/dist/cjs/src/botInstance/unOfficialOpenAi.js +6 -8
  10. package/dist/cjs/src/common/multiReply.d.ts +39 -0
  11. package/dist/cjs/src/common/multiReply.js +130 -0
  12. package/dist/cjs/src/handlers/on-message.js +70 -0
  13. package/dist/cjs/src/package-json.js +1 -1
  14. package/dist/cjs/src/service/gpt4vService.d.ts +12 -0
  15. package/dist/cjs/src/service/gpt4vService.js +71 -0
  16. package/dist/esm/src/botInstance/dify.js +5 -7
  17. package/dist/esm/src/botInstance/gpt4v.d.ts +5 -0
  18. package/dist/esm/src/botInstance/gpt4v.js +31 -0
  19. package/dist/esm/src/botInstance/officialOpenAi.d.ts +4 -1
  20. package/dist/esm/src/botInstance/officialOpenAi.js +21 -12
  21. package/dist/esm/src/botInstance/sdk/chatGPT4V.d.ts +17 -0
  22. package/dist/esm/src/botInstance/sdk/chatGPT4V.js +89 -0
  23. package/dist/esm/src/botInstance/unOfficialOpenAi.js +6 -8
  24. package/dist/esm/src/common/multiReply.d.ts +39 -0
  25. package/dist/esm/src/common/multiReply.js +127 -0
  26. package/dist/esm/src/handlers/on-message.js +70 -0
  27. package/dist/esm/src/package-json.js +1 -1
  28. package/dist/esm/src/service/gpt4vService.d.ts +12 -0
  29. package/dist/esm/src/service/gpt4vService.js +64 -0
  30. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.6.33(2023-12-07)
4
+ 1、优化FastGPT对话重置功能
5
+ 2、添加GPT-4V识图功能
6
+ 3、优化发送文字断行功能
7
+ 4、修复一个可能导致上下文重置的bug
8
+
3
9
  ### V1.6.31(2023-11-18)
4
10
  1、修复批量定时任务的查询逻辑
5
11
 
@@ -88,10 +88,8 @@ class DifyAi {
88
88
  }
89
89
  // 保存对话id 对于同一个用户的对话不更新conversationId
90
90
  if (!this.chatOption[uid]?.conversationId) {
91
- this.chatOption = {
92
- [uid]: {
93
- conversationId
94
- },
91
+ this.chatOption[uid] = {
92
+ conversationId
95
93
  };
96
94
  }
97
95
  let replys = [];
@@ -102,9 +100,9 @@ class DifyAi {
102
100
  else {
103
101
  message = text.replaceAll('\n', this.eol);
104
102
  }
105
- while (message.length > 500) {
106
- replys.push(message.slice(0, 500));
107
- message = message.slice(500);
103
+ while (message.length > 1000) {
104
+ replys.push(message.slice(0, 1000));
105
+ message = message.slice(1000);
108
106
  }
109
107
  replys.push(message);
110
108
  replys = replys.map(item => {
@@ -0,0 +1,5 @@
1
+ export function get4vReply(images: any, question: any, config: any): Promise<{
2
+ type: number;
3
+ content: any;
4
+ }[]>;
5
+ //# sourceMappingURL=gpt4v.d.ts.map
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get4vReply = void 0;
4
+ const chatGPT4V_js_1 = require("./sdk/chatGPT4V.js");
5
+ const puppet_type_js_1 = require("../const/puppet-type.js");
6
+ async function get4vReply(images, question, config) {
7
+ try {
8
+ const eol = await (0, puppet_type_js_1.getPuppetEol)();
9
+ const finalConfig = {
10
+ ...config,
11
+ baseUrl: config.proxyPass || ''
12
+ };
13
+ const { text } = await (0, chatGPT4V_js_1.getImageVision)(images, question, finalConfig);
14
+ let replys = [];
15
+ let message = text.replaceAll("\n", eol);
16
+ while (message.length > 1000) {
17
+ replys.push(message.slice(0, 1000));
18
+ message = message.slice(1000);
19
+ }
20
+ replys.push(message);
21
+ replys = replys.map(item => {
22
+ return {
23
+ type: 1,
24
+ content: item.trim()
25
+ };
26
+ });
27
+ return replys;
28
+ }
29
+ catch (e) {
30
+ console.log("gpt4v报错:" + e);
31
+ return [{ type: 1, content: '图像识别失败,请确保你的账号有GPT-4V权限' }];
32
+ }
33
+ }
34
+ exports.get4vReply = get4vReply;
35
+ //# sourceMappingURL=gpt4v.js.map
@@ -15,7 +15,10 @@ declare class OfficialOpenAi {
15
15
  _apiKey: any;
16
16
  _apiOrg: any;
17
17
  _apiBaseUrl: any;
18
- _debug: boolean;
18
+ _debug: boolean; /**
19
+ * 重置apikey
20
+ * @return {Promise<void>}
21
+ */
19
22
  _fetch: any;
20
23
  _completionParams: any;
21
24
  _systemMessage: any;
@@ -10,6 +10,7 @@ const aichatDb_js_1 = require("../db/aichatDb.js");
10
10
  const aibotk_js_1 = require("../proxy/aibotk.js");
11
11
  const contentCensor_js_1 = require("../lib/contentCensor.js");
12
12
  const puppet_type_js_1 = require("../const/puppet-type.js");
13
+ const uuid_1 = require("uuid");
13
14
  const dayjs_1 = __importDefault(require("dayjs"));
14
15
  let chatGPT = null;
15
16
  class OfficialOpenAi {
@@ -125,20 +126,23 @@ class OfficialOpenAi {
125
126
  return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
126
127
  }
127
128
  }
128
- if (systemMessage || content === 'reset' || content === '重置') {
129
+ const resetWord = ['reset', '重置', '重置对话', '忽略上下文', '重置上下文', '重新开始', '清除对话', '清除上下文'];
130
+ if (systemMessage || resetWord.includes(content)) {
129
131
  console.log('重新更新上下文对话');
130
- this.chatOption[uid] = {};
132
+ this.chatOption[uid] = null;
131
133
  if (content === 'reset' || content === '重置') {
132
134
  return [{ type: 1, content: '上下文已重置' }];
133
135
  }
134
136
  }
137
+ if (isFastGPT && !this.chatOption[uid]) {
138
+ this.chatOption[uid] = {
139
+ chatId: (0, uuid_1.v4)()
140
+ };
141
+ }
135
142
  const sendParams = { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
136
143
  if (systemMessage) {
137
144
  sendParams.systemMessage = systemMessage;
138
145
  }
139
- if (isFastGPT) {
140
- sendParams.chatId = uid;
141
- }
142
146
  const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
143
147
  if (this.config.filter) {
144
148
  const censor = await this.contentCensor.checkText(text);
@@ -150,12 +154,17 @@ class OfficialOpenAi {
150
154
  if (this.config.record) {
151
155
  void (0, aichatDb_js_1.addAichatRecord)({ contactId: uid, adminId, input: content, output: text, time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss') });
152
156
  }
153
- this.chatOption = {
154
- [uid]: {
157
+ if (isFastGPT) {
158
+ this.chatOption[uid] = {
159
+ chatId: this.chatOption[uid].chatId
160
+ };
161
+ }
162
+ else {
163
+ this.chatOption[uid] = {
155
164
  conversationId,
156
165
  parentMessageId: id,
157
- },
158
- };
166
+ };
167
+ }
159
168
  let replys = [];
160
169
  let message;
161
170
  if (this.config.showQuestion) {
@@ -164,9 +173,9 @@ class OfficialOpenAi {
164
173
  else {
165
174
  message = text.replaceAll('\n', this.eol);
166
175
  }
167
- while (message.length > 500) {
168
- replys.push(message.slice(0, 500));
169
- message = message.slice(500);
176
+ while (message.length > 1000) {
177
+ replys.push(message.slice(0, 1000));
178
+ message = message.slice(1000);
170
179
  }
171
180
  replys.push(message);
172
181
  replys = replys.map(item => {
@@ -0,0 +1,17 @@
1
+ export function getImageVision(images: any, question: any, config: any): Promise<{
2
+ text: any;
3
+ }>;
4
+ export const BASE_URL: "https://api.openai.com/v1";
5
+ export namespace routes {
6
+ namespace createVisionPreviewMessage {
7
+ const method: string;
8
+ function url(): string;
9
+ }
10
+ namespace createDellImage {
11
+ const method_1: string;
12
+ export { method_1 as method };
13
+ export function url_1(): string;
14
+ export { url_1 as url };
15
+ }
16
+ }
17
+ //# sourceMappingURL=chatGPT4V.d.ts.map
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getImageVision = exports.routes = exports.BASE_URL = void 0;
7
+ const axios_1 = __importDefault(require("axios"));
8
+ exports.BASE_URL = "https://api.openai.com/v1";
9
+ const GPT4VError = class extends Error {
10
+ };
11
+ exports.routes = {
12
+ createVisionPreviewMessage: {
13
+ method: "POST",
14
+ url: () => '/chat/completions'
15
+ },
16
+ createDellImage: {
17
+ method: "POST",
18
+ url: () => '/images/generations'
19
+ },
20
+ };
21
+ async function sendRequest({ method, endpoint, data, params, stream = false, timeoutMs = 180 * 1000, apiKey, baseUrl, debug }) {
22
+ const headers = {
23
+ "Authorization": `Bearer ${apiKey}`, "Content-Type": "application/json"
24
+ };
25
+ const url = `${baseUrl}${endpoint}`;
26
+ let response;
27
+ if (debug) {
28
+ console.log("gpt4v request", url, { data, headers, params });
29
+ }
30
+ response = await (0, axios_1.default)({
31
+ method,
32
+ url,
33
+ data: data || null,
34
+ params: params || null,
35
+ headers,
36
+ timeout: timeoutMs,
37
+ responseType: stream ? "stream" : "json"
38
+ });
39
+ return response;
40
+ }
41
+ async function getImageVision(images, question, config) {
42
+ const data = {
43
+ model: "gpt-4-vision-preview",
44
+ messages: [
45
+ {
46
+ role: "user",
47
+ content: [
48
+ {
49
+ type: "text",
50
+ text: question || "Please describe the content of the image in Chinese. If it contains any prohibited content, please refrain from describing it."
51
+ }
52
+ ]
53
+ }
54
+ ],
55
+ max_tokens: 300,
56
+ ...config.completionParams
57
+ };
58
+ for (let item of images) {
59
+ data.messages[0].content.push({
60
+ type: "image_url",
61
+ image_url: {
62
+ url: item
63
+ }
64
+ });
65
+ }
66
+ if (config.debug) {
67
+ console.log("request data", data);
68
+ }
69
+ const res = await sendRequest({
70
+ apiKey: config.apiKey,
71
+ debug: config.debug,
72
+ baseUrl: config.baseUrl || exports.BASE_URL,
73
+ method: exports.routes.createVisionPreviewMessage.method,
74
+ endpoint: exports.routes.createVisionPreviewMessage.url(),
75
+ data,
76
+ stream: false,
77
+ timeoutMs: config.timeoutMs * 1000
78
+ });
79
+ if (res.status !== 200) {
80
+ if (config.debug) {
81
+ console.log("gpt4v request error", res.data);
82
+ }
83
+ const reason = JSON.stringify(res.data);
84
+ const msg = `GPT4V error ${res.status}: ${reason}`;
85
+ const error = new GPT4VError(msg, { cause: res });
86
+ error.statusCode = res.status;
87
+ error.statusText = JSON.stringify(res.data);
88
+ return Promise.reject(res.message);
89
+ }
90
+ const response = res.data;
91
+ return {
92
+ text: response.choices[0].message.content
93
+ };
94
+ }
95
+ exports.getImageVision = getImageVision;
96
+ //# sourceMappingURL=chatGPT4V.js.map
@@ -101,11 +101,9 @@ class UnOfficialOpenAi {
101
101
  time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss')
102
102
  });
103
103
  }
104
- this.chatOption = {
105
- [uid]: {
106
- conversationId,
107
- parentMessageId: id,
108
- },
104
+ this.chatOption[uid] = {
105
+ conversationId,
106
+ parentMessageId: id,
109
107
  };
110
108
  let replys = [];
111
109
  let message;
@@ -115,9 +113,9 @@ class UnOfficialOpenAi {
115
113
  else {
116
114
  message = text.replaceAll('\n', this.eol);
117
115
  }
118
- while (message.length > 500) {
119
- replys.push(message.slice(0, 500));
120
- message = message.slice(500);
116
+ while (message.length > 1000) {
117
+ replys.push(message.slice(0, 1000));
118
+ message = message.slice(1000);
121
119
  }
122
120
  replys.push(message);
123
121
  replys = replys.map(item => {
@@ -0,0 +1,39 @@
1
+ export class BotManage {
2
+ constructor(maxuser: number | undefined, that: any);
3
+ Bot: any;
4
+ userBotDict: {};
5
+ userTimeDict: {};
6
+ maxuser: number;
7
+ creatBot(username: any, content: any): Promise<{
8
+ type: number;
9
+ content: any;
10
+ }[] | undefined>;
11
+ updateBot(username: any, content: any, config: any): Promise<{
12
+ type: number;
13
+ content: any;
14
+ }[] | undefined>;
15
+ talk(username: any, content: any, config: any): Promise<{
16
+ type: number;
17
+ content: any;
18
+ }[] | undefined>;
19
+ removeBot(uid: any): void;
20
+ getBotList(): {};
21
+ /**
22
+ * 识别图片内容
23
+ * @param {*} username 用户名
24
+ * @returns
25
+ */
26
+ generateImage(username: any, question: any, config: any): Promise<{
27
+ type: number;
28
+ content: any;
29
+ }[]>;
30
+ getImage(username: any, content: any, step: any): {
31
+ type: number;
32
+ content: string;
33
+ }[];
34
+ run(userId: any, content: any, config: any): Promise<{
35
+ type: number;
36
+ content: any;
37
+ }[] | undefined>;
38
+ }
39
+ //# sourceMappingURL=multiReply.d.ts.map
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BotManage = void 0;
4
+ const gpt4v_js_1 = require("../botInstance/gpt4v.js");
5
+ class MultiReply {
6
+ constructor() {
7
+ this.step = 0; // 当前step
8
+ this.stepRecord = []; // 经历过的step
9
+ this.imageIds = []; // 用户发送的图片消息id
10
+ }
11
+ paramsInit() {
12
+ this.step = 0; // 当前step
13
+ this.stepRecord = []; // 经历过的step
14
+ this.imageIds = []; // 用户发送的图片消息id
15
+ }
16
+ }
17
+ class BotManage {
18
+ constructor(maxuser = 50, that) {
19
+ this.Bot = that;
20
+ this.userBotDict = {}; // 存放所有对话的用户
21
+ this.userTimeDict = {};
22
+ this.maxuser = maxuser; // 最大同时处理的用户数
23
+ }
24
+ async creatBot(username, content) {
25
+ console.log("bot process create");
26
+ this.userBotDict[username] = new MultiReply();
27
+ this.userBotDict[username].userName = username;
28
+ this.userBotDict[username].imageIds = [content.id];
29
+ return await this.updateBot(username, content);
30
+ }
31
+ // 更新对话
32
+ async updateBot(username, content, config) {
33
+ console.log(`更新{${username}}对话`);
34
+ this.userTimeDict[username] = new Date().getTime();
35
+ return await this.talk(username, content, config);
36
+ }
37
+ async talk(username, content, config) {
38
+ if (this.userBotDict[username].step == 0) {
39
+ this.userBotDict[username].stepRecord.push(0);
40
+ if (content.type === 3) {
41
+ this.userBotDict[username].step += 1;
42
+ return [
43
+ { type: 1, content: `请描述你对图片的问题,最多支持5张图片,已收到${this.userBotDict[username].imageIds.length}张图片` }
44
+ ];
45
+ }
46
+ }
47
+ else if (this.userBotDict[username].step == 1) {
48
+ console.log("第二轮对话,用户输入了需要提问的内容");
49
+ this.userBotDict[username].stepRecord.push(1);
50
+ if (content.type === 1) {
51
+ // 用户选择了漫画模式
52
+ const res = await this.generateImage(username, content.content, config);
53
+ this.removeBot(username);
54
+ return res;
55
+ }
56
+ }
57
+ }
58
+ removeBot(uid) {
59
+ delete this.userTimeDict[uid];
60
+ delete this.userBotDict[uid];
61
+ }
62
+ getBotList() {
63
+ return this.userBotDict;
64
+ }
65
+ /**
66
+ * 识别图片内容
67
+ * @param {*} username 用户名
68
+ * @returns
69
+ */
70
+ async generateImage(username, question, config) {
71
+ const images = [];
72
+ for (let id of this.userBotDict[username].imageIds) {
73
+ const msg = await this.Bot.Message.find({ id });
74
+ const file = await msg.toFileBox();
75
+ const base = await file.toDataURL();
76
+ images.push(base);
77
+ }
78
+ const replys = await (0, gpt4v_js_1.get4vReply)(images, question, config);
79
+ return replys;
80
+ }
81
+ getImage(username, content, step) {
82
+ if (this.userBotDict[username].imageIds.length === 5) {
83
+ this.removeBot(username);
84
+ let replys = {
85
+ type: 1,
86
+ content: "本次对话已经重置,请重新发送图片"
87
+ };
88
+ return [replys];
89
+ }
90
+ this.userBotDict[username].step = step;
91
+ this.userBotDict[username].imageIds.push(content.id);
92
+ if (this.userBotDict[username].imageIds.length === 5) {
93
+ let replys = {
94
+ type: 1,
95
+ content: "已收到5张图片,请描述你的问题,再次发送图片将会重置本次对话"
96
+ };
97
+ return [replys];
98
+ }
99
+ let replys = {
100
+ type: 1,
101
+ content: `请描述你的问题,最多支持5张图片,已收到${this.userBotDict[username].imageIds.length}张图片`
102
+ };
103
+ return [replys];
104
+ }
105
+ // 对话入口
106
+ async run(userId, content, config) {
107
+ if (content.type === 1) {
108
+ if (Object.keys(this.userTimeDict).includes(userId)) {
109
+ return this.updateBot(userId, content, config);
110
+ }
111
+ return [];
112
+ }
113
+ else if (content.type === 3) {
114
+ if (Object.keys(this.userTimeDict).includes(userId)) {
115
+ return this.getImage(userId, content, 1);
116
+ }
117
+ else {
118
+ if (this.userBotDict.length > this.maxuser) {
119
+ const minNum = Math.min(...Object.values(this.userTimeDict));
120
+ const earlyIndex = Object.values(this.userTimeDict).indexOf(minNum);
121
+ const earlyKey = Object.keys(this.userTimeDict)[earlyIndex];
122
+ this.removeBot(earlyKey);
123
+ }
124
+ return await this.creatBot(userId, content);
125
+ }
126
+ }
127
+ }
128
+ }
129
+ exports.BotManage = BotManage;
130
+ //# sourceMappingURL=multiReply.js.map
@@ -9,6 +9,7 @@ const aiDb_js_1 = require("../db/aiDb.js");
9
9
  const roomDb_js_1 = require("../db/roomDb.js");
10
10
  const hook_js_1 = require("../common/hook.js");
11
11
  const puppet_type_js_1 = require("../const/puppet-type.js");
12
+ const gpt4vService_js_1 = require("../service/gpt4vService.js");
12
13
  const ignoreRecord = [
13
14
  { type: "include", word: "加入了群聊" },
14
15
  { type: "include", word: "与群里其他人都不是朋友关系" },
@@ -58,6 +59,23 @@ async function dispatchFriendFilterByMsgType(that, msg) {
58
59
  console.log(`发消息人${name}:${content}`);
59
60
  const isIgnore = checkIgnore(content.trim(), aibotConfig.ignoreMessages);
60
61
  if (content.trim() && !isIgnore) {
62
+ const gpt4vReplys = await (0, gpt4vService_js_1.getGpt4vChat)({
63
+ that,
64
+ room: false,
65
+ roomId: '',
66
+ uniqueId: contact.id,
67
+ id: contact.id,
68
+ roomName: '',
69
+ isMention: false,
70
+ name,
71
+ msgContent: { type: 1, content }
72
+ });
73
+ if (gpt4vReplys.length) {
74
+ for (let reply of gpt4vReplys) {
75
+ await index_js_1.contactSay.call(that, contact, reply);
76
+ }
77
+ return;
78
+ }
61
79
  replys = await (0, reply_js_1.getContactTextReply)(that, contact, content.trim());
62
80
  for (let reply of replys) {
63
81
  await (0, index_js_2.delay)(1000);
@@ -74,6 +92,23 @@ async function dispatchFriendFilterByMsgType(that, msg) {
74
92
  break;
75
93
  case that.Message.Type.Image:
76
94
  console.log(`发消息人${await contact.name()}:发了一张图片`);
95
+ const imgGpt4vReplys = await (0, gpt4vService_js_1.getGpt4vChat)({
96
+ that,
97
+ room: false,
98
+ roomId: '',
99
+ id: contact.id,
100
+ uniqueId: contact.id,
101
+ roomName: '',
102
+ isMention: false,
103
+ name,
104
+ msgContent: { type: 3, id: msg.id }
105
+ });
106
+ if (imgGpt4vReplys.length) {
107
+ for (let reply of imgGpt4vReplys) {
108
+ await index_js_1.contactSay.call(that, contact, reply);
109
+ }
110
+ return;
111
+ }
77
112
  break;
78
113
  case that.Message.Type.Video:
79
114
  console.log(`发消息人${await contact.name()}:发了一个视频`);
@@ -145,6 +180,24 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
145
180
  const isIgnore = checkIgnore(content, aibotConfig.ignoreMessages);
146
181
  if (isIgnore)
147
182
  return;
183
+ const gpt4vReplys = await (0, gpt4vService_js_1.getGpt4vChat)({
184
+ that,
185
+ room,
186
+ roomId: room.id,
187
+ id: contactId,
188
+ uniqueId: `${room.id}-${contactId}`,
189
+ roomName,
190
+ isMention: mentionSelf,
191
+ name: contactName,
192
+ msgContent: { type: 1, content }
193
+ });
194
+ if (gpt4vReplys.length) {
195
+ for (let reply of gpt4vReplys) {
196
+ await (0, index_js_2.delay)(1000);
197
+ await index_js_1.roomSay.call(that, room, contact, reply);
198
+ }
199
+ return;
200
+ }
148
201
  replys = await (0, reply_js_1.getRoomTextReply)({
149
202
  that,
150
203
  content,
@@ -181,6 +234,23 @@ async function dispatchRoomFilterByMsgType(that, room, msg) {
181
234
  break;
182
235
  case that.Message.Type.Image:
183
236
  console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一张图片`);
237
+ const imgGpt4vReplys = await (0, gpt4vService_js_1.getGpt4vChat)({
238
+ that,
239
+ room,
240
+ roomId: room.id,
241
+ id: contactId,
242
+ uniqueId: `${room.id}-${contactId}`,
243
+ roomName,
244
+ isMention: false,
245
+ name: contactName,
246
+ msgContent: { type: 3, id: msg.id }
247
+ });
248
+ if (imgGpt4vReplys.length) {
249
+ for (let reply of imgGpt4vReplys) {
250
+ await index_js_1.roomSay.call(that, room, contact, reply);
251
+ }
252
+ return;
253
+ }
184
254
  break;
185
255
  case that.Message.Type.Video:
186
256
  console.log(`群名: ${roomName} 发消息人: ${contactName} 发了一个视频`);
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.6.31",
9
+ "version": "1.6.33",
10
10
  "description": "智能微秘书插件",
11
11
  "exports": {
12
12
  ".": {
@@ -0,0 +1,12 @@
1
+ export function getGpt4vChat({ room, roomId, roomName, isMention, msgContent, name, id, uniqueId, that }: {
2
+ room: any;
3
+ roomId: any;
4
+ roomName: any;
5
+ isMention: any;
6
+ msgContent: any;
7
+ name: any;
8
+ id: any;
9
+ uniqueId: any;
10
+ that: any;
11
+ }): Promise<any>;
12
+ //# sourceMappingURL=gpt4vService.d.ts.map
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getGpt4vChat = void 0;
7
+ const global_js_1 = __importDefault(require("../db/global.js"));
8
+ const multiReply_js_1 = require("../common/multiReply.js");
9
+ let gpt4vRes = '';
10
+ async function getGpt4vChat({ room, roomId, roomName, isMention, msgContent, name, id, uniqueId, that }) {
11
+ if (!gpt4vRes) {
12
+ gpt4vRes = new multiReply_js_1.BotManage(100, that);
13
+ }
14
+ const gptConfigs = global_js_1.default.getAllGptConfig();
15
+ if (gptConfigs && gptConfigs.length) {
16
+ let finalConfig = "";
17
+ if (room) {
18
+ finalConfig = room && gptConfigs.find((item) => {
19
+ const targetNames = [];
20
+ const targetIds = [];
21
+ item.targets.forEach(tItem => {
22
+ targetNames.push(tItem.name);
23
+ targetIds.push(tItem.id);
24
+ });
25
+ return item.type === "room" && (targetNames.includes(roomName) || targetIds.includes(roomId));
26
+ });
27
+ }
28
+ else {
29
+ finalConfig = !room && gptConfigs.find((item) => {
30
+ const targetNames = [];
31
+ const targetIds = [];
32
+ item.targets.forEach(tItem => {
33
+ targetNames.push(tItem.name);
34
+ targetIds.push(tItem.id);
35
+ });
36
+ return item.type === "contact" && (targetNames.includes(name) || targetIds.includes(id));
37
+ });
38
+ }
39
+ if (finalConfig) {
40
+ const isRoom = finalConfig.type === "room";
41
+ if (finalConfig.openChat && finalConfig.botConfig.open4v) {
42
+ if (msgContent.type === 1) {
43
+ let msg = msgContent.content;
44
+ if ((isRoom && finalConfig.needAt === 1 && isMention) || isRoom & !finalConfig.needAt || !isRoom) {
45
+ const keyword = finalConfig?.keywords.find((item) => msg.includes(item));
46
+ if (keyword || !finalConfig?.keywords.length) {
47
+ msg = keyword ? msg.replace(keyword, "") : msg;
48
+ if (finalConfig.limitNum > 0 && finalConfig.limitNum <= finalConfig.usedNum) {
49
+ return [];
50
+ }
51
+ const config = {
52
+ ...finalConfig.botConfig,
53
+ proxyPass: finalConfig.botConfig.proxyPass,
54
+ apiKey: finalConfig.botConfig.token,
55
+ };
56
+ const res = await gpt4vRes.run(uniqueId, { type: 1, content: msg }, config);
57
+ return res;
58
+ }
59
+ }
60
+ }
61
+ else if (msgContent.type === 3) {
62
+ const res = await gpt4vRes.run(uniqueId, { type: 3, id: msgContent.id });
63
+ return res;
64
+ }
65
+ }
66
+ }
67
+ }
68
+ return [];
69
+ }
70
+ exports.getGpt4vChat = getGpt4vChat;
71
+ //# sourceMappingURL=gpt4vService.js.map