doomiaichat 1.4.0 → 1.4.3
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/index.d.ts +1 -1
- package/dist/index.js +7 -6
- package/package.json +1 -1
- package/src/index.ts +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -16,7 +16,7 @@ export declare class AIChat extends EventEmitter {
|
|
|
16
16
|
* 向OpenAI发送一个聊天请求
|
|
17
17
|
* @param {*} chatText
|
|
18
18
|
*/
|
|
19
|
-
chatRequest(chatText: string | Array<any>, callChatOption: CallChatApiOption, axiosOption
|
|
19
|
+
chatRequest(chatText: string | Array<any>, callChatOption: CallChatApiOption, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
|
|
20
20
|
/**
|
|
21
21
|
* 判断一句话的表达情绪
|
|
22
22
|
* @param {*} s1
|
package/dist/index.js
CHANGED
|
@@ -39,21 +39,22 @@ class AIChat extends events_1.EventEmitter {
|
|
|
39
39
|
* 向OpenAI发送一个聊天请求
|
|
40
40
|
* @param {*} chatText
|
|
41
41
|
*/
|
|
42
|
-
chatRequest(chatText, callChatOption, axiosOption) {
|
|
42
|
+
chatRequest(chatText, callChatOption, axiosOption = {}) {
|
|
43
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
44
44
|
if (!chatText)
|
|
45
45
|
return { successed: false, error: { errcode: 2, errmsg: '缺失聊天的内容' } };
|
|
46
46
|
if (!this.chatRobot)
|
|
47
47
|
return { successed: false, error: { errcode: 1, errmsg: '聊天机器人无效' } };
|
|
48
48
|
let message = typeof (chatText) == 'string' ?
|
|
49
|
-
[{ role: '
|
|
49
|
+
[{ role: 'user', content: chatText }] : chatText;
|
|
50
|
+
console.log('message', message);
|
|
50
51
|
try {
|
|
51
52
|
const response = yield this.chatRobot.createChatCompletion({
|
|
52
53
|
model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
|
|
53
54
|
messages: message,
|
|
54
|
-
temperature: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.temperature) || this.temperature,
|
|
55
|
-
max_tokens: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.maxtoken) || this.maxtoken,
|
|
56
|
-
n: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.replyCounts) || 1
|
|
55
|
+
temperature: Number((callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.temperature) || this.temperature),
|
|
56
|
+
max_tokens: Number((callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.maxtoken) || this.maxtoken),
|
|
57
|
+
n: Number((callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.replyCounts) || 1) || 1
|
|
57
58
|
}, axiosOption);
|
|
58
59
|
return { successed: true, message: response.data.choices };
|
|
59
60
|
}
|
|
@@ -127,7 +128,7 @@ class AIChat extends events_1.EventEmitter {
|
|
|
127
128
|
///如果源话是全中文,那么结果中不应该出来英文的相似说法,如果源话是全英文,则结果不能出现全中文的说法
|
|
128
129
|
let prefix = (!chnReg && engReg) ? '请用完整的英文表达,' : ((chnReg && !engReg) ? '请用完整的中文表达,' : '');
|
|
129
130
|
const text = `${prefix}生成与下面句子意思相同的内容"${content}"`;
|
|
130
|
-
let result = yield this.chatRequest(
|
|
131
|
+
let result = yield this.chatRequest(text, { replyCounts: count }, axiosOption);
|
|
131
132
|
if (!result.successed || !result.message)
|
|
132
133
|
return result;
|
|
133
134
|
let replys = result.message.map(item => { return item.message.content.trim(); });
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -34,20 +34,21 @@ export class AIChat extends EventEmitter {
|
|
|
34
34
|
* 向OpenAI发送一个聊天请求
|
|
35
35
|
* @param {*} chatText
|
|
36
36
|
*/
|
|
37
|
-
public async chatRequest(chatText: string | Array<any>, callChatOption: CallChatApiOption, axiosOption: AxiosRequestConfig): Promise<ChatReponse> {
|
|
37
|
+
public async chatRequest(chatText: string | Array<any>, callChatOption: CallChatApiOption, axiosOption: AxiosRequestConfig={}): Promise<ChatReponse> {
|
|
38
38
|
if (!chatText) return {successed:false, error:{ errcode: 2, errmsg: '缺失聊天的内容' }};
|
|
39
39
|
if(!this.chatRobot) return {successed: false, error: { errcode: 1, errmsg: '聊天机器人无效' }};
|
|
40
40
|
|
|
41
41
|
let message: Array<ChatCompletionRequestMessage> = typeof(chatText)=='string'?
|
|
42
|
-
[{ role: '
|
|
42
|
+
[{ role: 'user', content: chatText}] : chatText;
|
|
43
|
+
console.log('message', message)
|
|
43
44
|
try {
|
|
44
45
|
const response: AxiosResponse<CreateChatCompletionResponse, any>
|
|
45
46
|
= await this.chatRobot.createChatCompletion({
|
|
46
47
|
model: callChatOption?.model || this.chatModel,
|
|
47
48
|
messages: message,
|
|
48
|
-
temperature: callChatOption?.temperature || this.temperature,
|
|
49
|
-
max_tokens: callChatOption?.maxtoken || this.maxtoken,
|
|
50
|
-
n: callChatOption?.replyCounts || 1
|
|
49
|
+
temperature: Number(callChatOption?.temperature || this.temperature),
|
|
50
|
+
max_tokens: Number(callChatOption?.maxtoken || this.maxtoken),
|
|
51
|
+
n: Number(callChatOption?.replyCounts || 1) || 1
|
|
51
52
|
}, axiosOption);
|
|
52
53
|
return {successed:true,message: response.data.choices};
|
|
53
54
|
} catch (error) {
|
|
@@ -117,7 +118,7 @@ export class AIChat extends EventEmitter {
|
|
|
117
118
|
///如果源话是全中文,那么结果中不应该出来英文的相似说法,如果源话是全英文,则结果不能出现全中文的说法
|
|
118
119
|
let prefix = (!chnReg && engReg) ? '请用完整的英文表达,' : ((chnReg && !engReg) ? '请用完整的中文表达,':'')
|
|
119
120
|
const text = `${prefix}生成与下面句子意思相同的内容"${content}"`
|
|
120
|
-
let result = await this.chatRequest(
|
|
121
|
+
let result = await this.chatRequest(text, { replyCounts: count }, axiosOption);
|
|
121
122
|
if (!result.successed || !result.message) return result;
|
|
122
123
|
let replys = result.message.map(item => { return item.message.content.trim(); })
|
|
123
124
|
return { successed: true, message: replys }
|