wechaty-web-panel 1.6.21 → 1.6.22
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 +4 -0
- package/dist/cjs/src/botInstance/officialOpenAi.d.ts +1 -1
- package/dist/cjs/src/botInstance/officialOpenAi.js +10 -3
- package/dist/cjs/src/botInstance/sdk/chatGPT.js +4 -1
- package/dist/cjs/src/botInstance/sdk/difyClient.js +26 -53
- package/dist/cjs/src/common/index.d.ts +7 -0
- package/dist/cjs/src/common/index.js +15 -1
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/bot/chatgpt.d.ts +2 -2
- package/dist/cjs/src/proxy/bot/chatgpt.js +2 -2
- package/dist/cjs/src/proxy/bot/dispatch.js +6 -1
- package/dist/cjs/src/proxy/mqtt.js +14 -0
- package/dist/cjs/src/proxy/openAi.d.ts +1 -1
- package/dist/cjs/src/proxy/openAi.js +2 -2
- package/dist/cjs/src/service/event-dispatch-service.js +7 -2
- package/dist/esm/src/botInstance/officialOpenAi.d.ts +1 -1
- package/dist/esm/src/botInstance/officialOpenAi.js +10 -3
- package/dist/esm/src/botInstance/sdk/chatGPT.js +4 -1
- package/dist/esm/src/botInstance/sdk/difyClient.js +26 -53
- package/dist/esm/src/common/index.d.ts +7 -0
- package/dist/esm/src/common/index.js +14 -0
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/bot/chatgpt.d.ts +2 -2
- package/dist/esm/src/proxy/bot/chatgpt.js +2 -2
- package/dist/esm/src/proxy/bot/dispatch.js +6 -1
- package/dist/esm/src/proxy/mqtt.js +16 -2
- package/dist/esm/src/proxy/openAi.d.ts +1 -1
- package/dist/esm/src/proxy/openAi.js +2 -2
- package/dist/esm/src/service/event-dispatch-service.js +7 -2
- 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
|
|
62
|
+
getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
|
|
63
63
|
type: number;
|
|
64
64
|
content: any;
|
|
65
65
|
}[]>;
|
|
@@ -112,10 +112,10 @@ class OfficialOpenAi {
|
|
|
112
112
|
reset() {
|
|
113
113
|
this.chatGPT = null;
|
|
114
114
|
}
|
|
115
|
-
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
115
|
+
async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
|
|
116
116
|
try {
|
|
117
117
|
if (!this.chatGPT) {
|
|
118
|
-
console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
118
|
+
console.log(isFastGPT ? '看到此消息说明启用了fastgpt' : '看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
119
119
|
await this.init();
|
|
120
120
|
}
|
|
121
121
|
if (this.config.filter) {
|
|
@@ -132,7 +132,14 @@ class OfficialOpenAi {
|
|
|
132
132
|
return [{ type: 1, content: '上下文已重置' }];
|
|
133
133
|
}
|
|
134
134
|
}
|
|
135
|
-
const
|
|
135
|
+
const sendParams = { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
|
|
136
|
+
if (systemMessage) {
|
|
137
|
+
sendParams.systemMessage = systemMessage;
|
|
138
|
+
}
|
|
139
|
+
if (isFastGPT) {
|
|
140
|
+
sendParams.chatId = uid;
|
|
141
|
+
}
|
|
142
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
|
|
136
143
|
if (this.config.filter) {
|
|
137
144
|
const censor = await this.contentCensor.checkText(text);
|
|
138
145
|
if (!censor) {
|
|
@@ -149,7 +149,7 @@ Current date: ${currentDate}`;
|
|
|
149
149
|
}
|
|
150
150
|
}
|
|
151
151
|
async sendMessage(text, opts = {}) {
|
|
152
|
-
const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId } = opts;
|
|
152
|
+
const { parentMessageId, messageId = (0, uuid_1.v4)(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
|
|
153
153
|
let { abortSignal } = opts;
|
|
154
154
|
let abortController = null;
|
|
155
155
|
if (timeoutMs && !abortSignal) {
|
|
@@ -185,6 +185,9 @@ Current date: ${currentDate}`;
|
|
|
185
185
|
messages,
|
|
186
186
|
stream
|
|
187
187
|
};
|
|
188
|
+
if (chatId) {
|
|
189
|
+
body.chatId = chatId;
|
|
190
|
+
}
|
|
188
191
|
if (this._apiOrg) {
|
|
189
192
|
headers["OpenAI-Organization"] = this._apiOrg;
|
|
190
193
|
}
|
|
@@ -8,32 +8,19 @@ const axios_1 = __importDefault(require("axios"));
|
|
|
8
8
|
exports.BASE_URL = "https://api.dify.ai/v1";
|
|
9
9
|
exports.routes = {
|
|
10
10
|
application: {
|
|
11
|
-
method: "GET",
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
method: "POST",
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
method: "
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
method: "
|
|
24
|
-
url: () => `/chat-messages`
|
|
25
|
-
},
|
|
26
|
-
getConversationMessages: {
|
|
27
|
-
method: "GET",
|
|
28
|
-
url: () => "/messages"
|
|
29
|
-
},
|
|
30
|
-
getConversations: {
|
|
31
|
-
method: "GET",
|
|
32
|
-
url: () => "/conversations"
|
|
33
|
-
},
|
|
34
|
-
renameConversation: {
|
|
35
|
-
method: "PATCH",
|
|
36
|
-
url: (conversationId) => `/conversations/${conversationId}`
|
|
11
|
+
method: "GET", url: () => `/parameters`
|
|
12
|
+
}, feedback: {
|
|
13
|
+
method: "POST", url: (messageId) => `/messages/${messageId}/feedbacks`
|
|
14
|
+
}, createCompletionMessage: {
|
|
15
|
+
method: "POST", url: () => `/completion-messages`
|
|
16
|
+
}, createChatMessage: {
|
|
17
|
+
method: "POST", url: () => `/chat-messages`
|
|
18
|
+
}, getConversationMessages: {
|
|
19
|
+
method: "GET", url: () => "/messages"
|
|
20
|
+
}, getConversations: {
|
|
21
|
+
method: "GET", url: () => "/conversations"
|
|
22
|
+
}, renameConversation: {
|
|
23
|
+
method: "PATCH", url: (conversationId) => `/conversations/${conversationId}`
|
|
37
24
|
}
|
|
38
25
|
};
|
|
39
26
|
class DifyClient {
|
|
@@ -48,8 +35,7 @@ class DifyClient {
|
|
|
48
35
|
}
|
|
49
36
|
async sendRequest({ method, endpoint, data, params, stream = false, timeoutMs = 60 * 1000 }) {
|
|
50
37
|
const headers = {
|
|
51
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
52
|
-
"Content-Type": "application/json"
|
|
38
|
+
"Authorization": `Bearer ${this.apiKey}`, "Content-Type": "application/json"
|
|
53
39
|
};
|
|
54
40
|
const url = `${this.baseUrl}${endpoint}`;
|
|
55
41
|
let response;
|
|
@@ -69,17 +55,14 @@ class DifyClient {
|
|
|
69
55
|
}
|
|
70
56
|
else {
|
|
71
57
|
response = await fetch(url, {
|
|
72
|
-
headers,
|
|
73
|
-
method,
|
|
74
|
-
body: JSON.stringify(data)
|
|
58
|
+
headers, method, body: JSON.stringify(data)
|
|
75
59
|
});
|
|
76
60
|
}
|
|
77
61
|
return response;
|
|
78
62
|
}
|
|
79
63
|
messageFeedback(messageId, rating, user) {
|
|
80
64
|
const data = {
|
|
81
|
-
rating,
|
|
82
|
-
user
|
|
65
|
+
rating, user
|
|
83
66
|
};
|
|
84
67
|
return this.sendRequest({ method: exports.routes.feedback.method, endpoint: exports.routes.feedback.url(messageId), data });
|
|
85
68
|
}
|
|
@@ -92,10 +75,7 @@ exports.DifyClient = DifyClient;
|
|
|
92
75
|
class CompletionClient extends DifyClient {
|
|
93
76
|
createCompletionMessage(inputs, query, user, responseMode) {
|
|
94
77
|
const data = {
|
|
95
|
-
inputs,
|
|
96
|
-
query,
|
|
97
|
-
responseMode,
|
|
98
|
-
user
|
|
78
|
+
inputs, query, responseMode, user
|
|
99
79
|
};
|
|
100
80
|
return this.sendRequest({
|
|
101
81
|
method: exports.routes.createCompletionMessage.method,
|
|
@@ -109,17 +89,14 @@ exports.CompletionClient = CompletionClient;
|
|
|
109
89
|
class ChatClient extends DifyClient {
|
|
110
90
|
async sendMessage(query, { systemMessage, user, responseMode = "json", conversationId = null, timeoutMs = 60 * 1000 }) {
|
|
111
91
|
const data = {
|
|
112
|
-
inputs: {},
|
|
113
|
-
query,
|
|
114
|
-
user,
|
|
115
|
-
responseMode
|
|
92
|
+
inputs: {}, query, user, responseMode
|
|
116
93
|
};
|
|
117
94
|
if (systemMessage || this.systemMessage) {
|
|
118
|
-
data.inputs[
|
|
95
|
+
data.inputs["systemMessage"] = systemMessage || this.systemMessage;
|
|
119
96
|
}
|
|
120
97
|
if (conversationId)
|
|
121
98
|
data.conversation_id = conversationId;
|
|
122
|
-
console.log(
|
|
99
|
+
console.log("request data", data);
|
|
123
100
|
const res = await this.sendRequest({
|
|
124
101
|
method: exports.routes.createChatMessage.method,
|
|
125
102
|
endpoint: exports.routes.createChatMessage.url(),
|
|
@@ -135,9 +112,7 @@ class ChatClient extends DifyClient {
|
|
|
135
112
|
}
|
|
136
113
|
const response = res.data;
|
|
137
114
|
return {
|
|
138
|
-
text: response.answer,
|
|
139
|
-
conversationId: response.conversation_id,
|
|
140
|
-
id: response.id
|
|
115
|
+
text: response.answer, conversationId: response.conversation_id, id: response.id
|
|
141
116
|
};
|
|
142
117
|
}
|
|
143
118
|
getConversationMessages(user, conversationId = "", firstId = null, limit = null) {
|
|
@@ -149,21 +124,19 @@ class ChatClient extends DifyClient {
|
|
|
149
124
|
if (limit)
|
|
150
125
|
params.limit = limit;
|
|
151
126
|
return this.sendRequest({
|
|
152
|
-
method: exports.routes.getConversationMessages.method,
|
|
153
|
-
endpoint: exports.routes.getConversationMessages.url(),
|
|
154
|
-
params
|
|
127
|
+
method: exports.routes.getConversationMessages.method, endpoint: exports.routes.getConversationMessages.url(), params
|
|
155
128
|
});
|
|
156
129
|
}
|
|
157
130
|
getConversations(user, firstId = null, limit = null, pinned = null) {
|
|
158
131
|
const params = { user, first_id: firstId, limit, pinned };
|
|
159
|
-
return this.sendRequest({
|
|
132
|
+
return this.sendRequest({
|
|
133
|
+
method: exports.routes.getConversations.method, endpoint: exports.routes.getConversations.url(), params
|
|
134
|
+
});
|
|
160
135
|
}
|
|
161
136
|
renameConversation(conversationId, name, user) {
|
|
162
137
|
const data = { name, user };
|
|
163
138
|
return this.sendRequest({
|
|
164
|
-
method: exports.routes.renameConversation.method,
|
|
165
|
-
endpoint: exports.routes.renameConversation.url(conversationId),
|
|
166
|
-
data
|
|
139
|
+
method: exports.routes.renameConversation.method, endpoint: exports.routes.renameConversation.url(conversationId), data
|
|
167
140
|
});
|
|
168
141
|
}
|
|
169
142
|
}
|
|
@@ -91,4 +91,11 @@ export function getRoomEveryDayContent(date: any, city: any, endWord: any): Prom
|
|
|
91
91
|
* @return {string}
|
|
92
92
|
*/
|
|
93
93
|
export function getCountDownContent(date: any, prefix: any, suffix: any, endWord: any): string;
|
|
94
|
+
/**
|
|
95
|
+
* 发送群公告
|
|
96
|
+
* @param roomIds
|
|
97
|
+
* @param content
|
|
98
|
+
* @return {Promise<void>}
|
|
99
|
+
*/
|
|
100
|
+
export function sendRoomNotice(room: any, content: any): Promise<void>;
|
|
94
101
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getCountDownContent = exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getNewsContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = void 0;
|
|
3
|
+
exports.sendRoomNotice = exports.getCountDownContent = exports.getRoomEveryDayContent = exports.updateContactAndRoom = exports.addRoomWelcomeSay = exports.roomSay = exports.contactSay = exports.addRoom = exports.updateRoomInfo = exports.updateContactInfo = exports.getNewsContent = exports.getEveryDayContent = exports.updateContactOnly = exports.updateRoomOnly = void 0;
|
|
4
4
|
const api_js_1 = require("../proxy/api.js");
|
|
5
5
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
6
6
|
const userDb_js_1 = require("../db/userDb.js");
|
|
@@ -343,6 +343,20 @@ async function addRoom(that, contact, roomName, replys) {
|
|
|
343
343
|
}
|
|
344
344
|
}
|
|
345
345
|
exports.addRoom = addRoom;
|
|
346
|
+
/**
|
|
347
|
+
* 发送群公告
|
|
348
|
+
* @param roomIds
|
|
349
|
+
* @param content
|
|
350
|
+
* @return {Promise<void>}
|
|
351
|
+
*/
|
|
352
|
+
async function sendRoomNotice(room, content) {
|
|
353
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
354
|
+
const { role } = config.userInfo;
|
|
355
|
+
if (role === 'vip' && room && content) {
|
|
356
|
+
await room.announce(content);
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.sendRoomNotice = sendRoomNotice;
|
|
346
360
|
/**
|
|
347
361
|
* 重新同步好友和群组
|
|
348
362
|
* @param that
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function reset(adminId: any): void;
|
|
2
2
|
export function resetAll(): void;
|
|
3
|
-
export function getChatGPTReply(content: any, uid: any, adminId: any, config
|
|
3
|
+
export function getChatGPTReply(content: any, uid: any, adminId: any, config: {
|
|
4
4
|
token: string;
|
|
5
5
|
debug: boolean;
|
|
6
6
|
proxyPass: string;
|
|
@@ -10,5 +10,5 @@ export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
|
|
|
10
10
|
model: string;
|
|
11
11
|
systemMessage: string;
|
|
12
12
|
keywordSystemMessages: never[];
|
|
13
|
-
}): Promise<any>;
|
|
13
|
+
} | undefined, isFastGPT: any): Promise<any>;
|
|
14
14
|
//# sourceMappingURL=chatgpt.d.ts.map
|
|
@@ -23,7 +23,7 @@ function resetAll() {
|
|
|
23
23
|
chatGPT = {};
|
|
24
24
|
}
|
|
25
25
|
exports.resetAll = resetAll;
|
|
26
|
-
async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }) {
|
|
26
|
+
async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }, isFastGPT) {
|
|
27
27
|
if (!config.token) {
|
|
28
28
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
29
29
|
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
@@ -41,7 +41,7 @@ async function getChatGPTReply(content, uid, adminId, config = { token: "", debu
|
|
|
41
41
|
content = content.replace(finalSystemMsg.keyword, '');
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
-
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
44
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT);
|
|
45
45
|
}
|
|
46
46
|
exports.getChatGPTReply = getChatGPTReply;
|
|
47
47
|
//# sourceMappingURL=chatgpt.js.map
|
|
@@ -22,7 +22,7 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
|
|
|
22
22
|
switch (botType) {
|
|
23
23
|
case 6:
|
|
24
24
|
// ChatGPT api
|
|
25
|
-
res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config);
|
|
25
|
+
res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, false);
|
|
26
26
|
replys = res;
|
|
27
27
|
break;
|
|
28
28
|
case 7:
|
|
@@ -37,6 +37,11 @@ async function dispatchBot({ botType, content, uid, adminId, config }) {
|
|
|
37
37
|
res = await (0, dify_js_1.getDifyAiReply)(content, uid, adminId, config);
|
|
38
38
|
replys = res;
|
|
39
39
|
break;
|
|
40
|
+
case 9:
|
|
41
|
+
// fastGPT api
|
|
42
|
+
res = await (0, chatgpt_js_1.getChatGPTReply)(content, uid, adminId, config, true);
|
|
43
|
+
replys = res;
|
|
44
|
+
break;
|
|
40
45
|
default:
|
|
41
46
|
replys = [];
|
|
42
47
|
break;
|
|
@@ -132,6 +132,20 @@ async function initMqtt(that) {
|
|
|
132
132
|
await (0, aibotk_js_1.getRssConfig)();
|
|
133
133
|
void (0, rss_js_1.initRssTask)(that);
|
|
134
134
|
}
|
|
135
|
+
else if (topic === `aibotk/${userId}/roomnotice`) {
|
|
136
|
+
console.log('发送群公告请求');
|
|
137
|
+
const rooms = content.rooms;
|
|
138
|
+
for (let item of rooms) {
|
|
139
|
+
const room = await that.Room.find({ id: item.wxid, topic: item.name });
|
|
140
|
+
if (room) {
|
|
141
|
+
await index_js_1.sendRoomNotice.call(that, room, content.content);
|
|
142
|
+
await (0, index_js_3.delay)(1000);
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
console.log(`没有找到群:【${item.name}】,无法发送群公告`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
135
149
|
});
|
|
136
150
|
}
|
|
137
151
|
}
|
|
@@ -17,7 +17,7 @@ function reset() {
|
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
exports.reset = reset;
|
|
20
|
-
async function getGptOfficialReply(content, uid) {
|
|
20
|
+
async function getGptOfficialReply(content, uid, isFastGPT) {
|
|
21
21
|
const config = await (0, configDb_js_1.allConfig)();
|
|
22
22
|
if (!config.gpttoken) {
|
|
23
23
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
@@ -43,7 +43,7 @@ async function getGptOfficialReply(content, uid) {
|
|
|
43
43
|
if (!chatGPT) {
|
|
44
44
|
chatGPT = new officialOpenAi_js_1.default(chatConfig);
|
|
45
45
|
}
|
|
46
|
-
return await chatGPT.getReply(content, uid);
|
|
46
|
+
return await chatGPT.getReply(content, uid, '', '', isFastGPT);
|
|
47
47
|
}
|
|
48
48
|
exports.getGptOfficialReply = getGptOfficialReply;
|
|
49
49
|
//# sourceMappingURL=openAi.js.map
|
|
@@ -164,8 +164,8 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
164
164
|
replys = res;
|
|
165
165
|
break;
|
|
166
166
|
case 6:
|
|
167
|
-
//
|
|
168
|
-
res = await (0, openAi_js_1.getGptOfficialReply)(msg, id);
|
|
167
|
+
// ChatGPT-api
|
|
168
|
+
res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, false);
|
|
169
169
|
replys = res;
|
|
170
170
|
break;
|
|
171
171
|
case 7:
|
|
@@ -178,6 +178,11 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
178
178
|
res = await (0, difyAi_js_1.getDifyReply)(msg, id);
|
|
179
179
|
replys = res;
|
|
180
180
|
break;
|
|
181
|
+
case 9:
|
|
182
|
+
// fast gpt
|
|
183
|
+
res = await (0, openAi_js_1.getGptOfficialReply)(msg, id, true);
|
|
184
|
+
replys = res;
|
|
185
|
+
break;
|
|
181
186
|
default:
|
|
182
187
|
replys = [{ type: 1, content: '' }];
|
|
183
188
|
break;
|
|
@@ -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
|
|
62
|
+
getReply(content: any, uid: any, adminId: string | undefined, systemMessage: string | undefined, isFastGPT: any): Promise<{
|
|
63
63
|
type: number;
|
|
64
64
|
content: any;
|
|
65
65
|
}[]>;
|
|
@@ -107,10 +107,10 @@ class OfficialOpenAi {
|
|
|
107
107
|
reset() {
|
|
108
108
|
this.chatGPT = null;
|
|
109
109
|
}
|
|
110
|
-
async getReply(content, uid, adminId = '', systemMessage = '') {
|
|
110
|
+
async getReply(content, uid, adminId = '', systemMessage = '', isFastGPT) {
|
|
111
111
|
try {
|
|
112
112
|
if (!this.chatGPT) {
|
|
113
|
-
console.log('看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
113
|
+
console.log(isFastGPT ? '看到此消息说明启用了fastgpt' : '看到此消息说明已启用最新版chat gpt 3.5 turbo模型');
|
|
114
114
|
await this.init();
|
|
115
115
|
}
|
|
116
116
|
if (this.config.filter) {
|
|
@@ -127,7 +127,14 @@ class OfficialOpenAi {
|
|
|
127
127
|
return [{ type: 1, content: '上下文已重置' }];
|
|
128
128
|
}
|
|
129
129
|
}
|
|
130
|
-
const
|
|
130
|
+
const sendParams = { ...this.chatOption[uid], timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
|
|
131
|
+
if (systemMessage) {
|
|
132
|
+
sendParams.systemMessage = systemMessage;
|
|
133
|
+
}
|
|
134
|
+
if (isFastGPT) {
|
|
135
|
+
sendParams.chatId = uid;
|
|
136
|
+
}
|
|
137
|
+
const { conversationId, text, id } = await this.chatGPT.sendMessage(content, sendParams);
|
|
131
138
|
if (this.config.filter) {
|
|
132
139
|
const censor = await this.contentCensor.checkText(text);
|
|
133
140
|
if (!censor) {
|
|
@@ -141,7 +141,7 @@ Current date: ${currentDate}`;
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
async sendMessage(text, opts = {}) {
|
|
144
|
-
const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId } = opts;
|
|
144
|
+
const { parentMessageId, messageId = uuidv4(), timeoutMs, onProgress, stream = !!onProgress, completionParams, conversationId, chatId } = opts;
|
|
145
145
|
let { abortSignal } = opts;
|
|
146
146
|
let abortController = null;
|
|
147
147
|
if (timeoutMs && !abortSignal) {
|
|
@@ -177,6 +177,9 @@ Current date: ${currentDate}`;
|
|
|
177
177
|
messages,
|
|
178
178
|
stream
|
|
179
179
|
};
|
|
180
|
+
if (chatId) {
|
|
181
|
+
body.chatId = chatId;
|
|
182
|
+
}
|
|
180
183
|
if (this._apiOrg) {
|
|
181
184
|
headers["OpenAI-Organization"] = this._apiOrg;
|
|
182
185
|
}
|
|
@@ -2,32 +2,19 @@ import axios from "axios";
|
|
|
2
2
|
export const BASE_URL = "https://api.dify.ai/v1";
|
|
3
3
|
export const routes = {
|
|
4
4
|
application: {
|
|
5
|
-
method: "GET",
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
method: "POST",
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
method: "
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
method: "
|
|
18
|
-
url: () => `/chat-messages`
|
|
19
|
-
},
|
|
20
|
-
getConversationMessages: {
|
|
21
|
-
method: "GET",
|
|
22
|
-
url: () => "/messages"
|
|
23
|
-
},
|
|
24
|
-
getConversations: {
|
|
25
|
-
method: "GET",
|
|
26
|
-
url: () => "/conversations"
|
|
27
|
-
},
|
|
28
|
-
renameConversation: {
|
|
29
|
-
method: "PATCH",
|
|
30
|
-
url: (conversationId) => `/conversations/${conversationId}`
|
|
5
|
+
method: "GET", url: () => `/parameters`
|
|
6
|
+
}, feedback: {
|
|
7
|
+
method: "POST", url: (messageId) => `/messages/${messageId}/feedbacks`
|
|
8
|
+
}, createCompletionMessage: {
|
|
9
|
+
method: "POST", url: () => `/completion-messages`
|
|
10
|
+
}, createChatMessage: {
|
|
11
|
+
method: "POST", url: () => `/chat-messages`
|
|
12
|
+
}, getConversationMessages: {
|
|
13
|
+
method: "GET", url: () => "/messages"
|
|
14
|
+
}, getConversations: {
|
|
15
|
+
method: "GET", url: () => "/conversations"
|
|
16
|
+
}, renameConversation: {
|
|
17
|
+
method: "PATCH", url: (conversationId) => `/conversations/${conversationId}`
|
|
31
18
|
}
|
|
32
19
|
};
|
|
33
20
|
export class DifyClient {
|
|
@@ -42,8 +29,7 @@ export class DifyClient {
|
|
|
42
29
|
}
|
|
43
30
|
async sendRequest({ method, endpoint, data, params, stream = false, timeoutMs = 60 * 1000 }) {
|
|
44
31
|
const headers = {
|
|
45
|
-
"Authorization": `Bearer ${this.apiKey}`,
|
|
46
|
-
"Content-Type": "application/json"
|
|
32
|
+
"Authorization": `Bearer ${this.apiKey}`, "Content-Type": "application/json"
|
|
47
33
|
};
|
|
48
34
|
const url = `${this.baseUrl}${endpoint}`;
|
|
49
35
|
let response;
|
|
@@ -63,17 +49,14 @@ export class DifyClient {
|
|
|
63
49
|
}
|
|
64
50
|
else {
|
|
65
51
|
response = await fetch(url, {
|
|
66
|
-
headers,
|
|
67
|
-
method,
|
|
68
|
-
body: JSON.stringify(data)
|
|
52
|
+
headers, method, body: JSON.stringify(data)
|
|
69
53
|
});
|
|
70
54
|
}
|
|
71
55
|
return response;
|
|
72
56
|
}
|
|
73
57
|
messageFeedback(messageId, rating, user) {
|
|
74
58
|
const data = {
|
|
75
|
-
rating,
|
|
76
|
-
user
|
|
59
|
+
rating, user
|
|
77
60
|
};
|
|
78
61
|
return this.sendRequest({ method: routes.feedback.method, endpoint: routes.feedback.url(messageId), data });
|
|
79
62
|
}
|
|
@@ -85,10 +68,7 @@ export class DifyClient {
|
|
|
85
68
|
export class CompletionClient extends DifyClient {
|
|
86
69
|
createCompletionMessage(inputs, query, user, responseMode) {
|
|
87
70
|
const data = {
|
|
88
|
-
inputs,
|
|
89
|
-
query,
|
|
90
|
-
responseMode,
|
|
91
|
-
user
|
|
71
|
+
inputs, query, responseMode, user
|
|
92
72
|
};
|
|
93
73
|
return this.sendRequest({
|
|
94
74
|
method: routes.createCompletionMessage.method,
|
|
@@ -101,17 +81,14 @@ export class CompletionClient extends DifyClient {
|
|
|
101
81
|
export class ChatClient extends DifyClient {
|
|
102
82
|
async sendMessage(query, { systemMessage, user, responseMode = "json", conversationId = null, timeoutMs = 60 * 1000 }) {
|
|
103
83
|
const data = {
|
|
104
|
-
inputs: {},
|
|
105
|
-
query,
|
|
106
|
-
user,
|
|
107
|
-
responseMode
|
|
84
|
+
inputs: {}, query, user, responseMode
|
|
108
85
|
};
|
|
109
86
|
if (systemMessage || this.systemMessage) {
|
|
110
|
-
data.inputs[
|
|
87
|
+
data.inputs["systemMessage"] = systemMessage || this.systemMessage;
|
|
111
88
|
}
|
|
112
89
|
if (conversationId)
|
|
113
90
|
data.conversation_id = conversationId;
|
|
114
|
-
console.log(
|
|
91
|
+
console.log("request data", data);
|
|
115
92
|
const res = await this.sendRequest({
|
|
116
93
|
method: routes.createChatMessage.method,
|
|
117
94
|
endpoint: routes.createChatMessage.url(),
|
|
@@ -127,9 +104,7 @@ export class ChatClient extends DifyClient {
|
|
|
127
104
|
}
|
|
128
105
|
const response = res.data;
|
|
129
106
|
return {
|
|
130
|
-
text: response.answer,
|
|
131
|
-
conversationId: response.conversation_id,
|
|
132
|
-
id: response.id
|
|
107
|
+
text: response.answer, conversationId: response.conversation_id, id: response.id
|
|
133
108
|
};
|
|
134
109
|
}
|
|
135
110
|
getConversationMessages(user, conversationId = "", firstId = null, limit = null) {
|
|
@@ -141,21 +116,19 @@ export class ChatClient extends DifyClient {
|
|
|
141
116
|
if (limit)
|
|
142
117
|
params.limit = limit;
|
|
143
118
|
return this.sendRequest({
|
|
144
|
-
method: routes.getConversationMessages.method,
|
|
145
|
-
endpoint: routes.getConversationMessages.url(),
|
|
146
|
-
params
|
|
119
|
+
method: routes.getConversationMessages.method, endpoint: routes.getConversationMessages.url(), params
|
|
147
120
|
});
|
|
148
121
|
}
|
|
149
122
|
getConversations(user, firstId = null, limit = null, pinned = null) {
|
|
150
123
|
const params = { user, first_id: firstId, limit, pinned };
|
|
151
|
-
return this.sendRequest({
|
|
124
|
+
return this.sendRequest({
|
|
125
|
+
method: routes.getConversations.method, endpoint: routes.getConversations.url(), params
|
|
126
|
+
});
|
|
152
127
|
}
|
|
153
128
|
renameConversation(conversationId, name, user) {
|
|
154
129
|
const data = { name, user };
|
|
155
130
|
return this.sendRequest({
|
|
156
|
-
method: routes.renameConversation.method,
|
|
157
|
-
endpoint: routes.renameConversation.url(conversationId),
|
|
158
|
-
data
|
|
131
|
+
method: routes.renameConversation.method, endpoint: routes.renameConversation.url(conversationId), data
|
|
159
132
|
});
|
|
160
133
|
}
|
|
161
134
|
}
|
|
@@ -91,4 +91,11 @@ export function getRoomEveryDayContent(date: any, city: any, endWord: any): Prom
|
|
|
91
91
|
* @return {string}
|
|
92
92
|
*/
|
|
93
93
|
export function getCountDownContent(date: any, prefix: any, suffix: any, endWord: any): string;
|
|
94
|
+
/**
|
|
95
|
+
* 发送群公告
|
|
96
|
+
* @param roomIds
|
|
97
|
+
* @param content
|
|
98
|
+
* @return {Promise<void>}
|
|
99
|
+
*/
|
|
100
|
+
export function sendRoomNotice(room: any, content: any): Promise<void>;
|
|
94
101
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -330,6 +330,19 @@ async function addRoom(that, contact, roomName, replys) {
|
|
|
330
330
|
console.log(`不存在此群:${roomName}`);
|
|
331
331
|
}
|
|
332
332
|
}
|
|
333
|
+
/**
|
|
334
|
+
* 发送群公告
|
|
335
|
+
* @param roomIds
|
|
336
|
+
* @param content
|
|
337
|
+
* @return {Promise<void>}
|
|
338
|
+
*/
|
|
339
|
+
async function sendRoomNotice(room, content) {
|
|
340
|
+
const config = await allConfig();
|
|
341
|
+
const { role } = config.userInfo;
|
|
342
|
+
if (role === 'vip' && room && content) {
|
|
343
|
+
await room.announce(content);
|
|
344
|
+
}
|
|
345
|
+
}
|
|
333
346
|
/**
|
|
334
347
|
* 重新同步好友和群组
|
|
335
348
|
* @param that
|
|
@@ -380,6 +393,7 @@ export { addRoomWelcomeSay };
|
|
|
380
393
|
export { updateContactAndRoom };
|
|
381
394
|
export { getRoomEveryDayContent };
|
|
382
395
|
export { getCountDownContent };
|
|
396
|
+
export { sendRoomNotice };
|
|
383
397
|
export default {
|
|
384
398
|
updateRoomOnly,
|
|
385
399
|
updateContactOnly,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export function reset(adminId: any): void;
|
|
2
2
|
export function resetAll(): void;
|
|
3
|
-
export function getChatGPTReply(content: any, uid: any, adminId: any, config
|
|
3
|
+
export function getChatGPTReply(content: any, uid: any, adminId: any, config: {
|
|
4
4
|
token: string;
|
|
5
5
|
debug: boolean;
|
|
6
6
|
proxyPass: string;
|
|
@@ -10,5 +10,5 @@ export function getChatGPTReply(content: any, uid: any, adminId: any, config?: {
|
|
|
10
10
|
model: string;
|
|
11
11
|
systemMessage: string;
|
|
12
12
|
keywordSystemMessages: never[];
|
|
13
|
-
}): Promise<any>;
|
|
13
|
+
} | undefined, isFastGPT: any): Promise<any>;
|
|
14
14
|
//# sourceMappingURL=chatgpt.d.ts.map
|
|
@@ -15,7 +15,7 @@ export function resetAll() {
|
|
|
15
15
|
});
|
|
16
16
|
chatGPT = {};
|
|
17
17
|
}
|
|
18
|
-
export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }) {
|
|
18
|
+
export async function getChatGPTReply(content, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80, model: "", systemMessage: "", keywordSystemMessages: [] }, isFastGPT) {
|
|
19
19
|
if (!config.token) {
|
|
20
20
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
21
21
|
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
@@ -33,6 +33,6 @@ export async function getChatGPTReply(content, uid, adminId, config = { token: "
|
|
|
33
33
|
content = content.replace(finalSystemMsg.keyword, '');
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage);
|
|
36
|
+
return await chatGPT[adminId].getReply(content, uid, adminId, systemMessage, isFastGPT);
|
|
37
37
|
}
|
|
38
38
|
//# sourceMappingURL=chatgpt.js.map
|
|
@@ -16,7 +16,7 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
|
|
|
16
16
|
switch (botType) {
|
|
17
17
|
case 6:
|
|
18
18
|
// ChatGPT api
|
|
19
|
-
res = await getChatGPTReply(content, uid, adminId, config);
|
|
19
|
+
res = await getChatGPTReply(content, uid, adminId, config, false);
|
|
20
20
|
replys = res;
|
|
21
21
|
break;
|
|
22
22
|
case 7:
|
|
@@ -31,6 +31,11 @@ export async function dispatchBot({ botType, content, uid, adminId, config }) {
|
|
|
31
31
|
res = await getDifyAiReply(content, uid, adminId, config);
|
|
32
32
|
replys = res;
|
|
33
33
|
break;
|
|
34
|
+
case 9:
|
|
35
|
+
// fastGPT api
|
|
36
|
+
res = await getChatGPTReply(content, uid, adminId, config, true);
|
|
37
|
+
replys = res;
|
|
38
|
+
break;
|
|
34
39
|
default:
|
|
35
40
|
replys = [];
|
|
36
41
|
break;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as mqtt from 'mqtt';
|
|
2
2
|
import { allConfig } from '../db/configDb.js';
|
|
3
|
-
import { contactSay, roomSay } from '../common/index.js';
|
|
3
|
+
import { contactSay, roomSay, sendRoomNotice } from '../common/index.js';
|
|
4
4
|
import { getConfig, getMqttConfig, getGptConfig, getRssConfig } from "./aibotk.js";
|
|
5
5
|
import { dispatchEventContent } from '../service/event-dispatch-service.js';
|
|
6
6
|
import { sendTaskMessage } from "../task/index.js";
|
|
7
|
-
import { randomRange } from
|
|
7
|
+
import { delay, randomRange } from "../lib/index.js";
|
|
8
8
|
import { reset } from './bot/chatgpt.js';
|
|
9
9
|
import { reset as webReset } from './bot/chatgpt-web.js';
|
|
10
10
|
import { reset as difyReset } from './bot/dify.js';
|
|
@@ -106,6 +106,20 @@ async function initMqtt(that) {
|
|
|
106
106
|
await getRssConfig();
|
|
107
107
|
void initRssTask(that);
|
|
108
108
|
}
|
|
109
|
+
else if (topic === `aibotk/${userId}/roomnotice`) {
|
|
110
|
+
console.log('发送群公告请求');
|
|
111
|
+
const rooms = content.rooms;
|
|
112
|
+
for (let item of rooms) {
|
|
113
|
+
const room = await that.Room.find({ id: item.wxid, topic: item.name });
|
|
114
|
+
if (room) {
|
|
115
|
+
await sendRoomNotice.call(that, room, content.content);
|
|
116
|
+
await delay(1000);
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
console.log(`没有找到群:【${item.name}】,无法发送群公告`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}
|
|
109
123
|
});
|
|
110
124
|
}
|
|
111
125
|
}
|
|
@@ -10,7 +10,7 @@ export function reset() {
|
|
|
10
10
|
chatGPT = null;
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
|
-
export async function getGptOfficialReply(content, uid) {
|
|
13
|
+
export async function getGptOfficialReply(content, uid, isFastGPT) {
|
|
14
14
|
const config = await allConfig();
|
|
15
15
|
if (!config.gpttoken) {
|
|
16
16
|
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
@@ -36,6 +36,6 @@ export async function getGptOfficialReply(content, uid) {
|
|
|
36
36
|
if (!chatGPT) {
|
|
37
37
|
chatGPT = new OfficialOpenAi(chatConfig);
|
|
38
38
|
}
|
|
39
|
-
return await chatGPT.getReply(content, uid);
|
|
39
|
+
return await chatGPT.getReply(content, uid, '', '', isFastGPT);
|
|
40
40
|
}
|
|
41
41
|
//# sourceMappingURL=openAi.js.map
|
|
@@ -157,8 +157,8 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
157
157
|
replys = res;
|
|
158
158
|
break;
|
|
159
159
|
case 6:
|
|
160
|
-
//
|
|
161
|
-
res = await getGptOfficialReply(msg, id);
|
|
160
|
+
// ChatGPT-api
|
|
161
|
+
res = await getGptOfficialReply(msg, id, false);
|
|
162
162
|
replys = res;
|
|
163
163
|
break;
|
|
164
164
|
case 7:
|
|
@@ -171,6 +171,11 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
171
171
|
res = await getDifyReply(msg, id);
|
|
172
172
|
replys = res;
|
|
173
173
|
break;
|
|
174
|
+
case 9:
|
|
175
|
+
// fast gpt
|
|
176
|
+
res = await getGptOfficialReply(msg, id, true);
|
|
177
|
+
replys = res;
|
|
178
|
+
break;
|
|
174
179
|
default:
|
|
175
180
|
replys = [{ type: 1, content: '' }];
|
|
176
181
|
break;
|