wechaty-web-panel 1.4.5 → 1.4.6

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/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  ## 更新日志
2
2
 
3
+ ### V1.4.6(2023-02-07)
4
+ 1、添加gpt3模型api
5
+
3
6
  ### V1.4.5(2023-02-06)
4
7
  1、优化chatgpt报错提示,在日志中展示
5
8
  2、回调事件添加发消息人昵称
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.WechatyWebPanelPlugin = void 0;
7
+ require("isomorphic-fetch");
7
8
  const aiDb_js_1 = require("./db/aiDb.js");
8
9
  const on_scan_js_1 = __importDefault(require("./handlers/on-scan.js"));
9
10
  const on_login_js_1 = __importDefault(require("./handlers/on-login.js"));
@@ -51,11 +51,13 @@ export namespace packageJson {
51
51
  }
52
52
  const dependencies: {
53
53
  axios: string;
54
+ chatgpt: string;
54
55
  ix: string;
55
56
  jsonwebtoken: string;
56
57
  mqtt: string;
57
58
  mustache: string;
58
59
  nedb: string;
60
+ "node-fetch": string;
59
61
  "node-schedule": string;
60
62
  openai: string;
61
63
  puppeteer: string;
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
6
6
  */
7
7
  exports.packageJson = {
8
8
  "name": "wechaty-web-panel",
9
- "version": "1.4.5",
9
+ "version": "1.4.6",
10
10
  "description": "",
11
11
  "exports": {
12
12
  ".": {
@@ -69,11 +69,13 @@ exports.packageJson = {
69
69
  },
70
70
  "dependencies": {
71
71
  "axios": "^0.27.2",
72
+ "chatgpt": "^4.1.2",
72
73
  "ix": "^4.5.2",
73
74
  "jsonwebtoken": "^8.5.1",
74
75
  "mqtt": "^4.2.6",
75
76
  "mustache": "^4.2.0",
76
77
  "nedb": "^1.8.0",
78
+ "node-fetch": "^2.6.9",
77
79
  "node-schedule": "^1.3.2",
78
80
  "openai": "^3.1.0",
79
81
  "puppeteer": "^13.3.2",
@@ -0,0 +1,13 @@
1
+ export function initChatGPT(): Promise<{
2
+ type: number;
3
+ content: string;
4
+ }[] | undefined>;
5
+ declare namespace _default {
6
+ export { geGPT3Reply };
7
+ }
8
+ export default _default;
9
+ export function geGPT3Reply(content: any, uid: any): Promise<{
10
+ type: number;
11
+ content: string;
12
+ }[]>;
13
+ //# sourceMappingURL=openAi.d.ts.map
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.geGPT3Reply = exports.initChatGPT = void 0;
4
+ const configDb_js_1 = require("../db/configDb.js");
5
+ const chatgpt_1 = require("chatgpt");
6
+ let chatGPT = null;
7
+ let chatOption = {};
8
+ async function initChatGPT() {
9
+ const config = await (0, configDb_js_1.allConfig)();
10
+ if (!config.gpttoken) {
11
+ console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
12
+ return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
13
+ }
14
+ console.log('config.gpttoken', config.gpttoken);
15
+ chatGPT = new chatgpt_1.ChatGPTAPI({
16
+ apiKey: config.gpttoken,
17
+ });
18
+ }
19
+ exports.initChatGPT = initChatGPT;
20
+ async function geGPT3Reply(content, uid) {
21
+ try {
22
+ const config = await (0, configDb_js_1.allConfig)();
23
+ if (!config.gpttoken) {
24
+ console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
25
+ return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
26
+ }
27
+ if (!chatGPT) {
28
+ await initChatGPT();
29
+ }
30
+ const { conversationId, text, id } = await chatGPT.sendMessage(content, chatOption[uid]);
31
+ chatOption = {
32
+ [uid]: {
33
+ conversationId,
34
+ parentMessageId: id,
35
+ },
36
+ };
37
+ let replys = [];
38
+ let message = `${content}\n-----------\n` + text;
39
+ while (message.length > 500) {
40
+ replys.push(message.slice(0, 500));
41
+ message = message.slice(500);
42
+ }
43
+ replys.push(message);
44
+ replys = replys.map(item => {
45
+ return {
46
+ type: 1,
47
+ content: item.trim()
48
+ };
49
+ });
50
+ return replys;
51
+ }
52
+ catch (e) {
53
+ console.log('chat gpt报错:' + e);
54
+ return [{ type: 1, content: '' }];
55
+ }
56
+ }
57
+ exports.geGPT3Reply = geGPT3Reply;
58
+ exports.default = {
59
+ geGPT3Reply,
60
+ };
61
+ //# sourceMappingURL=openAi.js.map
@@ -13,6 +13,7 @@ const index_js_3 = require("../common/index.js");
13
13
  const tencent_open_js_1 = require("../proxy/tencent-open.js");
14
14
  const roomDb_js_1 = require("../db/roomDb.js");
15
15
  const chatgpt_js_1 = require("../proxy/chatgpt.js");
16
+ const openAi_js_1 = require("../proxy/openAi.js");
16
17
  /**
17
18
  * 根据事件名称分配不同的api处理,并获取返回内容
18
19
  * @param {string} eName 事件名称
@@ -225,8 +226,13 @@ async function dispatchAiBot(bot, msg, name, id) {
225
226
  replys = res;
226
227
  break;
227
228
  case 6:
228
- // ChatGPT
229
- res = await (0, chatgpt_js_1.geGPTReply)(msg);
229
+ // ChatGPT3
230
+ res = await (0, openAi_js_1.geGPT3Reply)(msg, id);
231
+ replys = res;
232
+ break;
233
+ case 7:
234
+ // ChatGPT2
235
+ res = await (0, chatgpt_js_1.geGPTReply)(msg, id);
230
236
  replys = res;
231
237
  break;
232
238
  default:
@@ -1,3 +1,4 @@
1
+ import 'isomorphic-fetch';
1
2
  import { addAibotConfig } from './db/aiDb.js';
2
3
  import onScan from './handlers/on-scan.js';
3
4
  import onLogin from './handlers/on-login.js';
@@ -51,11 +51,13 @@ export namespace packageJson {
51
51
  }
52
52
  const dependencies: {
53
53
  axios: string;
54
+ chatgpt: string;
54
55
  ix: string;
55
56
  jsonwebtoken: string;
56
57
  mqtt: string;
57
58
  mustache: string;
58
59
  nedb: string;
60
+ "node-fetch": string;
59
61
  "node-schedule": string;
60
62
  openai: string;
61
63
  puppeteer: string;
@@ -3,7 +3,7 @@
3
3
  */
4
4
  export const packageJson = {
5
5
  "name": "wechaty-web-panel",
6
- "version": "1.4.5",
6
+ "version": "1.4.6",
7
7
  "description": "",
8
8
  "exports": {
9
9
  ".": {
@@ -66,11 +66,13 @@ export const packageJson = {
66
66
  },
67
67
  "dependencies": {
68
68
  "axios": "^0.27.2",
69
+ "chatgpt": "^4.1.2",
69
70
  "ix": "^4.5.2",
70
71
  "jsonwebtoken": "^8.5.1",
71
72
  "mqtt": "^4.2.6",
72
73
  "mustache": "^4.2.0",
73
74
  "nedb": "^1.8.0",
75
+ "node-fetch": "^2.6.9",
74
76
  "node-schedule": "^1.3.2",
75
77
  "openai": "^3.1.0",
76
78
  "puppeteer": "^13.3.2",
@@ -0,0 +1,13 @@
1
+ export function initChatGPT(): Promise<{
2
+ type: number;
3
+ content: string;
4
+ }[] | undefined>;
5
+ declare namespace _default {
6
+ export { geGPT3Reply };
7
+ }
8
+ export default _default;
9
+ export function geGPT3Reply(content: any, uid: any): Promise<{
10
+ type: number;
11
+ content: string;
12
+ }[]>;
13
+ //# sourceMappingURL=openAi.d.ts.map
@@ -0,0 +1,57 @@
1
+ import { allConfig } from "../db/configDb.js";
2
+ import { ChatGPTAPI } from 'chatgpt';
3
+ let chatGPT = null;
4
+ let chatOption = {};
5
+ export async function initChatGPT() {
6
+ const config = await allConfig();
7
+ if (!config.gpttoken) {
8
+ console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
9
+ return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
10
+ }
11
+ console.log('config.gpttoken', config.gpttoken);
12
+ chatGPT = new ChatGPTAPI({
13
+ apiKey: config.gpttoken,
14
+ });
15
+ }
16
+ async function geGPT3Reply(content, uid) {
17
+ try {
18
+ const config = await allConfig();
19
+ if (!config.gpttoken) {
20
+ console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
21
+ return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
22
+ }
23
+ if (!chatGPT) {
24
+ await initChatGPT();
25
+ }
26
+ const { conversationId, text, id } = await chatGPT.sendMessage(content, chatOption[uid]);
27
+ chatOption = {
28
+ [uid]: {
29
+ conversationId,
30
+ parentMessageId: id,
31
+ },
32
+ };
33
+ let replys = [];
34
+ let message = `${content}\n-----------\n` + text;
35
+ while (message.length > 500) {
36
+ replys.push(message.slice(0, 500));
37
+ message = message.slice(500);
38
+ }
39
+ replys.push(message);
40
+ replys = replys.map(item => {
41
+ return {
42
+ type: 1,
43
+ content: item.trim()
44
+ };
45
+ });
46
+ return replys;
47
+ }
48
+ catch (e) {
49
+ console.log('chat gpt报错:' + e);
50
+ return [{ type: 1, content: '' }];
51
+ }
52
+ }
53
+ export { geGPT3Reply };
54
+ export default {
55
+ geGPT3Reply,
56
+ };
57
+ //# sourceMappingURL=openAi.js.map
@@ -7,6 +7,7 @@ import { updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../comm
7
7
  import { getTencentOpenReply } from '../proxy/tencent-open.js';
8
8
  import { getRoomRecordContent, removeRecord } from "../db/roomDb.js";
9
9
  import { geGPTReply } from '../proxy/chatgpt.js';
10
+ import { geGPT3Reply } from '../proxy/openAi.js';
10
11
  /**
11
12
  * 根据事件名称分配不同的api处理,并获取返回内容
12
13
  * @param {string} eName 事件名称
@@ -218,8 +219,13 @@ async function dispatchAiBot(bot, msg, name, id) {
218
219
  replys = res;
219
220
  break;
220
221
  case 6:
221
- // ChatGPT
222
- res = await geGPTReply(msg);
222
+ // ChatGPT3
223
+ res = await geGPT3Reply(msg, id);
224
+ replys = res;
225
+ break;
226
+ case 7:
227
+ // ChatGPT2
228
+ res = await geGPTReply(msg, id);
223
229
  replys = res;
224
230
  break;
225
231
  default:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wechaty-web-panel",
3
- "version": "1.4.5",
3
+ "version": "1.4.6",
4
4
  "description": "",
5
5
  "exports": {
6
6
  ".": {
@@ -63,11 +63,13 @@
63
63
  },
64
64
  "dependencies": {
65
65
  "axios": "^0.27.2",
66
+ "chatgpt": "^4.1.2",
66
67
  "ix": "^4.5.2",
67
68
  "jsonwebtoken": "^8.5.1",
68
69
  "mqtt": "^4.2.6",
69
70
  "mustache": "^4.2.0",
70
71
  "nedb": "^1.8.0",
72
+ "node-fetch": "^2.6.9",
71
73
  "node-schedule": "^1.3.2",
72
74
  "openai": "^3.1.0",
73
75
  "puppeteer": "^13.3.2",