wechaty-web-panel 1.6.79 → 1.6.80
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/cjs/src/bot/fastgpt/index.js +10 -7
- package/dist/cjs/src/botInstance/cozev3.js +0 -1
- package/dist/cjs/src/botInstance/fastgpt.d.ts +32 -0
- package/dist/cjs/src/botInstance/fastgpt.js +128 -0
- package/dist/cjs/src/botInstance/officialOpenAi.js +0 -2
- package/dist/cjs/src/handlers/on-callback-message.js +3 -2
- package/dist/cjs/src/package-json.js +1 -1
- package/dist/cjs/src/proxy/bot/dispatch.js +2 -1
- package/dist/cjs/src/proxy/bot/fastgpt.d.ts +14 -0
- package/dist/cjs/src/proxy/bot/fastgpt.js +36 -0
- package/dist/cjs/src/proxy/fastgpt.d.ts +12 -0
- package/dist/cjs/src/proxy/fastgpt.js +62 -0
- package/dist/cjs/src/service/event-dispatch-service.js +4 -2
- package/dist/esm/src/bot/fastgpt/index.js +6 -6
- package/dist/esm/src/botInstance/cozev3.js +0 -1
- package/dist/esm/src/botInstance/fastgpt.d.ts +32 -0
- package/dist/esm/src/botInstance/fastgpt.js +123 -0
- package/dist/esm/src/botInstance/officialOpenAi.js +0 -2
- package/dist/esm/src/handlers/on-callback-message.js +3 -2
- package/dist/esm/src/package-json.js +1 -1
- package/dist/esm/src/proxy/bot/dispatch.js +2 -1
- package/dist/esm/src/proxy/bot/fastgpt.d.ts +14 -0
- package/dist/esm/src/proxy/bot/fastgpt.js +27 -0
- package/dist/esm/src/proxy/fastgpt.d.ts +12 -0
- package/dist/esm/src/proxy/fastgpt.js +53 -0
- package/dist/esm/src/service/event-dispatch-service.js +4 -2
- package/package.json +1 -1
- package/dist/cjs/src/botInstance/sdk/chatGPT.d.ts +0 -49
- package/dist/cjs/src/botInstance/sdk/chatGPT.js +0 -421
- package/dist/cjs/src/botInstance/sdk/cozev3.d.ts +0 -60
- package/dist/cjs/src/botInstance/sdk/cozev3.js +0 -329
- package/dist/cjs/src/proxy/openAiHook.d.ts +0 -3
- package/dist/cjs/src/proxy/openAiHook.js +0 -45
- package/dist/esm/src/botInstance/sdk/chatGPT.d.ts +0 -49
- package/dist/esm/src/botInstance/sdk/chatGPT.js +0 -413
- package/dist/esm/src/botInstance/sdk/cozev3.d.ts +0 -60
- package/dist/esm/src/botInstance/sdk/cozev3.js +0 -323
- package/dist/esm/src/proxy/openAiHook.d.ts +0 -3
- package/dist/esm/src/proxy/openAiHook.js +0 -37
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.FastGPTAPI = void 0;
|
|
4
|
-
const
|
|
5
|
-
const axiosRetry = require('axios-retry').default;
|
|
6
|
-
axiosRetry(axios, { retries: 3, retryDelay: () => 1000 });
|
|
7
|
+
const axios_1 = __importDefault(require("axios"));
|
|
7
8
|
class FastGPTAPI {
|
|
8
9
|
constructor(opts) {
|
|
9
|
-
const { apiKey, apiBaseUrl = 'https://
|
|
10
|
+
const { apiKey, apiBaseUrl = 'https://cloud.fastgpt.cn/api/v1', debug, } = opts;
|
|
10
11
|
this._apiKey = apiKey;
|
|
11
12
|
this._apiBaseUrl = apiBaseUrl;
|
|
12
13
|
this._debug = debug;
|
|
@@ -31,7 +32,7 @@ class FastGPTAPI {
|
|
|
31
32
|
if (this._debug) {
|
|
32
33
|
console.log('request body', body);
|
|
33
34
|
}
|
|
34
|
-
const response = await
|
|
35
|
+
const response = await (0, axios_1.default)({
|
|
35
36
|
method: 'POST',
|
|
36
37
|
url: `${this._apiBaseUrl}/chat/completions`,
|
|
37
38
|
data: body || null,
|
|
@@ -43,9 +44,11 @@ class FastGPTAPI {
|
|
|
43
44
|
responseType: 'json',
|
|
44
45
|
});
|
|
45
46
|
if (response.status === 200) {
|
|
46
|
-
|
|
47
|
+
if (this._debug) {
|
|
48
|
+
console.log('response.data', JSON.stringify(response.data));
|
|
49
|
+
}
|
|
47
50
|
if (response.data.code) {
|
|
48
|
-
console.log('
|
|
51
|
+
console.log('FastGPT请求出错', JSON.stringify(response.data));
|
|
49
52
|
return {
|
|
50
53
|
text: '',
|
|
51
54
|
};
|
|
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
// import { CozeV3Api } from "./sdk/cozev3.js";
|
|
7
6
|
const index_js_1 = require("../bot/coze/sdk/index.js");
|
|
8
7
|
const aichatDb_js_1 = require("../db/aichatDb.js");
|
|
9
8
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default FastGPTAi;
|
|
2
|
+
declare class FastGPTAi {
|
|
3
|
+
constructor(config?: {
|
|
4
|
+
token: string;
|
|
5
|
+
debug: number;
|
|
6
|
+
proxyPass: string;
|
|
7
|
+
showQuestion: boolean;
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
});
|
|
10
|
+
fastGPT: FastGPTAPI | null;
|
|
11
|
+
config: {
|
|
12
|
+
token: string;
|
|
13
|
+
debug: number;
|
|
14
|
+
proxyPass: string;
|
|
15
|
+
showQuestion: boolean;
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
};
|
|
18
|
+
contentCensor: ContentCensor | null;
|
|
19
|
+
chatOption: {};
|
|
20
|
+
eol: string;
|
|
21
|
+
iswindows: boolean;
|
|
22
|
+
init(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* 重置apikey
|
|
25
|
+
* @return {Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
reset(): Promise<void>;
|
|
28
|
+
getReply(content: any, uid: any, adminId: string | undefined, variables: any): Promise<any>;
|
|
29
|
+
}
|
|
30
|
+
import { FastGPTAPI } from "../bot/fastgpt/index.js";
|
|
31
|
+
import { ContentCensor } from "../lib/contentCensor.js";
|
|
32
|
+
//# sourceMappingURL=fastgpt.d.ts.map
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const index_js_1 = require("../bot/fastgpt/index.js");
|
|
7
|
+
const aichatDb_js_1 = require("../db/aichatDb.js");
|
|
8
|
+
const contentCensor_js_1 = require("../lib/contentCensor.js");
|
|
9
|
+
const puppet_type_js_1 = require("../const/puppet-type.js");
|
|
10
|
+
const uuid_1 = require("uuid");
|
|
11
|
+
const dayjs_1 = __importDefault(require("dayjs"));
|
|
12
|
+
const index_js_2 = require("../lib/index.js");
|
|
13
|
+
const multimodal_js_1 = require("../proxy/multimodal.js");
|
|
14
|
+
class FastGPTAi {
|
|
15
|
+
constructor(config = {
|
|
16
|
+
token: '',
|
|
17
|
+
debug: 0,
|
|
18
|
+
proxyPass: '',
|
|
19
|
+
showQuestion: true,
|
|
20
|
+
timeoutMs: 60, // 超时时间 s
|
|
21
|
+
}) {
|
|
22
|
+
this.fastGPT = null;
|
|
23
|
+
this.config = config;
|
|
24
|
+
this.contentCensor = null;
|
|
25
|
+
this.chatOption = {};
|
|
26
|
+
this.eol = '\n';
|
|
27
|
+
this.iswindows = false;
|
|
28
|
+
}
|
|
29
|
+
async init() {
|
|
30
|
+
this.eol = await (0, puppet_type_js_1.getPuppetEol)();
|
|
31
|
+
this.iswindows = await (0, puppet_type_js_1.isWindowsPlatform)();
|
|
32
|
+
if (this.config.filter) {
|
|
33
|
+
this.contentCensor = new contentCensor_js_1.ContentCensor(this.config.filterConfig);
|
|
34
|
+
}
|
|
35
|
+
console.log(`请求地址:${this.config.proxyPass}`);
|
|
36
|
+
const baseOptions = {
|
|
37
|
+
apiKey: this.config.token,
|
|
38
|
+
debug: this.config.debug,
|
|
39
|
+
apiBaseUrl: this.config.proxyPass
|
|
40
|
+
};
|
|
41
|
+
this.fastGPT = new index_js_1.FastGPTAPI(baseOptions);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* 重置apikey
|
|
45
|
+
* @return {Promise<void>}
|
|
46
|
+
*/
|
|
47
|
+
reset() {
|
|
48
|
+
this.fastGPT = null;
|
|
49
|
+
}
|
|
50
|
+
async getReply(content, uid, adminId = '', variables) {
|
|
51
|
+
try {
|
|
52
|
+
if (!this.fastGPT) {
|
|
53
|
+
console.log('看到此消息说明已启用FastGPT');
|
|
54
|
+
await this.init();
|
|
55
|
+
}
|
|
56
|
+
if (this.config.filter) {
|
|
57
|
+
const censor = await this.contentCensor.checkText(content);
|
|
58
|
+
if (!censor) {
|
|
59
|
+
console.log(`问题:${content},包含违规词,已拦截`);
|
|
60
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
const resetWord = ['reset', '重置', '重置对话', '忽略上下文', '重置上下文', '重新开始', '清除对话', '清除上下文'];
|
|
64
|
+
if (resetWord.includes(content)) {
|
|
65
|
+
console.log('重新更新上下文对话');
|
|
66
|
+
this.chatOption[uid] = null;
|
|
67
|
+
return [{ type: 1, content: '上下文已重置' }];
|
|
68
|
+
}
|
|
69
|
+
if (!this.chatOption[uid]) {
|
|
70
|
+
this.chatOption[uid] = {
|
|
71
|
+
chatId: (0, uuid_1.v4)()
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
const sendParams = { ...this.chatOption[uid], variables, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
|
|
75
|
+
console.log('FastGPT sendParams---', sendParams);
|
|
76
|
+
const { chatId, text, id } = await this.fastGPT.sendMessage(content, sendParams);
|
|
77
|
+
if (this.config.filter) {
|
|
78
|
+
const censor = await this.contentCensor.checkText(text);
|
|
79
|
+
if (!censor) {
|
|
80
|
+
console.log(`回复: ${text},包含违规词,已拦截`);
|
|
81
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (this.config.record) {
|
|
85
|
+
void (0, aichatDb_js_1.addAichatRecord)({ contactId: uid, adminId, input: content, output: text, time: (0, dayjs_1.default)().format('YYYY-MM-DD HH:mm:ss') });
|
|
86
|
+
}
|
|
87
|
+
this.chatOption[uid] = { chatId };
|
|
88
|
+
let replys = [];
|
|
89
|
+
if (this.config?.openTTS) {
|
|
90
|
+
replys = await (0, multimodal_js_1.getText2Speech)(text, this.config.ttsConfig);
|
|
91
|
+
if (replys.length) {
|
|
92
|
+
return replys;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
let message;
|
|
96
|
+
if (this.config.showQuestion) {
|
|
97
|
+
message = `${content}${this.eol}-----------${this.eol}` + (this.iswindows ? text.replaceAll('\n', this.eol) : text);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
message = this.iswindows ? text.replaceAll('\n', this.eol) : text;
|
|
101
|
+
}
|
|
102
|
+
const imgs = (0, index_js_2.extractImageLinks)(message);
|
|
103
|
+
console.log('imgs', imgs);
|
|
104
|
+
while (message.length > 1500) {
|
|
105
|
+
replys.push(message.slice(0, 1500));
|
|
106
|
+
message = message.slice(1500);
|
|
107
|
+
}
|
|
108
|
+
replys.push(message);
|
|
109
|
+
replys = replys.map(item => {
|
|
110
|
+
return {
|
|
111
|
+
type: 1,
|
|
112
|
+
content: item.trim()
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
if (imgs.length) {
|
|
116
|
+
console.log('提取到内容中的图片', imgs);
|
|
117
|
+
replys = replys.concat(imgs);
|
|
118
|
+
}
|
|
119
|
+
return replys;
|
|
120
|
+
}
|
|
121
|
+
catch (e) {
|
|
122
|
+
console.log('FastGPT报错:' + e);
|
|
123
|
+
return [];
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
exports.default = FastGPTAi;
|
|
128
|
+
//# sourceMappingURL=fastgpt.js.map
|
|
@@ -3,8 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
const https_proxy_agent_1 = __importDefault(require("https-proxy-agent"));
|
|
7
|
-
const node_fetch_1 = __importDefault(require("node-fetch"));
|
|
8
6
|
const index_js_1 = require("../bot/chatgpt/index.js");
|
|
9
7
|
const aichatDb_js_1 = require("../db/aichatDb.js");
|
|
10
8
|
const aibotk_js_1 = require("../proxy/aibotk.js");
|
|
@@ -27,7 +27,7 @@ async function onRecordMessage(msg) {
|
|
|
27
27
|
const timestamp = msg.timestamp || (0, dayjs_1.default)().unix();
|
|
28
28
|
const robotInfo = this.currentUser;
|
|
29
29
|
const isOfficial = contact.type() === this.Contact.Type.Official;
|
|
30
|
-
if (
|
|
30
|
+
if (isOfficial)
|
|
31
31
|
return;
|
|
32
32
|
console.log('msg', msg);
|
|
33
33
|
const baseMsg = {
|
|
@@ -37,6 +37,7 @@ async function onRecordMessage(msg) {
|
|
|
37
37
|
chatName: contactName,
|
|
38
38
|
chatId: contact.id,
|
|
39
39
|
chatAlias: contactAlias,
|
|
40
|
+
isMyself: !!msgSelf,
|
|
40
41
|
time: timestamp.length > 10 ? parseInt(timestamp / 1000) : timestamp
|
|
41
42
|
};
|
|
42
43
|
switch (type) {
|
|
@@ -130,7 +131,7 @@ async function onRecordMessage(msg) {
|
|
|
130
131
|
}
|
|
131
132
|
}
|
|
132
133
|
function sendMessage(msgInfo, recordConfig, robotInfo) {
|
|
133
|
-
const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content'];
|
|
134
|
+
const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content', 'isMyself'];
|
|
134
135
|
const baseData = {
|
|
135
136
|
...msgInfo
|
|
136
137
|
};
|
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.dispatchBot = void 0;
|
|
7
7
|
const chatgpt_js_1 = require("./chatgpt.js");
|
|
8
|
+
const fastgpt_js_1 = require("./fastgpt.js");
|
|
8
9
|
const dify_js_1 = require("./dify.js");
|
|
9
10
|
const coze_js_1 = require("./coze.js");
|
|
10
11
|
const cozev3_js_1 = require("./cozev3.js");
|
|
@@ -38,7 +39,7 @@ async function dispatchBot({ botType, userAlias, userWeixin, content, id, uid, u
|
|
|
38
39
|
case 9:
|
|
39
40
|
// fastGPT api
|
|
40
41
|
console.log('进入FastGPT聊天');
|
|
41
|
-
res = await (0,
|
|
42
|
+
res = await (0, fastgpt_js_1.getFastGPTReply)({ content, variables: { uid, ualias: userAlias, uweixin: userWeixin, uname, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name } }, id, adminId, config);
|
|
42
43
|
replys = res;
|
|
43
44
|
break;
|
|
44
45
|
case 11:
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function reset(adminId: any): void;
|
|
2
|
+
export function resetAll(): void;
|
|
3
|
+
export function getFastGPTReply({ content, variables }: {
|
|
4
|
+
content: any;
|
|
5
|
+
variables: any;
|
|
6
|
+
}, uid: any, adminId: any, config?: {
|
|
7
|
+
token: string;
|
|
8
|
+
debug: boolean;
|
|
9
|
+
proxyPass: string;
|
|
10
|
+
proxyUrl: string;
|
|
11
|
+
showQuestion: boolean;
|
|
12
|
+
timeoutMs: number;
|
|
13
|
+
}): Promise<any>;
|
|
14
|
+
//# sourceMappingURL=fastgpt.d.ts.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getFastGPTReply = exports.resetAll = exports.reset = void 0;
|
|
7
|
+
const fastgpt_js_1 = __importDefault(require("../../botInstance/fastgpt.js"));
|
|
8
|
+
let fastGPT = {};
|
|
9
|
+
function reset(adminId) {
|
|
10
|
+
if (!fastGPT[adminId])
|
|
11
|
+
return;
|
|
12
|
+
fastGPT[adminId].reset();
|
|
13
|
+
fastGPT[adminId] = null;
|
|
14
|
+
}
|
|
15
|
+
exports.reset = reset;
|
|
16
|
+
function resetAll() {
|
|
17
|
+
Object.keys(fastGPT).forEach(key => {
|
|
18
|
+
if (fastGPT[key]) {
|
|
19
|
+
fastGPT[key].reset();
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
fastGPT = {};
|
|
23
|
+
}
|
|
24
|
+
exports.resetAll = resetAll;
|
|
25
|
+
async function getFastGPTReply({ content, variables }, uid, adminId, config = { token: "", debug: false, proxyPass: "", proxyUrl: "", showQuestion: false, timeoutMs: 80 }) {
|
|
26
|
+
if (!config.token) {
|
|
27
|
+
console.log('请到智能微秘书平台配置FastGPT apikey参数方可使用');
|
|
28
|
+
return [{ type: 1, content: '请到平台配置FastGPT apikey参数方可使用' }];
|
|
29
|
+
}
|
|
30
|
+
if (!fastGPT[adminId]) {
|
|
31
|
+
fastGPT[adminId] = new fastgpt_js_1.default(config);
|
|
32
|
+
}
|
|
33
|
+
return await fastGPT[adminId].getReply(content, uid, adminId, variables);
|
|
34
|
+
}
|
|
35
|
+
exports.getFastGPTReply = getFastGPTReply;
|
|
36
|
+
//# sourceMappingURL=fastgpt.js.map
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 重置实例
|
|
3
|
+
*/
|
|
4
|
+
export function reset(): void;
|
|
5
|
+
export function getFastGPTReply(content: any, uid: any, variables: any): Promise<any>;
|
|
6
|
+
export function getSimpleFastGptReply({ content, uid, config, variables }: {
|
|
7
|
+
content: any;
|
|
8
|
+
uid: any;
|
|
9
|
+
config: any;
|
|
10
|
+
variables: any;
|
|
11
|
+
}): Promise<any>;
|
|
12
|
+
//# sourceMappingURL=fastgpt.d.ts.map
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getSimpleFastGptReply = exports.getFastGPTReply = exports.reset = void 0;
|
|
7
|
+
const configDb_js_1 = require("../db/configDb.js");
|
|
8
|
+
const fastgpt_js_1 = __importDefault(require("../botInstance/fastgpt.js"));
|
|
9
|
+
let fastGPT = null;
|
|
10
|
+
/**
|
|
11
|
+
* 重置实例
|
|
12
|
+
*/
|
|
13
|
+
function reset() {
|
|
14
|
+
if (fastGPT) {
|
|
15
|
+
fastGPT.reset();
|
|
16
|
+
fastGPT = null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
exports.reset = reset;
|
|
20
|
+
async function getFastGPTReply(content, uid, variables) {
|
|
21
|
+
const config = await (0, configDb_js_1.allConfig)();
|
|
22
|
+
if (!config.gpttoken) {
|
|
23
|
+
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
24
|
+
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
25
|
+
}
|
|
26
|
+
const chatConfig = {
|
|
27
|
+
token: config.gpttoken,
|
|
28
|
+
debug: config.openaiDebug,
|
|
29
|
+
proxyPass: config.proxyPassUrl,
|
|
30
|
+
showQuestion: config.showQuestion,
|
|
31
|
+
timeoutMs: config.openaiTimeout,
|
|
32
|
+
filter: config.chatFilter,
|
|
33
|
+
filterConfig: {
|
|
34
|
+
type: 1,
|
|
35
|
+
appId: config.filterAppid,
|
|
36
|
+
apiKey: config.filterApiKey,
|
|
37
|
+
secretKey: config.filterSecretKey
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
if (!fastGPT) {
|
|
41
|
+
fastGPT = new fastgpt_js_1.default(chatConfig);
|
|
42
|
+
}
|
|
43
|
+
return await fastGPT.getReply(content, uid, '', variables);
|
|
44
|
+
}
|
|
45
|
+
exports.getFastGPTReply = getFastGPTReply;
|
|
46
|
+
async function getSimpleFastGptReply({ content, uid, config, variables }) {
|
|
47
|
+
if (!config.token) {
|
|
48
|
+
console.log('请到智能微秘书平台配置聊天总结的FastGPT API Token参数方可使用');
|
|
49
|
+
return [{ type: 1, content: '请到平台配置聊天总结的FastGPT API Token参数方可使用' }];
|
|
50
|
+
}
|
|
51
|
+
const chatConfig = {
|
|
52
|
+
token: config.token,
|
|
53
|
+
debug: config.debug,
|
|
54
|
+
proxyPass: config.baseUrl,
|
|
55
|
+
proxyUrl: '',
|
|
56
|
+
showQuestion: false,
|
|
57
|
+
timeoutMs: config.timeout, // 超时时间 s
|
|
58
|
+
};
|
|
59
|
+
return await new fastgpt_js_1.default(chatConfig).getReply(content, uid, '', variables);
|
|
60
|
+
}
|
|
61
|
+
exports.getSimpleFastGptReply = getSimpleFastGptReply;
|
|
62
|
+
//# sourceMappingURL=fastgpt.js.map
|
|
@@ -9,6 +9,7 @@ const index_js_3 = require("../common/index.js");
|
|
|
9
9
|
const tencent_open_js_1 = require("../proxy/tencent-open.js");
|
|
10
10
|
const roomDb_js_1 = require("../db/roomDb.js");
|
|
11
11
|
const openAi_js_1 = require("../proxy/openAi.js");
|
|
12
|
+
const fastgpt_js_1 = require("../proxy/fastgpt.js");
|
|
12
13
|
const difyAi_js_1 = require("../proxy/difyAi.js");
|
|
13
14
|
const cozeV3Ai_js_1 = require("../proxy/cozeV3Ai.js");
|
|
14
15
|
const cozeAi_js_1 = require("../proxy/cozeAi.js");
|
|
@@ -130,6 +131,7 @@ async function dispatchEventContent(that, eName, msg, name, id, avatar, room, ro
|
|
|
130
131
|
(0, cozeAi_js_1.reset)();
|
|
131
132
|
(0, qAnyAi_js_1.reset)();
|
|
132
133
|
(0, cozeV3Ai_js_1.reset)();
|
|
134
|
+
(0, fastgpt_js_1.reset)();
|
|
133
135
|
content = '更新配置成功,请稍等一分钟后生效';
|
|
134
136
|
break;
|
|
135
137
|
case 'autoRoomCreate':
|
|
@@ -205,7 +207,7 @@ async function dispatchAiBot({ bot, msg, name, id, uid, uname, roomId, userAlias
|
|
|
205
207
|
break;
|
|
206
208
|
case 9:
|
|
207
209
|
// fast gpt
|
|
208
|
-
res = await (0,
|
|
210
|
+
res = await (0, fastgpt_js_1.getFastGPTReply)(msg, id, { uid, uname, ualias: userAlias, uweixin: userWeixin, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name });
|
|
209
211
|
replys = res;
|
|
210
212
|
break;
|
|
211
213
|
case 11:
|
|
@@ -252,7 +254,7 @@ async function dispatchSummerBot({ content, id, uid, uname, roomId, roomName, us
|
|
|
252
254
|
break;
|
|
253
255
|
case 9:
|
|
254
256
|
// fast gpt
|
|
255
|
-
res = await (0,
|
|
257
|
+
res = await (0, fastgpt_js_1.getSimpleFastGptReply)({ content, uid: id, config, variables: { uid, ualias: userAlias, uweixin: userWeixin, uname, roomId, roomName, robotId: contactSelf.robotId, robotName: contactSelf.name } });
|
|
256
258
|
replys = res;
|
|
257
259
|
break;
|
|
258
260
|
case 11:
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
const axiosRetry = require('axios-retry').default;
|
|
3
|
-
axiosRetry(axios, { retries: 3, retryDelay: () => 1000 });
|
|
1
|
+
import axios from 'axios';
|
|
4
2
|
export class FastGPTAPI {
|
|
5
3
|
constructor(opts) {
|
|
6
|
-
const { apiKey, apiBaseUrl = 'https://
|
|
4
|
+
const { apiKey, apiBaseUrl = 'https://cloud.fastgpt.cn/api/v1', debug, } = opts;
|
|
7
5
|
this._apiKey = apiKey;
|
|
8
6
|
this._apiBaseUrl = apiBaseUrl;
|
|
9
7
|
this._debug = debug;
|
|
@@ -40,9 +38,11 @@ export class FastGPTAPI {
|
|
|
40
38
|
responseType: 'json',
|
|
41
39
|
});
|
|
42
40
|
if (response.status === 200) {
|
|
43
|
-
|
|
41
|
+
if (this._debug) {
|
|
42
|
+
console.log('response.data', JSON.stringify(response.data));
|
|
43
|
+
}
|
|
44
44
|
if (response.data.code) {
|
|
45
|
-
console.log('
|
|
45
|
+
console.log('FastGPT请求出错', JSON.stringify(response.data));
|
|
46
46
|
return {
|
|
47
47
|
text: '',
|
|
48
48
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export default FastGPTAi;
|
|
2
|
+
declare class FastGPTAi {
|
|
3
|
+
constructor(config?: {
|
|
4
|
+
token: string;
|
|
5
|
+
debug: number;
|
|
6
|
+
proxyPass: string;
|
|
7
|
+
showQuestion: boolean;
|
|
8
|
+
timeoutMs: number;
|
|
9
|
+
});
|
|
10
|
+
fastGPT: FastGPTAPI | null;
|
|
11
|
+
config: {
|
|
12
|
+
token: string;
|
|
13
|
+
debug: number;
|
|
14
|
+
proxyPass: string;
|
|
15
|
+
showQuestion: boolean;
|
|
16
|
+
timeoutMs: number;
|
|
17
|
+
};
|
|
18
|
+
contentCensor: ContentCensor | null;
|
|
19
|
+
chatOption: {};
|
|
20
|
+
eol: string;
|
|
21
|
+
iswindows: boolean;
|
|
22
|
+
init(): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* 重置apikey
|
|
25
|
+
* @return {Promise<void>}
|
|
26
|
+
*/
|
|
27
|
+
reset(): Promise<void>;
|
|
28
|
+
getReply(content: any, uid: any, adminId: string | undefined, variables: any): Promise<any>;
|
|
29
|
+
}
|
|
30
|
+
import { FastGPTAPI } from "../bot/fastgpt/index.js";
|
|
31
|
+
import { ContentCensor } from "../lib/contentCensor.js";
|
|
32
|
+
//# sourceMappingURL=fastgpt.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { FastGPTAPI } from "../bot/fastgpt/index.js";
|
|
2
|
+
import { addAichatRecord } from "../db/aichatDb.js";
|
|
3
|
+
import { ContentCensor } from "../lib/contentCensor.js";
|
|
4
|
+
import { getPuppetEol, isWindowsPlatform } from '../const/puppet-type.js';
|
|
5
|
+
import { v4 as uuidv4 } from "uuid";
|
|
6
|
+
import dayjs from "dayjs";
|
|
7
|
+
import { extractImageLinks } from '../lib/index.js';
|
|
8
|
+
import { getText2Speech } from "../proxy/multimodal.js";
|
|
9
|
+
class FastGPTAi {
|
|
10
|
+
constructor(config = {
|
|
11
|
+
token: '',
|
|
12
|
+
debug: 0,
|
|
13
|
+
proxyPass: '',
|
|
14
|
+
showQuestion: true,
|
|
15
|
+
timeoutMs: 60, // 超时时间 s
|
|
16
|
+
}) {
|
|
17
|
+
this.fastGPT = null;
|
|
18
|
+
this.config = config;
|
|
19
|
+
this.contentCensor = null;
|
|
20
|
+
this.chatOption = {};
|
|
21
|
+
this.eol = '\n';
|
|
22
|
+
this.iswindows = false;
|
|
23
|
+
}
|
|
24
|
+
async init() {
|
|
25
|
+
this.eol = await getPuppetEol();
|
|
26
|
+
this.iswindows = await isWindowsPlatform();
|
|
27
|
+
if (this.config.filter) {
|
|
28
|
+
this.contentCensor = new ContentCensor(this.config.filterConfig);
|
|
29
|
+
}
|
|
30
|
+
console.log(`请求地址:${this.config.proxyPass}`);
|
|
31
|
+
const baseOptions = {
|
|
32
|
+
apiKey: this.config.token,
|
|
33
|
+
debug: this.config.debug,
|
|
34
|
+
apiBaseUrl: this.config.proxyPass
|
|
35
|
+
};
|
|
36
|
+
this.fastGPT = new FastGPTAPI(baseOptions);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* 重置apikey
|
|
40
|
+
* @return {Promise<void>}
|
|
41
|
+
*/
|
|
42
|
+
reset() {
|
|
43
|
+
this.fastGPT = null;
|
|
44
|
+
}
|
|
45
|
+
async getReply(content, uid, adminId = '', variables) {
|
|
46
|
+
try {
|
|
47
|
+
if (!this.fastGPT) {
|
|
48
|
+
console.log('看到此消息说明已启用FastGPT');
|
|
49
|
+
await this.init();
|
|
50
|
+
}
|
|
51
|
+
if (this.config.filter) {
|
|
52
|
+
const censor = await this.contentCensor.checkText(content);
|
|
53
|
+
if (!censor) {
|
|
54
|
+
console.log(`问题:${content},包含违规词,已拦截`);
|
|
55
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
const resetWord = ['reset', '重置', '重置对话', '忽略上下文', '重置上下文', '重新开始', '清除对话', '清除上下文'];
|
|
59
|
+
if (resetWord.includes(content)) {
|
|
60
|
+
console.log('重新更新上下文对话');
|
|
61
|
+
this.chatOption[uid] = null;
|
|
62
|
+
return [{ type: 1, content: '上下文已重置' }];
|
|
63
|
+
}
|
|
64
|
+
if (!this.chatOption[uid]) {
|
|
65
|
+
this.chatOption[uid] = {
|
|
66
|
+
chatId: uuidv4()
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
const sendParams = { ...this.chatOption[uid], variables, timeoutMs: this.config.timeoutMs * 1000 || 80 * 1000 };
|
|
70
|
+
console.log('FastGPT sendParams---', sendParams);
|
|
71
|
+
const { chatId, text, id } = await this.fastGPT.sendMessage(content, sendParams);
|
|
72
|
+
if (this.config.filter) {
|
|
73
|
+
const censor = await this.contentCensor.checkText(text);
|
|
74
|
+
if (!censor) {
|
|
75
|
+
console.log(`回复: ${text},包含违规词,已拦截`);
|
|
76
|
+
return [{ type: 1, content: '这个话题不适合讨论,换个话题吧。' }];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (this.config.record) {
|
|
80
|
+
void addAichatRecord({ contactId: uid, adminId, input: content, output: text, time: dayjs().format('YYYY-MM-DD HH:mm:ss') });
|
|
81
|
+
}
|
|
82
|
+
this.chatOption[uid] = { chatId };
|
|
83
|
+
let replys = [];
|
|
84
|
+
if (this.config?.openTTS) {
|
|
85
|
+
replys = await getText2Speech(text, this.config.ttsConfig);
|
|
86
|
+
if (replys.length) {
|
|
87
|
+
return replys;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
let message;
|
|
91
|
+
if (this.config.showQuestion) {
|
|
92
|
+
message = `${content}${this.eol}-----------${this.eol}` + (this.iswindows ? text.replaceAll('\n', this.eol) : text);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
message = this.iswindows ? text.replaceAll('\n', this.eol) : text;
|
|
96
|
+
}
|
|
97
|
+
const imgs = extractImageLinks(message);
|
|
98
|
+
console.log('imgs', imgs);
|
|
99
|
+
while (message.length > 1500) {
|
|
100
|
+
replys.push(message.slice(0, 1500));
|
|
101
|
+
message = message.slice(1500);
|
|
102
|
+
}
|
|
103
|
+
replys.push(message);
|
|
104
|
+
replys = replys.map(item => {
|
|
105
|
+
return {
|
|
106
|
+
type: 1,
|
|
107
|
+
content: item.trim()
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
if (imgs.length) {
|
|
111
|
+
console.log('提取到内容中的图片', imgs);
|
|
112
|
+
replys = replys.concat(imgs);
|
|
113
|
+
}
|
|
114
|
+
return replys;
|
|
115
|
+
}
|
|
116
|
+
catch (e) {
|
|
117
|
+
console.log('FastGPT报错:' + e);
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
export default FastGPTAi;
|
|
123
|
+
//# sourceMappingURL=fastgpt.js.map
|
|
@@ -22,7 +22,7 @@ async function onRecordMessage(msg) {
|
|
|
22
22
|
const timestamp = msg.timestamp || dayjs().unix();
|
|
23
23
|
const robotInfo = this.currentUser;
|
|
24
24
|
const isOfficial = contact.type() === this.Contact.Type.Official;
|
|
25
|
-
if (
|
|
25
|
+
if (isOfficial)
|
|
26
26
|
return;
|
|
27
27
|
console.log('msg', msg);
|
|
28
28
|
const baseMsg = {
|
|
@@ -32,6 +32,7 @@ async function onRecordMessage(msg) {
|
|
|
32
32
|
chatName: contactName,
|
|
33
33
|
chatId: contact.id,
|
|
34
34
|
chatAlias: contactAlias,
|
|
35
|
+
isMyself: !!msgSelf,
|
|
35
36
|
time: timestamp.length > 10 ? parseInt(timestamp / 1000) : timestamp
|
|
36
37
|
};
|
|
37
38
|
switch (type) {
|
|
@@ -125,7 +126,7 @@ async function onRecordMessage(msg) {
|
|
|
125
126
|
}
|
|
126
127
|
}
|
|
127
128
|
function sendMessage(msgInfo, recordConfig, robotInfo) {
|
|
128
|
-
const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content'];
|
|
129
|
+
const blackKey = ['conversationId', 'conversionName', 'isRoom', 'isRobot', 'chatName', 'chatId', 'chatAlias', 'time', 'type', 'url', 'mediaInfo', 'content', 'isMyself'];
|
|
129
130
|
const baseData = {
|
|
130
131
|
...msgInfo
|
|
131
132
|
};
|