doomiaichat 1.3.0 → 1.4.1

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 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: AxiosRequestConfig): Promise<ChatReponse>;
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,7 +39,7 @@ 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: '缺失聊天的内容' } };
@@ -47,13 +47,14 @@ class AIChat extends events_1.EventEmitter {
47
47
  return { successed: false, error: { errcode: 1, errmsg: '聊天机器人无效' } };
48
48
  let message = typeof (chatText) == 'string' ?
49
49
  [{ role: 'system', content: chatText + '' }] : chatText;
50
+ console.log('message', message);
50
51
  try {
51
52
  const response = yield this.chatRobot.createChatCompletion({
52
- model: callChatOption.model || this.chatModel,
53
+ model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
53
54
  messages: message,
54
55
  temperature: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.temperature) || this.temperature,
55
56
  max_tokens: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.maxtoken) || this.maxtoken,
56
- n: callChatOption.replyCounts || 1
57
+ n: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.replyCounts) || 1
57
58
  }, axiosOption);
58
59
  return { successed: true, message: response.data.choices };
59
60
  }
@@ -106,7 +107,7 @@ class AIChat extends events_1.EventEmitter {
106
107
  let value = result.message[0].message.content.replace(/[^\d]/g, "");
107
108
  if (value > 100)
108
109
  value = Math.floor(value / 10);
109
- return { successed: true, value };
110
+ return { successed: true, value: Number(value) };
110
111
  }
111
112
  return { successed: false, error: result.error, value: 0 };
112
113
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "1.3.0",
3
+ "version": "1.4.1",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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
42
  [{ role: 'system', 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
- model: callChatOption.model || this.chatModel,
47
+ model: callChatOption?.model || this.chatModel,
47
48
  messages: message,
48
49
  temperature: callChatOption?.temperature || this.temperature,
49
50
  max_tokens: callChatOption?.maxtoken || this.maxtoken,
50
- n: callChatOption.replyCounts || 1
51
+ n: callChatOption?.replyCounts || 1
51
52
  }, axiosOption);
52
53
  return {successed:true,message: response.data.choices};
53
54
  } catch (error) {
@@ -95,7 +96,7 @@ export class AIChat extends EventEmitter {
95
96
  if (result.successed && result.message){
96
97
  let value = result.message[0].message.content.replace(/[^\d]/g, "")
97
98
  if (value > 100) value = Math.floor(value / 10);
98
- return { successed: true, value };
99
+ return { successed: true, value:Number(value) };
99
100
  }
100
101
  return { successed: false, error:result.error,value:0 };
101
102