wechaty-web-panel 1.4.14 → 1.4.16
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 +3 -0
- package/dist/cjs/src/common/index.js +1 -1
- package/dist/cjs/src/package-json.d.ts +0 -3
- package/dist/cjs/src/package-json.js +2 -5
- package/dist/cjs/src/proxy/aibotk.js +1 -1
- package/dist/cjs/src/proxy/api.js +6 -6
- package/dist/cjs/src/proxy/openAi.js +7 -0
- package/dist/cjs/src/service/event-dispatch-service.js +0 -4
- package/dist/esm/src/common/index.js +1 -1
- package/dist/esm/src/package-json.d.ts +0 -3
- package/dist/esm/src/package-json.js +2 -5
- package/dist/esm/src/proxy/aibotk.js +1 -1
- package/dist/esm/src/proxy/api.js +6 -6
- package/dist/esm/src/proxy/openAi.js +7 -0
- package/dist/esm/src/service/event-dispatch-service.js +1 -5
- package/package.json +2 -5
- package/dist/cjs/src/proxy/chatgpt.d.ts +0 -10
- package/dist/cjs/src/proxy/chatgpt.js +0 -71
- package/dist/esm/src/proxy/chatgpt.d.ts +0 -10
- package/dist/esm/src/proxy/chatgpt.js +0 -64
package/CHANGELOG.md
CHANGED
|
@@ -55,7 +55,7 @@ exports.getRoomEveryDayContent = getRoomEveryDayContent;
|
|
|
55
55
|
function getCountDownContent(date, prefix, suffix, endWord) {
|
|
56
56
|
let countDownDay = (0, index_js_1.getDay)(date); //获取倒计时天数
|
|
57
57
|
let today = (0, index_js_1.formatDate)(new Date()); //获取今天的日期
|
|
58
|
-
let str = `${today}\r距离${prefix}还有\r\r
|
|
58
|
+
let str = `${today}\r距离${prefix}还有\r\r${countDownDay}天\r\r${suffix}${endWord ? `\r\r————————${endWord}` : ''}`;
|
|
59
59
|
return str;
|
|
60
60
|
}
|
|
61
61
|
exports.getCountDownContent = getCountDownContent;
|
|
@@ -61,11 +61,8 @@ export namespace packageJson {
|
|
|
61
61
|
nedb: string;
|
|
62
62
|
"node-fetch": string;
|
|
63
63
|
"node-schedule": string;
|
|
64
|
-
openai: string;
|
|
65
64
|
puppeteer: string;
|
|
66
65
|
"qrcode-terminal": string;
|
|
67
|
-
remark: string;
|
|
68
|
-
"strip-markdown": string;
|
|
69
66
|
superagent: string;
|
|
70
67
|
};
|
|
71
68
|
namespace publishConfig {
|
|
@@ -6,7 +6,7 @@ exports.packageJson = void 0;
|
|
|
6
6
|
*/
|
|
7
7
|
exports.packageJson = {
|
|
8
8
|
"name": "wechaty-web-panel",
|
|
9
|
-
"version": "1.4.
|
|
9
|
+
"version": "1.4.16",
|
|
10
10
|
"description": "智能微秘书插件",
|
|
11
11
|
"exports": {
|
|
12
12
|
".": {
|
|
@@ -68,7 +68,7 @@ exports.packageJson = {
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"axios": "^0.27.2",
|
|
71
|
-
"chatgpt": "^5.
|
|
71
|
+
"chatgpt": "^5.1.1",
|
|
72
72
|
"dayjs": "^1.11.7",
|
|
73
73
|
"https-proxy-agent": "^5.0.1",
|
|
74
74
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -79,11 +79,8 @@ exports.packageJson = {
|
|
|
79
79
|
"nedb": "^1.8.0",
|
|
80
80
|
"node-fetch": "^2.6.9",
|
|
81
81
|
"node-schedule": "^1.3.2",
|
|
82
|
-
"openai": "^3.1.0",
|
|
83
82
|
"puppeteer": "^13.3.2",
|
|
84
83
|
"qrcode-terminal": "^0.12.0",
|
|
85
|
-
"remark": "^13.0.0",
|
|
86
|
-
"strip-markdown": "^4.2.0",
|
|
87
84
|
"superagent": "^5.2.2"
|
|
88
85
|
},
|
|
89
86
|
"publishConfig": {
|
|
@@ -155,7 +155,7 @@ async function getConfig() {
|
|
|
155
155
|
let content = await (0, superagent_js_1.aiBotReq)(option);
|
|
156
156
|
const config = JSON.parse(content.data.config);
|
|
157
157
|
const cloudRoom = await getWordCloudRoom();
|
|
158
|
-
let cres = await (0, configDb_js_1.updateConfig)({ puppetType: 'wechaty-puppet-wechat', botScope: 'all', parseMini: false, proxyUrl: '', countDownTaskSchedule: [], parseMiniRooms: [], preventLength: 1000, ...config, cloudRoom });
|
|
158
|
+
let cres = await (0, configDb_js_1.updateConfig)({ puppetType: 'wechaty-puppet-wechat', botScope: 'all', parseMini: false, proxyUrl: '', proxyPassUrl: '', countDownTaskSchedule: [], parseMiniRooms: [], preventLength: 1000, ...config, cloudRoom });
|
|
159
159
|
return cres;
|
|
160
160
|
}
|
|
161
161
|
catch (e) {
|
|
@@ -72,7 +72,7 @@ async function getResByTX(word, id) {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
catch (error) {
|
|
75
|
-
console.log('
|
|
75
|
+
console.log('天行聊天机器人请求失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', error);
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
exports.getResByTX = getResByTX;
|
|
@@ -147,7 +147,7 @@ async function getRubbishType(word) {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
catch (error) {
|
|
150
|
-
console.log('
|
|
150
|
+
console.log('垃圾分类请求失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', error);
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
exports.getRubbishType = getRubbishType;
|
|
@@ -172,7 +172,7 @@ async function getSweetWord() {
|
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
174
|
catch (err) {
|
|
175
|
-
console.log('
|
|
175
|
+
console.log('获取土情话接口失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', err);
|
|
176
176
|
}
|
|
177
177
|
}
|
|
178
178
|
exports.getSweetWord = getSweetWord;
|
|
@@ -200,7 +200,7 @@ async function getTXweather(city) {
|
|
|
200
200
|
}
|
|
201
201
|
}
|
|
202
202
|
catch (err) {
|
|
203
|
-
console.log('
|
|
203
|
+
console.log('获取天气接口失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', err);
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
206
|
exports.getTXweather = getTXweather;
|
|
@@ -230,11 +230,11 @@ async function getNews(id, num = 10) {
|
|
|
230
230
|
return `${news}\r`;
|
|
231
231
|
}
|
|
232
232
|
else {
|
|
233
|
-
console.log('
|
|
233
|
+
console.log('获取新闻接口失败:请申请https://www.tianapi.com/apiview/51 这个接口', content.msg);
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
catch (error) {
|
|
237
|
-
console.log('
|
|
237
|
+
console.log('获取天行新闻失败:请申请https://www.tianapi.com/apiview/51 这个接口', error);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
240
240
|
exports.getNews = getNews;
|
|
@@ -33,6 +33,13 @@ async function initChatGPT() {
|
|
|
33
33
|
},
|
|
34
34
|
});
|
|
35
35
|
}
|
|
36
|
+
else if (config.proxyPassUrl) {
|
|
37
|
+
console.log(`启用反向代理请求:${config.proxyPassUrl}`);
|
|
38
|
+
chatGPT = new chatgpt_1.ChatGPTAPI({
|
|
39
|
+
apiBaseUrl: config.proxyPassUrl,
|
|
40
|
+
apiKey: config.gpttoken
|
|
41
|
+
});
|
|
42
|
+
}
|
|
36
43
|
else {
|
|
37
44
|
console.log('未启用代理请求,可能会失败');
|
|
38
45
|
chatGPT = new chatgpt_1.ChatGPTAPI({
|
|
@@ -230,10 +230,6 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
230
230
|
case 6:
|
|
231
231
|
// ChatGPT3
|
|
232
232
|
res = await (0, openAi_js_1.geGPT3Reply)(msg, id);
|
|
233
|
-
if (res.length === 1 && !res[0].content) {
|
|
234
|
-
console.log('第一个gpt接口返回失败,开始请求第二个gpt接口');
|
|
235
|
-
res = await (0, chatgpt_js_1.geGPTReply)(msg, id);
|
|
236
|
-
}
|
|
237
233
|
replys = res;
|
|
238
234
|
break;
|
|
239
235
|
default:
|
|
@@ -49,7 +49,7 @@ async function getRoomEveryDayContent(date, city, endWord) {
|
|
|
49
49
|
function getCountDownContent(date, prefix, suffix, endWord) {
|
|
50
50
|
let countDownDay = getDay(date); //获取倒计时天数
|
|
51
51
|
let today = formatDate(new Date()); //获取今天的日期
|
|
52
|
-
let str = `${today}\r距离${prefix}还有\r\r
|
|
52
|
+
let str = `${today}\r距离${prefix}还有\r\r${countDownDay}天\r\r${suffix}${endWord ? `\r\r————————${endWord}` : ''}`;
|
|
53
53
|
return str;
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
@@ -61,11 +61,8 @@ export namespace packageJson {
|
|
|
61
61
|
nedb: string;
|
|
62
62
|
"node-fetch": string;
|
|
63
63
|
"node-schedule": string;
|
|
64
|
-
openai: string;
|
|
65
64
|
puppeteer: string;
|
|
66
65
|
"qrcode-terminal": string;
|
|
67
|
-
remark: string;
|
|
68
|
-
"strip-markdown": string;
|
|
69
66
|
superagent: string;
|
|
70
67
|
};
|
|
71
68
|
namespace publishConfig {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
export const packageJson = {
|
|
5
5
|
"name": "wechaty-web-panel",
|
|
6
|
-
"version": "1.4.
|
|
6
|
+
"version": "1.4.16",
|
|
7
7
|
"description": "智能微秘书插件",
|
|
8
8
|
"exports": {
|
|
9
9
|
".": {
|
|
@@ -65,7 +65,7 @@ export const packageJson = {
|
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"axios": "^0.27.2",
|
|
68
|
-
"chatgpt": "^5.
|
|
68
|
+
"chatgpt": "^5.1.1",
|
|
69
69
|
"dayjs": "^1.11.7",
|
|
70
70
|
"https-proxy-agent": "^5.0.1",
|
|
71
71
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -76,11 +76,8 @@ export const packageJson = {
|
|
|
76
76
|
"nedb": "^1.8.0",
|
|
77
77
|
"node-fetch": "^2.6.9",
|
|
78
78
|
"node-schedule": "^1.3.2",
|
|
79
|
-
"openai": "^3.1.0",
|
|
80
79
|
"puppeteer": "^13.3.2",
|
|
81
80
|
"qrcode-terminal": "^0.12.0",
|
|
82
|
-
"remark": "^13.0.0",
|
|
83
|
-
"strip-markdown": "^4.2.0",
|
|
84
81
|
"superagent": "^5.2.2"
|
|
85
82
|
},
|
|
86
83
|
"publishConfig": {
|
|
@@ -146,7 +146,7 @@ async function getConfig() {
|
|
|
146
146
|
let content = await aiBotReq(option);
|
|
147
147
|
const config = JSON.parse(content.data.config);
|
|
148
148
|
const cloudRoom = await getWordCloudRoom();
|
|
149
|
-
let cres = await updateConfig({ puppetType: 'wechaty-puppet-wechat', botScope: 'all', parseMini: false, proxyUrl: '', countDownTaskSchedule: [], parseMiniRooms: [], preventLength: 1000, ...config, cloudRoom });
|
|
149
|
+
let cres = await updateConfig({ puppetType: 'wechaty-puppet-wechat', botScope: 'all', parseMini: false, proxyUrl: '', proxyPassUrl: '', countDownTaskSchedule: [], parseMiniRooms: [], preventLength: 1000, ...config, cloudRoom });
|
|
150
150
|
return cres;
|
|
151
151
|
}
|
|
152
152
|
catch (e) {
|
|
@@ -68,7 +68,7 @@ async function getResByTX(word, id) {
|
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
catch (error) {
|
|
71
|
-
console.log('
|
|
71
|
+
console.log('天行聊天机器人请求失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', error);
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
/**
|
|
@@ -141,7 +141,7 @@ async function getRubbishType(word) {
|
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
catch (error) {
|
|
144
|
-
console.log('
|
|
144
|
+
console.log('垃圾分类请求失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', error);
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
@@ -165,7 +165,7 @@ async function getSweetWord() {
|
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
catch (err) {
|
|
168
|
-
console.log('
|
|
168
|
+
console.log('获取土情话接口失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', err);
|
|
169
169
|
}
|
|
170
170
|
}
|
|
171
171
|
/**
|
|
@@ -192,7 +192,7 @@ async function getTXweather(city) {
|
|
|
192
192
|
}
|
|
193
193
|
}
|
|
194
194
|
catch (err) {
|
|
195
|
-
console.log('
|
|
195
|
+
console.log('获取天气接口失败:参考 http://wechat.aibotk.com/docs/install 在天行申请必选接口', err);
|
|
196
196
|
}
|
|
197
197
|
}
|
|
198
198
|
/**
|
|
@@ -221,11 +221,11 @@ async function getNews(id, num = 10) {
|
|
|
221
221
|
return `${news}\r`;
|
|
222
222
|
}
|
|
223
223
|
else {
|
|
224
|
-
console.log('
|
|
224
|
+
console.log('获取新闻接口失败:请申请https://www.tianapi.com/apiview/51 这个接口', content.msg);
|
|
225
225
|
}
|
|
226
226
|
}
|
|
227
227
|
catch (error) {
|
|
228
|
-
console.log('
|
|
228
|
+
console.log('获取天行新闻失败:请申请https://www.tianapi.com/apiview/51 这个接口', error);
|
|
229
229
|
}
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
@@ -27,6 +27,13 @@ export async function initChatGPT() {
|
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
}
|
|
30
|
+
else if (config.proxyPassUrl) {
|
|
31
|
+
console.log(`启用反向代理请求:${config.proxyPassUrl}`);
|
|
32
|
+
chatGPT = new ChatGPTAPI({
|
|
33
|
+
apiBaseUrl: config.proxyPassUrl,
|
|
34
|
+
apiKey: config.gpttoken
|
|
35
|
+
});
|
|
36
|
+
}
|
|
30
37
|
else {
|
|
31
38
|
console.log('未启用代理请求,可能会失败');
|
|
32
39
|
chatGPT = new ChatGPTAPI({
|
|
@@ -6,7 +6,7 @@ import { initTaskLocalSchedule, initTimeSchedule } from "../task/index.js";
|
|
|
6
6
|
import { updateContactAndRoom, updateContactOnly, updateRoomOnly } from '../common/index.js';
|
|
7
7
|
import { getTencentOpenReply } from '../proxy/tencent-open.js';
|
|
8
8
|
import { getRoomRecordContent, removeRecord } from "../db/roomDb.js";
|
|
9
|
-
import {
|
|
9
|
+
import { initOpenApi } from '../proxy/chatgpt.js';
|
|
10
10
|
import { geGPT3Reply, initGpt } from '../proxy/openAi.js';
|
|
11
11
|
/**
|
|
12
12
|
* 根据事件名称分配不同的api处理,并获取返回内容
|
|
@@ -223,10 +223,6 @@ async function dispatchAiBot(bot, msg, name, id) {
|
|
|
223
223
|
case 6:
|
|
224
224
|
// ChatGPT3
|
|
225
225
|
res = await geGPT3Reply(msg, id);
|
|
226
|
-
if (res.length === 1 && !res[0].content) {
|
|
227
|
-
console.log('第一个gpt接口返回失败,开始请求第二个gpt接口');
|
|
228
|
-
res = await geGPTReply(msg, id);
|
|
229
|
-
}
|
|
230
226
|
replys = res;
|
|
231
227
|
break;
|
|
232
228
|
default:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wechaty-web-panel",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.16",
|
|
4
4
|
"description": "智能微秘书插件",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
},
|
|
63
63
|
"dependencies": {
|
|
64
64
|
"axios": "^0.27.2",
|
|
65
|
-
"chatgpt": "^5.
|
|
65
|
+
"chatgpt": "^5.1.1",
|
|
66
66
|
"dayjs": "^1.11.7",
|
|
67
67
|
"https-proxy-agent": "^5.0.1",
|
|
68
68
|
"isomorphic-fetch": "^3.0.0",
|
|
@@ -73,11 +73,8 @@
|
|
|
73
73
|
"nedb": "^1.8.0",
|
|
74
74
|
"node-fetch": "^2.6.9",
|
|
75
75
|
"node-schedule": "^1.3.2",
|
|
76
|
-
"openai": "^3.1.0",
|
|
77
76
|
"puppeteer": "^13.3.2",
|
|
78
77
|
"qrcode-terminal": "^0.12.0",
|
|
79
|
-
"remark": "^13.0.0",
|
|
80
|
-
"strip-markdown": "^4.2.0",
|
|
81
78
|
"superagent": "^5.2.2"
|
|
82
79
|
},
|
|
83
80
|
"publishConfig": {
|
|
@@ -1,71 +0,0 @@
|
|
|
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.geGPTReply = exports.initOpenApi = void 0;
|
|
7
|
-
const remark_1 = __importDefault(require("remark"));
|
|
8
|
-
const strip_markdown_1 = __importDefault(require("strip-markdown"));
|
|
9
|
-
const openai_1 = require("openai");
|
|
10
|
-
const configDb_js_1 = require("../db/configDb.js");
|
|
11
|
-
let openai = null;
|
|
12
|
-
function markdownToText(markdown) {
|
|
13
|
-
return (0, remark_1.default)()
|
|
14
|
-
.use(strip_markdown_1.default)
|
|
15
|
-
.processSync(markdown || '')
|
|
16
|
-
.toString();
|
|
17
|
-
}
|
|
18
|
-
function initOpenApi() {
|
|
19
|
-
openai = null;
|
|
20
|
-
}
|
|
21
|
-
exports.initOpenApi = initOpenApi;
|
|
22
|
-
async function geGPTReply(content) {
|
|
23
|
-
try {
|
|
24
|
-
const config = await (0, configDb_js_1.allConfig)();
|
|
25
|
-
if (!config.gpttoken) {
|
|
26
|
-
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
27
|
-
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
28
|
-
}
|
|
29
|
-
if (!openai) {
|
|
30
|
-
let configuration = new openai_1.Configuration({
|
|
31
|
-
apiKey: config.gpttoken,
|
|
32
|
-
});
|
|
33
|
-
openai = new openai_1.OpenAIApi(configuration);
|
|
34
|
-
}
|
|
35
|
-
let response = await openai.createCompletion({
|
|
36
|
-
model: 'text-davinci-003',
|
|
37
|
-
prompt: content,
|
|
38
|
-
temperature: 0.9,
|
|
39
|
-
max_tokens: 2000,
|
|
40
|
-
top_p: 1,
|
|
41
|
-
frequency_penalty: 0.0,
|
|
42
|
-
presence_penalty: 0.6,
|
|
43
|
-
stop: ['Human:', 'AI:'],
|
|
44
|
-
});
|
|
45
|
-
console.log('chat gpt返回原始数据:' + response.data.choices[0].text);
|
|
46
|
-
response = markdownToText(response.data.choices[0].text);
|
|
47
|
-
let replys = [];
|
|
48
|
-
let message = response;
|
|
49
|
-
while (message.length > 500) {
|
|
50
|
-
replys.push(message.slice(0, 500));
|
|
51
|
-
message = message.slice(500);
|
|
52
|
-
}
|
|
53
|
-
replys.push(message);
|
|
54
|
-
replys = replys.map(item => {
|
|
55
|
-
return {
|
|
56
|
-
type: 1,
|
|
57
|
-
content: item.trim()
|
|
58
|
-
};
|
|
59
|
-
});
|
|
60
|
-
return replys;
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
console.log('chat gpt报错:' + e);
|
|
64
|
-
return [{ type: 1, content: '' }];
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.geGPTReply = geGPTReply;
|
|
68
|
-
exports.default = {
|
|
69
|
-
geGPTReply,
|
|
70
|
-
};
|
|
71
|
-
//# sourceMappingURL=chatgpt.js.map
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import remark from 'remark';
|
|
2
|
-
import stripMarkdown from 'strip-markdown';
|
|
3
|
-
import { Configuration, OpenAIApi } from 'openai';
|
|
4
|
-
import { allConfig } from "../db/configDb.js";
|
|
5
|
-
let openai = null;
|
|
6
|
-
function markdownToText(markdown) {
|
|
7
|
-
return remark()
|
|
8
|
-
.use(stripMarkdown)
|
|
9
|
-
.processSync(markdown || '')
|
|
10
|
-
.toString();
|
|
11
|
-
}
|
|
12
|
-
export function initOpenApi() {
|
|
13
|
-
openai = null;
|
|
14
|
-
}
|
|
15
|
-
async function geGPTReply(content) {
|
|
16
|
-
try {
|
|
17
|
-
const config = await allConfig();
|
|
18
|
-
if (!config.gpttoken) {
|
|
19
|
-
console.log('请到智能微秘书平台配置Openai apikey参数方可使用');
|
|
20
|
-
return [{ type: 1, content: '请到平台配置Openai apikey参数方可使用' }];
|
|
21
|
-
}
|
|
22
|
-
if (!openai) {
|
|
23
|
-
let configuration = new Configuration({
|
|
24
|
-
apiKey: config.gpttoken,
|
|
25
|
-
});
|
|
26
|
-
openai = new OpenAIApi(configuration);
|
|
27
|
-
}
|
|
28
|
-
let response = await openai.createCompletion({
|
|
29
|
-
model: 'text-davinci-003',
|
|
30
|
-
prompt: content,
|
|
31
|
-
temperature: 0.9,
|
|
32
|
-
max_tokens: 2000,
|
|
33
|
-
top_p: 1,
|
|
34
|
-
frequency_penalty: 0.0,
|
|
35
|
-
presence_penalty: 0.6,
|
|
36
|
-
stop: ['Human:', 'AI:'],
|
|
37
|
-
});
|
|
38
|
-
console.log('chat gpt返回原始数据:' + response.data.choices[0].text);
|
|
39
|
-
response = markdownToText(response.data.choices[0].text);
|
|
40
|
-
let replys = [];
|
|
41
|
-
let message = response;
|
|
42
|
-
while (message.length > 500) {
|
|
43
|
-
replys.push(message.slice(0, 500));
|
|
44
|
-
message = message.slice(500);
|
|
45
|
-
}
|
|
46
|
-
replys.push(message);
|
|
47
|
-
replys = replys.map(item => {
|
|
48
|
-
return {
|
|
49
|
-
type: 1,
|
|
50
|
-
content: item.trim()
|
|
51
|
-
};
|
|
52
|
-
});
|
|
53
|
-
return replys;
|
|
54
|
-
}
|
|
55
|
-
catch (e) {
|
|
56
|
-
console.log('chat gpt报错:' + e);
|
|
57
|
-
return [{ type: 1, content: '' }];
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
export { geGPTReply };
|
|
61
|
-
export default {
|
|
62
|
-
geGPTReply,
|
|
63
|
-
};
|
|
64
|
-
//# sourceMappingURL=chatgpt.js.map
|