wechaty-web-panel 1.6.4 → 1.6.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 +6 -0
- package/dist/cjs/src/lib/officialOpenAi.d.ts +1 -1
- package/dist/cjs/src/lib/officialOpenAi.js +4 -4
- package/dist/cjs/src/lib/unOfficialOpenAi.d.ts +1 -1
- package/dist/cjs/src/lib/unOfficialOpenAi.js +6 -3
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/bot/chatgpt-web.d.ts +1 -0
- package/dist/cjs/src/proxy/bot/chatgpt-web.js +13 -2
- package/dist/cjs/src/proxy/bot/chatgpt.d.ts +1 -0
- package/dist/cjs/src/proxy/bot/chatgpt.js +13 -2
- package/dist/cjs/src/proxy/superagent.d.ts +1 -1
- package/dist/cjs/src/proxy/superagent.js +2 -2
- package/dist/cjs/src/service/msg-filter-service.js +1 -1
- package/dist/cjs/src/service/msg-filters.d.ts +3 -1
- package/dist/cjs/src/service/msg-filters.js +9 -4
- package/dist/esm/src/lib/officialOpenAi.d.ts +1 -1
- package/dist/esm/src/lib/officialOpenAi.js +4 -4
- package/dist/esm/src/lib/unOfficialOpenAi.d.ts +1 -1
- package/dist/esm/src/lib/unOfficialOpenAi.js +6 -3
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/bot/chatgpt-web.d.ts +1 -0
- package/dist/esm/src/proxy/bot/chatgpt-web.js +13 -2
- package/dist/esm/src/proxy/bot/chatgpt.d.ts +1 -0
- package/dist/esm/src/proxy/bot/chatgpt.js +13 -2
- package/dist/esm/src/proxy/superagent.d.ts +1 -1
- package/dist/esm/src/proxy/superagent.js +2 -2
- package/dist/esm/src/service/msg-filter-service.js +1 -1
- package/dist/esm/src/service/msg-filters.d.ts +3 -1
- package/dist/esm/src/service/msg-filters.js +9 -4
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -59,7 +59,7 @@ declare class OfficialOpenAi {
|
|
|
59
59
|
* @return {Promise<void>}
|
|
60
60
|
*/
|
|
61
61
|
reset(): Promise<void>;
|
|
62
|
-
getReply(content: any, uid: any, adminId?: string): Promise<{
|
|
62
|
+
getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
|
|
63
63
|
type: number;
|
|
64
64
|
content: any;
|
|
65
65
|
}[]>;
|
|
@@ -108,7 +108,7 @@ class OfficialOpenAi {
|
|
|
108
108
|
reset() {
|
|
109
109
|
this.chatGPT = null;
|
|
110
110
|
}
|
|
111
|
-
async getReply(content, uid, adminId = '') {
|
|
111
|
+
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
112
112
|
try {
|
|
113
113
|
if (!this.chatGPT) {
|
|
114
114
|
console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
@@ -119,15 +119,15 @@ class OfficialOpenAi {
|
|
|
119
119
|
const censor = await this.contentCensor.checkText(content);
|
|
120
120
|
if (!censor) {
|
|
121
121
|
console.log(`问题:${content},包含违规词,已拦截`);
|
|
122
|
-
return [{ type: 1, content: '' }];
|
|
122
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 });
|
|
125
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 });
|
|
126
126
|
if (this.config.filter) {
|
|
127
127
|
const censor = await this.contentCensor.checkText(text);
|
|
128
128
|
if (!censor) {
|
|
129
129
|
console.log(`回复: ${text},包含违规词,已拦截`);
|
|
130
|
-
return [{ type: 1, content: '' }];
|
|
130
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
if (this.config.record) {
|
|
@@ -36,7 +36,7 @@ declare class UnOfficialOpenAi {
|
|
|
36
36
|
* @return {Promise<void>}
|
|
37
37
|
*/
|
|
38
38
|
reset(): Promise<void>;
|
|
39
|
-
getReply(content: any, uid: any, adminId?: string): Promise<{
|
|
39
|
+
getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
|
|
40
40
|
type: number;
|
|
41
41
|
content: any;
|
|
42
42
|
}[]>;
|
|
@@ -76,14 +76,17 @@ class UnOfficialOpenAi {
|
|
|
76
76
|
reset() {
|
|
77
77
|
this.chatGPT = null;
|
|
78
78
|
}
|
|
79
|
-
async getReply(content, uid, adminId = '') {
|
|
79
|
+
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
80
80
|
try {
|
|
81
81
|
if (!this.chatGPT) {
|
|
82
82
|
console.log('看到此消息说明已启用chatGPT 网页hook版');
|
|
83
83
|
await this.init();
|
|
84
84
|
}
|
|
85
|
-
|
|
86
|
-
|
|
85
|
+
let question = this.config.systemMessage ? this.config.systemMessage + content : content;
|
|
86
|
+
if (systemMessage) {
|
|
87
|
+
question = systemMessage + content;
|
|
88
|
+
}
|
|
89
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(question, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 });
|
|
87
90
|
if (this.config.record) {
|
|
88
91
|
void (0, aichatDb_js_1.addAichatRecord)({
|
|
89
92
|
contactId: uid,
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getChatGPTWebReply = exports.resetAll = exports.reset = void 0;
|
|
7
7
|
const unOfficialOpenAi_js_1 = __importDefault(require("../../lib/unOfficialOpenAi.js"));
|
|
8
|
+
const aibotk_js_1 = require("../aibotk.js");
|
|
8
9
|
let chatGPT = {};
|
|
9
10
|
function reset(adminId) {
|
|
10
11
|
if (!chatGPT[adminId])
|
|
@@ -22,7 +23,7 @@ function resetAll() {
|
|
|
22
23
|
chatGPT = {};
|
|
23
24
|
}
|
|
24
25
|
exports.resetAll = resetAll;
|
|
25
|
-
async function getChatGPTWebReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", systemMessage: '', showQuestion: false, timeoutMs: 0 }) {
|
|
26
|
+
async function getChatGPTWebReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", systemMessage: '', showQuestion: false, timeoutMs: 0, keywordSystemMessages: [] }) {
|
|
26
27
|
if (!config.token) {
|
|
27
28
|
console.log('请到智能微秘书平台配置openaiAccessToken参数方可使用');
|
|
28
29
|
return [{ type: 1, content: '请到平台配置Openai openaiAccessToken参数方可使用' }];
|
|
@@ -30,7 +31,17 @@ async function getChatGPTWebReply(content, uid, adminId, config = { token: "", d
|
|
|
30
31
|
if (!chatGPT[adminId]) {
|
|
31
32
|
chatGPT[adminId] = new unOfficialOpenAi_js_1.default(config);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
let systemMessage = '';
|
|
35
|
+
if (config.keywordSystemMessages && config.keywordSystemMessages.length) {
|
|
36
|
+
const finalSystemMsg = config.keywordSystemMessages.find(item => content.startsWith(item.keyword));
|
|
37
|
+
if (finalSystemMsg) {
|
|
38
|
+
const promotInfo = await (0, aibotk_js_1.getPromotInfo)(finalSystemMsg.promotId);
|
|
39
|
+
console.log(`触发关键词角色功能,使用对应预设角色:${promotInfo.name}`);
|
|
40
|
+
systemMessage = promotInfo.promot;
|
|
41
|
+
content = content.replace(finalSystemMsg.keyword, '');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
34
45
|
}
|
|
35
46
|
exports.getChatGPTWebReply = getChatGPTWebReply;
|
|
36
47
|
//# sourceMappingURL=chatgpt-web.js.map
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.getChatGPTReply = exports.resetAll = exports.reset = void 0;
|
|
7
7
|
const officialOpenAi_js_1 = __importDefault(require("../../lib/officialOpenAi.js"));
|
|
8
|
+
const aibotk_js_1 = require("../aibotk.js");
|
|
8
9
|
let chatGPT = {};
|
|
9
10
|
function reset(adminId) {
|
|
10
11
|
if (!chatGPT[adminId])
|
|
@@ -22,7 +23,7 @@ function resetAll() {
|
|
|
22
23
|
chatGPT = {};
|
|
23
24
|
}
|
|
24
25
|
exports.resetAll = resetAll;
|
|
25
|
-
async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 0, model: "", systemMessage: "" }) {
|
|
26
|
+
async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 0, model: "", systemMessage: "", keywordSystemMessages: [] }) {
|
|
26
27
|
if (!config.token) {
|
|
27
28
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
28
29
|
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
@@ -30,7 +31,17 @@ async function getChatGPTReply(content, uid, adminId, config = { token: "", debu
|
|
|
30
31
|
if (!chatGPT[adminId]) {
|
|
31
32
|
chatGPT[adminId] = new officialOpenAi_js_1.default(config);
|
|
32
33
|
}
|
|
33
|
-
|
|
34
|
+
let systemMessage = '';
|
|
35
|
+
if (config.keywordSystemMessages && config.keywordSystemMessages.length) {
|
|
36
|
+
const finalSystemMsg = config.keywordSystemMessages.find(item => content.startsWith(item.keyword));
|
|
37
|
+
if (finalSystemMsg) {
|
|
38
|
+
const promotInfo = await (0, aibotk_js_1.getPromotInfo)(finalSystemMsg.promotId);
|
|
39
|
+
console.log(`触发关键词角色功能,使用对应预设角色:${promotInfo.name}`);
|
|
40
|
+
systemMessage = promotInfo.promot;
|
|
41
|
+
content = content.replace(finalSystemMsg.keyword, '');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
34
45
|
}
|
|
35
46
|
exports.getChatGPTReply = getChatGPTReply;
|
|
36
47
|
//# sourceMappingURL=chatgpt.js.map
|
|
@@ -10,5 +10,5 @@ export function req(option: any): Promise<any> | undefined;
|
|
|
10
10
|
export function txReq(option: any): Promise<any>;
|
|
11
11
|
export function aiBotReq(option: any): Promise<any>;
|
|
12
12
|
export const service: import("axios").AxiosInstance;
|
|
13
|
-
export function callbackAibotApi(url: any, data: any): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
13
|
+
export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
14
14
|
//# sourceMappingURL=superagent.d.ts.map
|
|
@@ -168,7 +168,7 @@ async function aiBotReq(option) {
|
|
|
168
168
|
}
|
|
169
169
|
}
|
|
170
170
|
exports.aiBotReq = aiBotReq;
|
|
171
|
-
async function callbackAibotApi(url, data) {
|
|
171
|
+
async function callbackAibotApi(url, data, timeout = 60) {
|
|
172
172
|
const env = await (0, aiDb_js_1.getAibotConfig)();
|
|
173
173
|
const { apiKey, apiSecret } = env;
|
|
174
174
|
if (!apiKey || !apiSecret) {
|
|
@@ -176,7 +176,7 @@ async function callbackAibotApi(url, data) {
|
|
|
176
176
|
return [];
|
|
177
177
|
}
|
|
178
178
|
data = (0, index_js_1.getFormatQuery)(apiKey, apiSecret, data);
|
|
179
|
-
let res = await service.post(url, data);
|
|
179
|
+
let res = await service.post(url, data, { timeout: timeout * 1000 });
|
|
180
180
|
return res;
|
|
181
181
|
}
|
|
182
182
|
exports.callbackAibotApi = callbackAibotApi;
|
|
@@ -86,7 +86,7 @@ async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roo
|
|
|
86
86
|
const resArray = [
|
|
87
87
|
{ bool: msg === '', method: 'emptyMsg' },
|
|
88
88
|
{ bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
|
|
89
|
-
{ bool: config.preventWords, method: 'preventWordCheck' },
|
|
89
|
+
{ bool: !!config.preventWords, method: 'preventWordCheck' },
|
|
90
90
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
91
91
|
{ bool: true, method: 'keywordsMsg' },
|
|
92
92
|
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
@@ -114,8 +114,10 @@ export function customChat({ msg, name, id, config, isMention, room, roomId, roo
|
|
|
114
114
|
* @param config
|
|
115
115
|
* @return {*[]}
|
|
116
116
|
*/
|
|
117
|
-
export function preventWordCheck({ msg, config }: {
|
|
117
|
+
export function preventWordCheck({ msg, config, isMention, room }: {
|
|
118
118
|
msg: any;
|
|
119
119
|
config: any;
|
|
120
|
+
isMention: any;
|
|
121
|
+
room: any;
|
|
120
122
|
}): any[];
|
|
121
123
|
//# sourceMappingURL=msg-filters.d.ts.map
|
|
@@ -180,12 +180,13 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
180
180
|
data[mItem.key] = mItem.value;
|
|
181
181
|
}
|
|
182
182
|
});
|
|
183
|
+
const timeout = item.timeout || 60;
|
|
183
184
|
if (item.type === 100) {
|
|
184
|
-
let res = await superagent_js_1.service.post(item.customUrl, data);
|
|
185
|
+
let res = await superagent_js_1.service.post(item.customUrl, data, { timeout: timeout * 1000 });
|
|
185
186
|
return res;
|
|
186
187
|
}
|
|
187
188
|
else if (item.type === 1) {
|
|
188
|
-
let res = await (0, superagent_js_1.callbackAibotApi)(item.postUrl, data);
|
|
189
|
+
let res = await (0, superagent_js_1.callbackAibotApi)(item.postUrl, data, timeout);
|
|
189
190
|
return res;
|
|
190
191
|
}
|
|
191
192
|
}
|
|
@@ -349,13 +350,17 @@ exports.customChat = customChat;
|
|
|
349
350
|
* @param config
|
|
350
351
|
* @return {*[]}
|
|
351
352
|
*/
|
|
352
|
-
function preventWordCheck({ msg, config }) {
|
|
353
|
+
function preventWordCheck({ msg, config, isMention, room }) {
|
|
353
354
|
const preventWords = config.preventWords.replaceAll(',', ',').split(',');
|
|
355
|
+
// 如果是群消息,但是没有提及机器人,则不需要返回任何消息 因为可能是正常交流而已
|
|
356
|
+
if (room && !isMention) {
|
|
357
|
+
return [];
|
|
358
|
+
}
|
|
354
359
|
if (preventWords && preventWords.length) {
|
|
355
360
|
for (let item of preventWords) {
|
|
356
361
|
if (item && item !== '' && msg.includes(item)) {
|
|
357
362
|
console.log(`触发禁止词【${item}】,不回复用户`);
|
|
358
|
-
return [{ type: 1, content: '' }];
|
|
363
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
359
364
|
}
|
|
360
365
|
}
|
|
361
366
|
}
|
|
@@ -59,7 +59,7 @@ declare class OfficialOpenAi {
|
|
|
59
59
|
* @return {Promise<void>}
|
|
60
60
|
*/
|
|
61
61
|
reset(): Promise<void>;
|
|
62
|
-
getReply(content: any, uid: any, adminId?: string): Promise<{
|
|
62
|
+
getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
|
|
63
63
|
type: number;
|
|
64
64
|
content: any;
|
|
65
65
|
}[]>;
|
|
@@ -103,7 +103,7 @@ class OfficialOpenAi {
|
|
|
103
103
|
reset() {
|
|
104
104
|
this.chatGPT = null;
|
|
105
105
|
}
|
|
106
|
-
async getReply(content, uid, adminId = '') {
|
|
106
|
+
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
107
107
|
try {
|
|
108
108
|
if (!this.chatGPT) {
|
|
109
109
|
console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
@@ -114,15 +114,15 @@ class OfficialOpenAi {
|
|
|
114
114
|
const censor = await this.contentCensor.checkText(content);
|
|
115
115
|
if (!censor) {
|
|
116
116
|
console.log(`问题:${content},包含违规词,已拦截`);
|
|
117
|
-
return [{ type: 1, content: '' }];
|
|
117
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
118
118
|
}
|
|
119
119
|
}
|
|
120
|
-
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 });
|
|
120
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 });
|
|
121
121
|
if (this.config.filter) {
|
|
122
122
|
const censor = await this.contentCensor.checkText(text);
|
|
123
123
|
if (!censor) {
|
|
124
124
|
console.log(`回复: ${text},包含违规词,已拦截`);
|
|
125
|
-
return [{ type: 1, content: '' }];
|
|
125
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
126
126
|
}
|
|
127
127
|
}
|
|
128
128
|
if (this.config.record) {
|
|
@@ -36,7 +36,7 @@ declare class UnOfficialOpenAi {
|
|
|
36
36
|
* @return {Promise<void>}
|
|
37
37
|
*/
|
|
38
38
|
reset(): Promise<void>;
|
|
39
|
-
getReply(content: any, uid: any, adminId?: string): Promise<{
|
|
39
|
+
getReply(content: any, uid: any, adminId?: string, systemMessage?: string): Promise<{
|
|
40
40
|
type: number;
|
|
41
41
|
content: any;
|
|
42
42
|
}[]>;
|
|
@@ -71,14 +71,17 @@ class UnOfficialOpenAi {
|
|
|
71
71
|
reset() {
|
|
72
72
|
this.chatGPT = null;
|
|
73
73
|
}
|
|
74
|
-
async getReply(content, uid, adminId = '') {
|
|
74
|
+
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
75
75
|
try {
|
|
76
76
|
if (!this.chatGPT) {
|
|
77
77
|
console.log('看到此消息说明已启用chatGPT 网页hook版');
|
|
78
78
|
await this.init();
|
|
79
79
|
}
|
|
80
|
-
|
|
81
|
-
|
|
80
|
+
let question = this.config.systemMessage ? this.config.systemMessage + content : content;
|
|
81
|
+
if (systemMessage) {
|
|
82
|
+
question = systemMessage + content;
|
|
83
|
+
}
|
|
84
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(question, { ...this.chatOption[uid], systemMessage, timeoutMs: this.config.timeoutMs * 1000 });
|
|
82
85
|
if (this.config.record) {
|
|
83
86
|
void addAichatRecord({
|
|
84
87
|
contactId: uid,
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import UnOfficialOpenAi from '../../lib/unOfficialOpenAi.js';
|
|
2
|
+
import { getPromotInfo } from "../aibotk.js";
|
|
2
3
|
let chatGPT = {};
|
|
3
4
|
export function reset(adminId) {
|
|
4
5
|
if (!chatGPT[adminId])
|
|
@@ -14,7 +15,7 @@ export function resetAll() {
|
|
|
14
15
|
});
|
|
15
16
|
chatGPT = {};
|
|
16
17
|
}
|
|
17
|
-
export async function getChatGPTWebReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", systemMessage: '', showQuestion: false, timeoutMs: 0 }) {
|
|
18
|
+
export async function getChatGPTWebReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", systemMessage: '', showQuestion: false, timeoutMs: 0, keywordSystemMessages: [] }) {
|
|
18
19
|
if (!config.token) {
|
|
19
20
|
console.log('请到智能微秘书平台配置openaiAccessToken参数方可使用');
|
|
20
21
|
return [{ type: 1, content: '请到平台配置Openai openaiAccessToken参数方可使用' }];
|
|
@@ -22,6 +23,16 @@ export async function getChatGPTWebReply(content, uid, adminId, config = { token
|
|
|
22
23
|
if (!chatGPT[adminId]) {
|
|
23
24
|
chatGPT[adminId] = new UnOfficialOpenAi(config);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
let systemMessage = '';
|
|
27
|
+
if (config.keywordSystemMessages && config.keywordSystemMessages.length) {
|
|
28
|
+
const finalSystemMsg = config.keywordSystemMessages.find(item => content.startsWith(item.keyword));
|
|
29
|
+
if (finalSystemMsg) {
|
|
30
|
+
const promotInfo = await getPromotInfo(finalSystemMsg.promotId);
|
|
31
|
+
console.log(`触发关键词角色功能,使用对应预设角色:${promotInfo.name}`);
|
|
32
|
+
systemMessage = promotInfo.promot;
|
|
33
|
+
content = content.replace(finalSystemMsg.keyword, '');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
26
37
|
}
|
|
27
38
|
//# sourceMappingURL=chatgpt-web.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import OfficialOpenAi from "../../lib/officialOpenAi.js";
|
|
2
|
+
import { getPromotInfo } from "../aibotk.js";
|
|
2
3
|
let chatGPT = {};
|
|
3
4
|
export function reset(adminId) {
|
|
4
5
|
if (!chatGPT[adminId])
|
|
@@ -14,7 +15,7 @@ export function resetAll() {
|
|
|
14
15
|
});
|
|
15
16
|
chatGPT = {};
|
|
16
17
|
}
|
|
17
|
-
export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 0, model: "", systemMessage: "" }) {
|
|
18
|
+
export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 0, model: "", systemMessage: "", keywordSystemMessages: [] }) {
|
|
18
19
|
if (!config.token) {
|
|
19
20
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
20
21
|
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
@@ -22,6 +23,16 @@ export async function getChatGPTReply(content, uid, adminId, config = { token: "
|
|
|
22
23
|
if (!chatGPT[adminId]) {
|
|
23
24
|
chatGPT[adminId] = new OfficialOpenAi(config);
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
let systemMessage = '';
|
|
27
|
+
if (config.keywordSystemMessages && config.keywordSystemMessages.length) {
|
|
28
|
+
const finalSystemMsg = config.keywordSystemMessages.find(item => content.startsWith(item.keyword));
|
|
29
|
+
if (finalSystemMsg) {
|
|
30
|
+
const promotInfo = await getPromotInfo(finalSystemMsg.promotId);
|
|
31
|
+
console.log(`触发关键词角色功能,使用对应预设角色:${promotInfo.name}`);
|
|
32
|
+
systemMessage = promotInfo.promot;
|
|
33
|
+
content = content.replace(finalSystemMsg.keyword, '');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
26
37
|
}
|
|
27
38
|
//# sourceMappingURL=chatgpt.js.map
|
|
@@ -10,5 +10,5 @@ export function req(option: any): Promise<any> | undefined;
|
|
|
10
10
|
export function txReq(option: any): Promise<any>;
|
|
11
11
|
export function aiBotReq(option: any): Promise<any>;
|
|
12
12
|
export const service: import("axios").AxiosInstance;
|
|
13
|
-
export function callbackAibotApi(url: any, data: any): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
13
|
+
export function callbackAibotApi(url: any, data: any, timeout?: number): Promise<never[] | import("axios").AxiosResponse<any, any>>;
|
|
14
14
|
//# sourceMappingURL=superagent.d.ts.map
|
|
@@ -158,7 +158,7 @@ async function aiBotReq(option) {
|
|
|
158
158
|
return get({ url: AIBOTK + option.url, params, contentType: option.contentType, platform: option.platform || 'aibot' });
|
|
159
159
|
}
|
|
160
160
|
}
|
|
161
|
-
async function callbackAibotApi(url, data) {
|
|
161
|
+
async function callbackAibotApi(url, data, timeout = 60) {
|
|
162
162
|
const env = await getAibotConfig();
|
|
163
163
|
const { apiKey, apiSecret } = env;
|
|
164
164
|
if (!apiKey || !apiSecret) {
|
|
@@ -166,7 +166,7 @@ async function callbackAibotApi(url, data) {
|
|
|
166
166
|
return [];
|
|
167
167
|
}
|
|
168
168
|
data = getFormatQuery(apiKey, apiSecret, data);
|
|
169
|
-
let res = await service.post(url, data);
|
|
169
|
+
let res = await service.post(url, data, { timeout: timeout * 1000 });
|
|
170
170
|
return res;
|
|
171
171
|
}
|
|
172
172
|
export { req };
|
|
@@ -79,7 +79,7 @@ async function filterRoomMsg({ that, msg, name, id, avatar, room, isMention, roo
|
|
|
79
79
|
const resArray = [
|
|
80
80
|
{ bool: msg === '', method: 'emptyMsg' },
|
|
81
81
|
{ bool: config.callBackEvents && config.callBackEvents.length > 0, method: 'callbackEvent' },
|
|
82
|
-
{ bool: config.preventWords, method: 'preventWordCheck' },
|
|
82
|
+
{ bool: !!config.preventWords, method: 'preventWordCheck' },
|
|
83
83
|
{ bool: config.eventKeywords && config.eventKeywords.length > 0, method: 'eventMsg' },
|
|
84
84
|
{ bool: true, method: 'keywordsMsg' },
|
|
85
85
|
{ bool: gptConfig && gptConfig.length > 0, method: 'customChat' },
|
|
@@ -114,8 +114,10 @@ export function customChat({ msg, name, id, config, isMention, room, roomId, roo
|
|
|
114
114
|
* @param config
|
|
115
115
|
* @return {*[]}
|
|
116
116
|
*/
|
|
117
|
-
export function preventWordCheck({ msg, config }: {
|
|
117
|
+
export function preventWordCheck({ msg, config, isMention, room }: {
|
|
118
118
|
msg: any;
|
|
119
119
|
config: any;
|
|
120
|
+
isMention: any;
|
|
121
|
+
room: any;
|
|
120
122
|
}): any[];
|
|
121
123
|
//# sourceMappingURL=msg-filters.d.ts.map
|
|
@@ -168,12 +168,13 @@ async function callbackEvent({ that, msg, name, id, config, room, isMention }) {
|
|
|
168
168
|
data[mItem.key] = mItem.value;
|
|
169
169
|
}
|
|
170
170
|
});
|
|
171
|
+
const timeout = item.timeout || 60;
|
|
171
172
|
if (item.type === 100) {
|
|
172
|
-
let res = await service.post(item.customUrl, data);
|
|
173
|
+
let res = await service.post(item.customUrl, data, { timeout: timeout * 1000 });
|
|
173
174
|
return res;
|
|
174
175
|
}
|
|
175
176
|
else if (item.type === 1) {
|
|
176
|
-
let res = await callbackAibotApi(item.postUrl, data);
|
|
177
|
+
let res = await callbackAibotApi(item.postUrl, data, timeout);
|
|
177
178
|
return res;
|
|
178
179
|
}
|
|
179
180
|
}
|
|
@@ -332,13 +333,17 @@ async function customChat({ msg, name, id, config, isMention, room, roomId, room
|
|
|
332
333
|
* @param config
|
|
333
334
|
* @return {*[]}
|
|
334
335
|
*/
|
|
335
|
-
function preventWordCheck({ msg, config }) {
|
|
336
|
+
function preventWordCheck({ msg, config, isMention, room }) {
|
|
336
337
|
const preventWords = config.preventWords.replaceAll(',', ',').split(',');
|
|
338
|
+
// 如果是群消息,但是没有提及机器人,则不需要返回任何消息 因为可能是正常交流而已
|
|
339
|
+
if (room && !isMention) {
|
|
340
|
+
return [];
|
|
341
|
+
}
|
|
337
342
|
if (preventWords && preventWords.length) {
|
|
338
343
|
for (let item of preventWords) {
|
|
339
344
|
if (item && item !== '' && msg.includes(item)) {
|
|
340
345
|
console.log(`触发禁止词【${item}】,不回复用户`);
|
|
341
|
-
return [{ type: 1, content: '' }];
|
|
346
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
}
|