wechaty-web-panel 1.6.112 → 1.6.113
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/dist/bot/chatgpt/index.js +235 -0
- package/dist/bot/coze/sdk/index.js +110 -0
- package/dist/bot/dify/sdk/index.js +461 -0
- package/dist/bot/dify/sdk/office.js +319 -0
- package/dist/bot/fastgpt/index.js +98 -0
- package/dist/bot/qanything/index.js +136 -0
- package/dist/botInstance/coze.js +167 -0
- package/dist/botInstance/cozev3.js +157 -0
- package/dist/botInstance/dify.js +160 -0
- package/dist/botInstance/fastgpt.js +130 -0
- package/dist/botInstance/gpt4v.js +95 -0
- package/dist/botInstance/officialOpenAi.js +186 -0
- package/dist/botInstance/qany.js +144 -0
- package/dist/botInstance/sdk/chatGPT4V.js +89 -0
- package/dist/botInstance/sdk/coze.js +200 -0
- package/dist/botInstance/sdk/difyClient.js +354 -0
- package/dist/botInstance/sdk/pTimeout.js +97 -0
- package/dist/botInstance/sdk/qanything.js +137 -0
- package/dist/botInstance/sdk/quick-lru.js +237 -0
- package/dist/common/hook.js +66 -0
- package/dist/common/index.js +513 -0
- package/dist/common/multiReply.js +158 -0
- package/dist/common/reply.js +23 -0
- package/dist/const/puppet-type.js +71 -0
- package/dist/db/aiDb.js +27 -0
- package/dist/db/aichatDb.js +84 -0
- package/dist/db/chatHistory.js +137 -0
- package/dist/db/configDb.js +97 -0
- package/dist/db/global.js +62 -0
- package/dist/db/gptConfig.js +85 -0
- package/dist/db/nedb.js +88 -0
- package/dist/db/puppetDb.js +58 -0
- package/dist/db/roomDb.js +83 -0
- package/dist/db/rssConfig.js +82 -0
- package/dist/db/rssHistory.js +88 -0
- package/dist/db/userDb.js +27 -0
- package/dist/handlers/on-callback-message.js +183 -0
- package/dist/handlers/on-error.js +5 -0
- package/dist/handlers/on-friend.js +62 -0
- package/dist/handlers/on-heartbeat.js +20 -0
- package/dist/handlers/on-login.js +58 -0
- package/dist/handlers/on-logout.js +17 -0
- package/dist/handlers/on-message.js +644 -0
- package/dist/handlers/on-ready.js +36 -0
- package/dist/handlers/on-record-message.js +56 -0
- package/dist/handlers/on-roomjoin.js +42 -0
- package/dist/handlers/on-roomleave.js +12 -0
- package/dist/handlers/on-roomtopic.js +16 -0
- package/dist/handlers/on-scan.js +64 -0
- package/dist/handlers/on-verifycode.js +42 -0
- package/dist/index.js +81 -69306
- package/dist/lib/contentCensor.js +23 -0
- package/dist/lib/index.js +562 -0
- package/dist/lib/oss.js +43 -0
- package/dist/lib/s3oss.js +33 -0
- package/dist/mcp/mcp-server.js +26 -0
- package/dist/mcp/src/config/database.js +51 -0
- package/dist/mcp/src/index.js +238 -0
- package/dist/mcp/src/mcp/schemas.js +178 -0
- package/dist/mcp/src/mcp/server.js +421 -0
- package/dist/mcp/src/mcp/streamable-server.js +690 -0
- package/dist/mcp/src/models/ChatMessage.js +151 -0
- package/dist/mcp/src/models/Friend.js +64 -0
- package/dist/mcp/src/models/Group.js +55 -0
- package/dist/mcp/src/models/GroupMember.js +67 -0
- package/dist/mcp/src/models/index.js +27 -0
- package/dist/mcp/src/scripts/migrate.js +21 -0
- package/dist/mcp/src/services/ChatDataService.js +284 -0
- package/dist/mcp/src/services/McpService.js +521 -0
- package/dist/mcp/src/services/McpTools.js +504 -0
- package/dist/mcp/streamable-examples.js +283 -0
- package/dist/mcp/streamable-server.js +79 -0
- package/dist/mcp/test-mcp.js +64 -0
- package/dist/mcp/test-streamable-server.js +86 -0
- package/dist/package-json.js +89 -0
- package/dist/proxy/aibotk.js +829 -0
- package/dist/proxy/api.js +431 -0
- package/dist/proxy/apib.js +587 -0
- package/dist/proxy/bot/chatgpt.js +38 -0
- package/dist/proxy/bot/coze.js +38 -0
- package/dist/proxy/bot/cozev3.js +38 -0
- package/dist/proxy/bot/dify.js +38 -0
- package/dist/proxy/bot/dispatch.js +81 -0
- package/dist/proxy/bot/fastgpt.js +27 -0
- package/dist/proxy/bot/qany.js +27 -0
- package/dist/proxy/config.js +14 -0
- package/dist/proxy/cozeAi.js +60 -0
- package/dist/proxy/cozeV3Ai.js +60 -0
- package/dist/proxy/difyAi.js +58 -0
- package/dist/proxy/fastgpt.js +55 -0
- package/dist/proxy/mqtt.js +275 -0
- package/dist/proxy/multimodal.js +122 -0
- package/dist/proxy/openAi.js +63 -0
- package/dist/proxy/outapi.js +62 -0
- package/dist/proxy/qAnyAi.js +57 -0
- package/dist/proxy/superagent.js +200 -0
- package/dist/proxy/tencent-open.js +255 -0
- package/dist/service/event-dispatch-service.js +309 -0
- package/dist/service/gpt4vService.js +45 -0
- package/dist/service/msg-filter-service.js +121 -0
- package/dist/service/msg-filters.js +645 -0
- package/dist/service/room-async-service.js +455 -0
- package/dist/task/index.js +535 -0
- package/dist/task/rss.js +174 -0
- package/package.json +2 -2
- package/src/package-json.js +2 -2
- package/tsconfig.json +3 -12
- package/dist/index.d.ts +0 -9
- package/tsconfig.cjs.json +0 -12
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import * as mqtt from 'mqtt';
|
|
2
|
+
import { allConfig } from '../db/configDb.js';
|
|
3
|
+
import { contactSay, roomSay, sendRoomNotice } from '../common/index.js';
|
|
4
|
+
import { getConfig, getGptConfig, getMqttConfig, getRssConfig, getTasks, getVerifyCode } from "./aibotk.js";
|
|
5
|
+
import { dispatchEventContent } from '../service/event-dispatch-service.js';
|
|
6
|
+
import { initMultiTask, sendMultiTaskMessage, sendTaskMessage } from "../task/index.js";
|
|
7
|
+
import { delay, randomRange } from "../lib/index.js";
|
|
8
|
+
import { reset } from './bot/chatgpt.js';
|
|
9
|
+
import { reset as difyReset } from './bot/dify.js';
|
|
10
|
+
import { reset as cozeReset } from './bot/coze.js';
|
|
11
|
+
import { reset as qanyReset } from './bot/qany.js';
|
|
12
|
+
import { reset as cozeV3Reset } from './bot/cozev3.js';
|
|
13
|
+
import { initRssTask, sendRssTaskMessage } from "../task/rss.js";
|
|
14
|
+
import globalConfig from "../db/global.js";
|
|
15
|
+
import { resetScanTime } from '../handlers/on-scan.js';
|
|
16
|
+
import { clearHistory } from "../db/chatHistory.js";
|
|
17
|
+
let mqttclient = null;
|
|
18
|
+
async function getContact(that, contact) {
|
|
19
|
+
const contactInfo = (contact.wxid && await that.Contact.find({ id: contact.wxid || '' })) || (contact.id && await that.Contact.find({ id: contact.id || '' })) || (contact.name && await that.Contact.find({ name: contact.name || '' })) || (contact.alias && await that.Contact.find({ alias: contact.alias || '' })) || (contact.weixin && await that.Contact.find({ weixin: contact.weixin || '' }));
|
|
20
|
+
return contactInfo;
|
|
21
|
+
}
|
|
22
|
+
async function getRoom(that, room) {
|
|
23
|
+
const roomInfo = (room.wxid && await that.Room.find({ id: room.wxid || '' })) || (room.id && await that.Room.find({ id: room.id || '' })) || (room.name && await that.Room.find({ topic: room.name || '' })) || (room.roomName && await that.Room.find({ topic: room.roomName || '' }));
|
|
24
|
+
return roomInfo;
|
|
25
|
+
}
|
|
26
|
+
async function sendRoomSay(that, room, messages, atList) {
|
|
27
|
+
console.log(`收到群:${room.name}批量发送消息请求, 消息数量【${messages.length}】`);
|
|
28
|
+
const finalRoom = await getRoom(that, room);
|
|
29
|
+
if (!finalRoom) {
|
|
30
|
+
console.log(`查找不到群:${room.name},请检查群名是否正确`);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
for (let message of messages) {
|
|
35
|
+
const atContacts = await getAtContacts(that, atList);
|
|
36
|
+
await roomSay.call(that, finalRoom, atContacts, message);
|
|
37
|
+
await delay(500);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async function sendContactSay(that, contact, messages) {
|
|
42
|
+
console.log(`收到好友:${contact.name}批量发送消息请求, 消息数量【${messages.length}】`);
|
|
43
|
+
const finalContact = await getContact(that, contact);
|
|
44
|
+
if (!finalContact) {
|
|
45
|
+
console.log(`查找不到好友:${contact.name},请检查好友名称是否正确`);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
for (let message of messages) {
|
|
50
|
+
await contactSay.call(that, finalContact, message);
|
|
51
|
+
await delay(500);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async function getAtContacts(that, atList) {
|
|
56
|
+
if (!atList || atList.length === 0)
|
|
57
|
+
return '';
|
|
58
|
+
console.log('atList', atList);
|
|
59
|
+
let contacts = [];
|
|
60
|
+
for (let contact of atList) {
|
|
61
|
+
if (contact.id === '@all' || contact.name === '@all') {
|
|
62
|
+
contacts.push('@all');
|
|
63
|
+
return contacts;
|
|
64
|
+
}
|
|
65
|
+
let atContact = await getContact(that, contact);
|
|
66
|
+
if (atContact) {
|
|
67
|
+
contacts.push(atContact);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
console.log('search contact', contacts);
|
|
71
|
+
return contacts;
|
|
72
|
+
}
|
|
73
|
+
async function sendRoomsNotice(that, room, messages) {
|
|
74
|
+
console.log(`收到群:${room.name}批量发送群公告请求, 公告数量【${messages.length}】`);
|
|
75
|
+
const finalRoom = await getRoom(that, room);
|
|
76
|
+
if (!finalRoom) {
|
|
77
|
+
console.log(`查找不到群:${room.name},请检查群名是否正确`);
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
for (let message of messages) {
|
|
82
|
+
await sendRoomNotice.call(that, finalRoom, message.content);
|
|
83
|
+
await delay(500);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
async function initMqtt(that) {
|
|
88
|
+
try {
|
|
89
|
+
await getConfig(); // 获取配置文件
|
|
90
|
+
const config = await allConfig();
|
|
91
|
+
const { userId, name, role } = config.userInfo;
|
|
92
|
+
if (role === 'vip') {
|
|
93
|
+
const config = await getMqttConfig();
|
|
94
|
+
const { host, port, username, password, clientId } = config;
|
|
95
|
+
if (!mqttclient) {
|
|
96
|
+
mqttclient = host
|
|
97
|
+
? mqtt.connect(`${host}:${port}`, {
|
|
98
|
+
username: username,
|
|
99
|
+
password: password,
|
|
100
|
+
clientId: clientId + randomRange(1, 10000),
|
|
101
|
+
})
|
|
102
|
+
: null;
|
|
103
|
+
}
|
|
104
|
+
if (mqttclient) {
|
|
105
|
+
mqttclient.on('connect', function () {
|
|
106
|
+
console.debug('connect to Wechaty mqtt----------');
|
|
107
|
+
mqttclient.subscribe(`aibotk/${userId}/+`, function (err) {
|
|
108
|
+
if (err) {
|
|
109
|
+
console.log(err);
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
mqttclient.on('reconnect', function (e) {
|
|
114
|
+
console.log('subscriber on reconnect');
|
|
115
|
+
});
|
|
116
|
+
mqttclient.on('disconnect', function (e) {
|
|
117
|
+
console.log('disconnect--------', e);
|
|
118
|
+
});
|
|
119
|
+
mqttclient.on('error', function (e) {
|
|
120
|
+
console.debug('error----------', e);
|
|
121
|
+
});
|
|
122
|
+
mqttclient.on('message', async function (topic, message) {
|
|
123
|
+
const content = JSON.parse(message.toString());
|
|
124
|
+
if (topic === `aibotk/${userId}/say`) {
|
|
125
|
+
if (content.target === 'Room' || content.target === 'room') {
|
|
126
|
+
console.log(`收到群:${content.roomName || content.wxid}发送消息请求: ${content.message.content || content.message.url}`);
|
|
127
|
+
const room = content.wxid && await that.Room.find({ id: content.wxid }) || content.roomName && await that.Room.find({ topic: content.roomName });
|
|
128
|
+
if (!room) {
|
|
129
|
+
console.log(`查找不到群:${content.roomName},请检查群名是否正确`);
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
const atContacts = content?.atList && content?.atList.length ? await getAtContacts(that, content?.atList) : '';
|
|
134
|
+
await roomSay.call(that, room, atContacts, content.message);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else if (content.target === 'Contact' || content.target === 'contact') {
|
|
138
|
+
console.log(`收到联系人:${content.alias || content.name}发送消息请求: ${content.message.content || content.message.url}`);
|
|
139
|
+
let contact = await getContact(that, content); // 获取你要发送的联系人
|
|
140
|
+
if (!contact) {
|
|
141
|
+
console.log(`查找不到联系人:${content.name || content.alias},请检查联系人名称是否正确`);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
await contactSay.call(that, contact, content.message);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (topic === `aibotk/${userId}/multisay`) {
|
|
150
|
+
console.log('触发批量发送消息请求', content.target);
|
|
151
|
+
if (content.target === 'Room' || content.target === 'room') {
|
|
152
|
+
for (let room of content.groups) {
|
|
153
|
+
await sendRoomSay(that, room, content.messages, content?.atList);
|
|
154
|
+
await delay(600);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
else if (content.target === 'Contact' || content.target === 'contact') {
|
|
158
|
+
for (let contact of content.groups) {
|
|
159
|
+
await sendContactSay(that, contact, content.messages);
|
|
160
|
+
await delay(600);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
else if (content.target === 'RoomNotice' || content.target === 'roomnotice' || content.target === 'roomNotice') {
|
|
164
|
+
for (let room of content.groups) {
|
|
165
|
+
await sendRoomsNotice(that, room, content.messages);
|
|
166
|
+
await delay(600);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
else if (topic === `aibotk/${userId}/event`) {
|
|
171
|
+
if (content.target === 'system') {
|
|
172
|
+
console.log('触发了内置事件');
|
|
173
|
+
const eventName = content.event;
|
|
174
|
+
const res = await dispatchEventContent(that, eventName);
|
|
175
|
+
console.log('事件处理结果', res[0].content);
|
|
176
|
+
}
|
|
177
|
+
else if (content.target === 'Room') {
|
|
178
|
+
console.log('触发了群事件');
|
|
179
|
+
await sendTaskMessage(that, content);
|
|
180
|
+
}
|
|
181
|
+
else if (content.target === 'Contact') {
|
|
182
|
+
console.log('触发了好友事件');
|
|
183
|
+
await sendTaskMessage(that, content);
|
|
184
|
+
}
|
|
185
|
+
else if (content.target === 'Rss') {
|
|
186
|
+
console.log('触发了rss立即更新事件');
|
|
187
|
+
await sendRssTaskMessage(that, content);
|
|
188
|
+
}
|
|
189
|
+
else if (content.target === 'Tasks') {
|
|
190
|
+
console.log('触发了批量任务立即发送');
|
|
191
|
+
await sendMultiTaskMessage(that, content.task);
|
|
192
|
+
}
|
|
193
|
+
else if (content.target === 'refreshCode') {
|
|
194
|
+
console.log('强制更新二维码');
|
|
195
|
+
await that.refreshQrCode();
|
|
196
|
+
}
|
|
197
|
+
else if (content.target === 'getNewQrCode') {
|
|
198
|
+
console.log('获取最新二维码');
|
|
199
|
+
resetScanTime();
|
|
200
|
+
}
|
|
201
|
+
else if (content.target === 'logout') {
|
|
202
|
+
console.log('退出登录');
|
|
203
|
+
that.logout();
|
|
204
|
+
}
|
|
205
|
+
else if (content.target === 'verifyCode') {
|
|
206
|
+
console.log('触发了输入验证码事件');
|
|
207
|
+
if (globalConfig.getVerifyId() === globalConfig.getQrKey()) {
|
|
208
|
+
await getVerifyCode();
|
|
209
|
+
if (globalConfig.getVerifyCode()) {
|
|
210
|
+
console.log(`获取到输入的验证码:${globalConfig.getVerifyCode()},正在填入`);
|
|
211
|
+
const verifyCode = globalConfig.getVerifyCode(); // 通过一些途径输入验证码
|
|
212
|
+
try {
|
|
213
|
+
await that.enterVerifyCode(globalConfig.getVerifyId(), verifyCode); // 如果没抛错,则说明输入成功,会推送登录事件
|
|
214
|
+
}
|
|
215
|
+
catch (e) {
|
|
216
|
+
console.log('验证码校验错误:', e.message);
|
|
217
|
+
// 如果抛错,请根据 message 处理,目前发现可以输错3次,超过3次错误需要重新扫码。
|
|
218
|
+
// 错误关键词: 验证码错误输入错误,请重新输入
|
|
219
|
+
// 错误关键词:验证码错误次数超过阈值,请重新扫码'
|
|
220
|
+
// 目前不会推送 EXPIRED 事件,需要根据错误内容判断
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
else if (topic === `aibotk/${userId}/gptconfig`) {
|
|
227
|
+
await getGptConfig();
|
|
228
|
+
console.log('更新最新自定义对话配置');
|
|
229
|
+
if (content.event === 'update' || content.event === 'delete') {
|
|
230
|
+
console.log('更新自定义对话配置,重置对话');
|
|
231
|
+
reset(content.updateId);
|
|
232
|
+
difyReset(content.updateId);
|
|
233
|
+
cozeReset(content.updateId);
|
|
234
|
+
qanyReset(content.updateId);
|
|
235
|
+
cozeV3Reset(content.updateId);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
else if (topic === `aibotk/${userId}/rssconfig`) {
|
|
239
|
+
console.log('更新rss配置');
|
|
240
|
+
await getRssConfig();
|
|
241
|
+
void initRssTask(that);
|
|
242
|
+
}
|
|
243
|
+
else if (topic === `aibotk/${userId}/tasks`) {
|
|
244
|
+
console.log('更新批量定时任务');
|
|
245
|
+
await getTasks();
|
|
246
|
+
void initMultiTask(that);
|
|
247
|
+
}
|
|
248
|
+
else if (topic === `aibotk/${userId}/history`) {
|
|
249
|
+
console.log('历史记录操作');
|
|
250
|
+
if (content.event === 'clear') {
|
|
251
|
+
clearHistory();
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
else {
|
|
258
|
+
return false;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
catch (e) {
|
|
262
|
+
console.log('mqtt 创建链接失败', e);
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
export function closeMqtt() {
|
|
266
|
+
if (mqttclient && mqttclient.connected) {
|
|
267
|
+
mqttclient.end();
|
|
268
|
+
mqttclient = null;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
export { initMqtt };
|
|
272
|
+
export default {
|
|
273
|
+
initMqtt,
|
|
274
|
+
};
|
|
275
|
+
//# sourceMappingURL=mqtt.js.map
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import FormData from 'form-data';
|
|
3
|
+
import { AIBOTK_OUTAPI } from './config.js';
|
|
4
|
+
import { getAibotConfig } from '../db/aiDb.js';
|
|
5
|
+
/**
|
|
6
|
+
* 语音转换文字
|
|
7
|
+
* @param file
|
|
8
|
+
* @param aiConfig
|
|
9
|
+
* @returns {Promise<*|string>}
|
|
10
|
+
*/
|
|
11
|
+
export async function getVoiceText(file, aiConfig) {
|
|
12
|
+
try {
|
|
13
|
+
const env = await getAibotConfig();
|
|
14
|
+
const { apiKey } = env;
|
|
15
|
+
const base64 = await file.toBase64();
|
|
16
|
+
const readable = Buffer.from(base64, 'base64');
|
|
17
|
+
const formData = new FormData();
|
|
18
|
+
formData.append('file', readable, { contentType: file.mediaType, filename: file.name });
|
|
19
|
+
formData.append('aiConfig', JSON.stringify(aiConfig));
|
|
20
|
+
let config = {
|
|
21
|
+
method: 'post',
|
|
22
|
+
maxBodyLength: Infinity,
|
|
23
|
+
timeout: 180000,
|
|
24
|
+
url: AIBOTK_OUTAPI + '/voice/text',
|
|
25
|
+
headers: {
|
|
26
|
+
...formData.getHeaders(),
|
|
27
|
+
Authorization: `Bearer ${apiKey}`,
|
|
28
|
+
},
|
|
29
|
+
data: formData
|
|
30
|
+
};
|
|
31
|
+
const result = await axios.request(config);
|
|
32
|
+
if (result.data.code === 200) {
|
|
33
|
+
return result.data.data;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
console.log('语音转换出错', result.data.message);
|
|
37
|
+
return '';
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
catch (e) {
|
|
41
|
+
console.log(`语音转换出错: ${e}`);
|
|
42
|
+
return '';
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* 文字转语音
|
|
47
|
+
* @param text
|
|
48
|
+
* @param aiConfig
|
|
49
|
+
* @returns {Promise<*|string>}
|
|
50
|
+
*/
|
|
51
|
+
export async function getText2Speech(text, aiConfig) {
|
|
52
|
+
try {
|
|
53
|
+
const env = await getAibotConfig();
|
|
54
|
+
const { apiKey } = env;
|
|
55
|
+
let config = {
|
|
56
|
+
method: 'post',
|
|
57
|
+
maxBodyLength: Infinity,
|
|
58
|
+
timeout: 180000,
|
|
59
|
+
url: AIBOTK_OUTAPI + '/text/speech',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
Authorization: `Bearer ${apiKey}`,
|
|
63
|
+
},
|
|
64
|
+
data: {
|
|
65
|
+
text,
|
|
66
|
+
aiConfig
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
const result = await axios.request(config);
|
|
70
|
+
if (result.data.code === 200) {
|
|
71
|
+
return result.data.data;
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
console.log('语音生成出错', result.data.message);
|
|
75
|
+
return '';
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
console.log(`语音生成出错: ${e}`);
|
|
80
|
+
return '';
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* 识别图像
|
|
85
|
+
* @param images
|
|
86
|
+
* @param question
|
|
87
|
+
* @param config
|
|
88
|
+
* @returns {Promise<*|[{type: number, content: string}]>}
|
|
89
|
+
*/
|
|
90
|
+
export async function getImageVision(images, question, config) {
|
|
91
|
+
try {
|
|
92
|
+
const env = await getAibotConfig();
|
|
93
|
+
const { apiKey } = env;
|
|
94
|
+
const reqConfig = {
|
|
95
|
+
method: 'post',
|
|
96
|
+
maxBodyLength: Infinity,
|
|
97
|
+
timeout: 180000,
|
|
98
|
+
url: AIBOTK_OUTAPI + '/image/vision',
|
|
99
|
+
headers: {
|
|
100
|
+
Authorization: `Bearer ${apiKey}`,
|
|
101
|
+
},
|
|
102
|
+
data: {
|
|
103
|
+
images,
|
|
104
|
+
question,
|
|
105
|
+
config
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
const result = await axios.request(reqConfig);
|
|
109
|
+
if (result.data.code === 200) {
|
|
110
|
+
return result.data.data;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
console.log('识别图像出错', result.data.message);
|
|
114
|
+
return [{ type: 1, content: '' }];
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
catch (e) {
|
|
118
|
+
console.log('识别图像出错', e);
|
|
119
|
+
return [{ type: 1, content: '' }];
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=multimodal.js.map
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { allConfig } from '../db/configDb.js';
|
|
2
|
+
import OfficialOpenAi from '../botInstance/officialOpenAi.js';
|
|
3
|
+
let chatGPT = null;
|
|
4
|
+
/**
|
|
5
|
+
* 重置实例
|
|
6
|
+
*/
|
|
7
|
+
export function reset() {
|
|
8
|
+
if (chatGPT) {
|
|
9
|
+
chatGPT.reset();
|
|
10
|
+
chatGPT = null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function getGptOfficialReply({ content, uid, file }) {
|
|
14
|
+
const config = await allConfig();
|
|
15
|
+
if (!config.gpttoken) {
|
|
16
|
+
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
17
|
+
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
18
|
+
}
|
|
19
|
+
const chatConfig = {
|
|
20
|
+
token: config.gpttoken, // token
|
|
21
|
+
debug: config.openaiDebug, // 开启调试
|
|
22
|
+
proxyPass: config.proxyPassUrl, // 反向代理地址
|
|
23
|
+
proxyUrl: config.proxyUrl, // 代理地址
|
|
24
|
+
showQuestion: config.showQuestion, // 显示原文
|
|
25
|
+
timeoutMs: config.openaiTimeout, // 超时时间 s
|
|
26
|
+
model: config.openaiModel, // 模型
|
|
27
|
+
temperature: config?.temperature, // 温度
|
|
28
|
+
top_p: config?.top_p, // 随机值
|
|
29
|
+
presence_penalty: config?.presence_penalty, // 离散值
|
|
30
|
+
systemMessage: config.openaiSystemMessage, // 预设promotion
|
|
31
|
+
filter: config.chatFilter,
|
|
32
|
+
ignoreFiles: config?.ignoreFiles || false,
|
|
33
|
+
filterLinkContent: config?.filterLinkContent || false,
|
|
34
|
+
filterConfig: {
|
|
35
|
+
type: 1,
|
|
36
|
+
appId: config.filterAppid,
|
|
37
|
+
apiKey: config.filterApiKey,
|
|
38
|
+
secretKey: config.filterSecretKey,
|
|
39
|
+
},
|
|
40
|
+
};
|
|
41
|
+
if (!chatGPT) {
|
|
42
|
+
chatGPT = new OfficialOpenAi(chatConfig);
|
|
43
|
+
}
|
|
44
|
+
return await chatGPT.getReply({ content, uid, adminId: '', systemMessage: '', file });
|
|
45
|
+
}
|
|
46
|
+
export async function getSimpleGptReply({ content, uid, config }) {
|
|
47
|
+
if (!config.token) {
|
|
48
|
+
console.log('请到智能微秘书平台配置聊天总结的API Token参数方可使用');
|
|
49
|
+
return [{ type: 1, content: '请到平台配置聊天总结的API Token参数方可使用' }];
|
|
50
|
+
}
|
|
51
|
+
const chatConfig = {
|
|
52
|
+
token: config.token, // token
|
|
53
|
+
debug: config.debug, // 开启调试
|
|
54
|
+
proxyPass: config.baseUrl, // 反向代理地址
|
|
55
|
+
proxyUrl: '', // 代理地址
|
|
56
|
+
showQuestion: false, // 显示原文
|
|
57
|
+
timeoutMs: config.timeout, // 超时时间 s
|
|
58
|
+
model: config.model, // 模型
|
|
59
|
+
systemMessage: config.prompt, // 预设promotion
|
|
60
|
+
};
|
|
61
|
+
return await new OfficialOpenAi(chatConfig).getReply({ content, uid, adminId: '', systemMessage: '' });
|
|
62
|
+
}
|
|
63
|
+
//# sourceMappingURL=openAi.js.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
import { allConfig } from '../db/configDb.js';
|
|
3
|
+
import { AIBOTK_OUTAPI } from './config.js';
|
|
4
|
+
const service = axios.create({
|
|
5
|
+
// 定义统一的请求头部
|
|
6
|
+
headers: {
|
|
7
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
8
|
+
},
|
|
9
|
+
// 配置请求超时时间
|
|
10
|
+
timeout: 300 * 1000,
|
|
11
|
+
// 如果用的JSONP,可以配置此参数带上cookie凭证,如果是代理和CORS不用设置
|
|
12
|
+
withCredentials: false,
|
|
13
|
+
});
|
|
14
|
+
// 请求拦截
|
|
15
|
+
service.interceptors.request.use((config) => {
|
|
16
|
+
return config;
|
|
17
|
+
});
|
|
18
|
+
// 返回拦截
|
|
19
|
+
service.interceptors.response.use((response) => {
|
|
20
|
+
if (response.status === 200) {
|
|
21
|
+
// 获取接口返回结果
|
|
22
|
+
const res = response.data;
|
|
23
|
+
// code为0,直接把结果返回回去,这样前端代码就不用在获取一次data.
|
|
24
|
+
if (res.code === 200) {
|
|
25
|
+
if (Array.isArray(res.data)) {
|
|
26
|
+
return Promise.resolve(res.data);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
const result = [{ type: 1, content: '' }];
|
|
30
|
+
return Promise.resolve(result);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const result = [{ type: 1, content: res.msg || '' }];
|
|
35
|
+
return Promise.resolve(result);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const res = [{ type: 1, content: '外部 api 网络请求错误:' + response.status }];
|
|
39
|
+
return Promise.resolve(res);
|
|
40
|
+
}, (err) => {
|
|
41
|
+
console.log('err', err);
|
|
42
|
+
const res = [{ type: 1, content: '网络错误,请稍后重试' }];
|
|
43
|
+
return Promise.resolve(res);
|
|
44
|
+
});
|
|
45
|
+
/**
|
|
46
|
+
* 适配外部 api接口
|
|
47
|
+
* @param params
|
|
48
|
+
* @returns {Promise<AxiosResponse<any>>}
|
|
49
|
+
*/
|
|
50
|
+
export async function outApi(params) {
|
|
51
|
+
const config = await allConfig();
|
|
52
|
+
if (!params)
|
|
53
|
+
return;
|
|
54
|
+
const data = {
|
|
55
|
+
key: config.txApiKey,
|
|
56
|
+
...params,
|
|
57
|
+
};
|
|
58
|
+
const url = AIBOTK_OUTAPI + '/skill';
|
|
59
|
+
const res = await service.post(url, data);
|
|
60
|
+
return res;
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=outapi.js.map
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { allConfig } from "../db/configDb.js";
|
|
2
|
+
import QAnyAi from "../botInstance/qany.js";
|
|
3
|
+
let chatQAny = null;
|
|
4
|
+
/**
|
|
5
|
+
* 重置实例
|
|
6
|
+
*/
|
|
7
|
+
export function reset() {
|
|
8
|
+
if (chatQAny) {
|
|
9
|
+
chatQAny.reset();
|
|
10
|
+
chatQAny = null;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
export async function getQAnyReply(content, uid) {
|
|
14
|
+
const config = await allConfig();
|
|
15
|
+
if (!config.qany_token || !config.qany_botId) {
|
|
16
|
+
console.log('请到智能微秘书平台配置Coze Token 和 botId参数方可使用');
|
|
17
|
+
return [{ type: 1, content: '请到平台配置Coze Token 和 botId 参数方可使用' }];
|
|
18
|
+
}
|
|
19
|
+
const chatConfig = {
|
|
20
|
+
token: config.qany_token, // token
|
|
21
|
+
debug: config.openaiDebug, // 开启调试
|
|
22
|
+
botId: config.qany_botId,
|
|
23
|
+
proxyPass: config.qany_baseUrl, // 反向代理地址
|
|
24
|
+
showQuestion: config.showQuestion, // 显示原文
|
|
25
|
+
timeoutMs: config.openaiTimeout, // 超时时间 s
|
|
26
|
+
filter: config.chatFilter,
|
|
27
|
+
ignoreFiles: config?.ignoreFiles || false,
|
|
28
|
+
filterLinkContent: config?.filterLinkContent || false,
|
|
29
|
+
filterConfig: {
|
|
30
|
+
type: 1,
|
|
31
|
+
appId: config.filterAppid,
|
|
32
|
+
apiKey: config.filterApiKey,
|
|
33
|
+
secretKey: config.filterSecretKey
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
if (!chatQAny) {
|
|
37
|
+
chatQAny = new QAnyAi(chatConfig);
|
|
38
|
+
}
|
|
39
|
+
return await chatQAny.getReply(content, uid, '', '');
|
|
40
|
+
}
|
|
41
|
+
export async function getQAnySimpleReply({ content, uid, config }) {
|
|
42
|
+
if (!config.token || !config.botId) {
|
|
43
|
+
console.log('请到智能微秘书平台配置聊天总结的QAnything Token 和 botId参数方可使用');
|
|
44
|
+
return [{ type: 1, content: '请到平台配置聊天总结的QAnything Token 和 botId 参数方可使用' }];
|
|
45
|
+
}
|
|
46
|
+
const chatConfig = {
|
|
47
|
+
token: config.token, // token
|
|
48
|
+
debug: config.debug, // 开启调试
|
|
49
|
+
botId: config.botId,
|
|
50
|
+
proxyPass: config.baseUrl, // 反向代理地址
|
|
51
|
+
showQuestion: false, // 显示原文
|
|
52
|
+
showSuggestions: false, // 显示原文
|
|
53
|
+
timeoutMs: config.timeout, // 超时时间 s
|
|
54
|
+
};
|
|
55
|
+
return await new QAnyAi(chatConfig).getReply(content, uid, '', '');
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=qAnyAi.js.map
|