doomiaichat 1.4.3 → 1.4.5

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
@@ -39,6 +39,12 @@ export declare class AIChat extends EventEmitter {
39
39
  * @param {需要出来的数量} count
40
40
  */
41
41
  getSimilarityContent(content: string, count?: number, axiosOption?: AxiosRequestConfig): Promise<ChatReponse>;
42
+ /**
43
+ * 提取内容的中心思想摘要
44
+ * @param content
45
+ * @param axiosOption
46
+ */
47
+ getSummaryOfContent(content: string | Array<any>, axiosOption?: AxiosRequestConfig): Promise<SummaryReponse>;
42
48
  /**
43
49
  * 从指定的文本内容中生成相关的问答
44
50
  * @param {*} content
@@ -97,6 +103,17 @@ export interface ChatReponse extends ApiResult {
97
103
  */
98
104
  'message'?: Array<any>;
99
105
  }
106
+ /**
107
+ * 摘要信息
108
+ */
109
+ export interface SummaryReponse extends ApiResult {
110
+ /**
111
+ * The name of the user in a multi-user chat
112
+ * @type {Array<any>}
113
+ * @memberof SummaryReponse
114
+ */
115
+ 'summary'?: Array<string>;
116
+ }
100
117
  /**
101
118
  * 调用OpenAI Api的参数约定
102
119
  */
package/dist/index.js CHANGED
@@ -47,7 +47,7 @@ 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: 'user', content: chatText }] : chatText;
50
- console.log('message', message);
50
+ // console.log('message', message)
51
51
  try {
52
52
  const response = yield this.chatRobot.createChatCompletion({
53
53
  model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
@@ -135,6 +135,36 @@ class AIChat extends events_1.EventEmitter {
135
135
  return { successed: true, message: replys };
136
136
  });
137
137
  }
138
+ /**
139
+ * 提取内容的中心思想摘要
140
+ * @param content
141
+ * @param axiosOption
142
+ */
143
+ getSummaryOfContent(content, axiosOption = {}) {
144
+ return __awaiter(this, void 0, void 0, function* () {
145
+ const arrContent = typeof (content) == 'string' ? this.splitLongText(content) : content;
146
+ let summary = [];
147
+ while (arrContent.length > 0) {
148
+ let subarray = arrContent.slice(0, MESSAGE_LENGTH);
149
+ subarray.push({ role: 'user', content: '根据上述内容精简,提炼摘要内容,并将摘要逐条放入JSON数组结构输出' });
150
+ let result = yield this.chatRequest(subarray, {}, axiosOption);
151
+ if (result.successed && result.message) {
152
+ try {
153
+ let jsonObjItems = JSON.parse(result.message[0].content);
154
+ console.log('result.message[0].content', result.message[0].content);
155
+ if (Array.isArray(jsonObjItems))
156
+ summary = summary.concat(jsonObjItems);
157
+ }
158
+ catch (error) {
159
+ console.log('result.message[0].content', error, result.message[0].content);
160
+ }
161
+ }
162
+ ////删除已经处理的文本
163
+ arrContent.splice(0, MESSAGE_LENGTH);
164
+ }
165
+ return { successed: true, summary };
166
+ });
167
+ }
138
168
  /**
139
169
  * 从指定的文本内容中生成相关的问答
140
170
  * @param {*} content
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "1.4.3",
3
+ "version": "1.4.5",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -40,7 +40,7 @@ export class AIChat extends EventEmitter {
40
40
 
41
41
  let message: Array<ChatCompletionRequestMessage> = typeof(chatText)=='string'?
42
42
  [{ role: 'user', content: chatText}] : chatText;
43
- console.log('message', message)
43
+ // console.log('message', message)
44
44
  try {
45
45
  const response: AxiosResponse<CreateChatCompletionResponse, any>
46
46
  = await this.chatRobot.createChatCompletion({
@@ -123,7 +123,32 @@ export class AIChat extends EventEmitter {
123
123
  let replys = result.message.map(item => { return item.message.content.trim(); })
124
124
  return { successed: true, message: replys }
125
125
  }
126
-
126
+ /**
127
+ * 提取内容的中心思想摘要
128
+ * @param content
129
+ * @param axiosOption
130
+ */
131
+ async getSummaryOfContent(content: string|Array<any>, axiosOption: AxiosRequestConfig = {}): Promise<SummaryReponse> {
132
+ const arrContent = typeof (content) == 'string' ? this.splitLongText(content) : content;
133
+ let summary :Array<string> = [];
134
+ while (arrContent.length > 0 ) {
135
+ let subarray = arrContent.slice(0, MESSAGE_LENGTH);
136
+ subarray.push({ role: 'user', content: '根据上述内容精简,提炼摘要内容,并将摘要逐条放入JSON数组结构输出' })
137
+ let result = await this.chatRequest(subarray, {}, axiosOption);
138
+ if (result.successed && result.message){
139
+ try{
140
+ let jsonObjItems = JSON.parse(result.message[0].content)
141
+ console.log('result.message[0].content', result.message[0].content)
142
+ if (Array.isArray(jsonObjItems)) summary = summary.concat(jsonObjItems)
143
+ }catch(error){
144
+ console.log('result.message[0].content',error, result.message[0].content)
145
+ }
146
+ }
147
+ ////删除已经处理的文本
148
+ arrContent.splice(0, MESSAGE_LENGTH);
149
+ }
150
+ return { successed: true, summary }
151
+ }
127
152
  /**
128
153
  * 从指定的文本内容中生成相关的问答
129
154
  * @param {*} content
@@ -342,6 +367,18 @@ export interface ChatReponse extends ApiResult {
342
367
  */
343
368
  'message'?: Array<any>;
344
369
  }
370
+ /**
371
+ * 摘要信息
372
+ */
373
+ export interface SummaryReponse extends ApiResult {
374
+
375
+ /**
376
+ * The name of the user in a multi-user chat
377
+ * @type {Array<any>}
378
+ * @memberof SummaryReponse
379
+ */
380
+ 'summary'?:Array<string>;
381
+ }
345
382
  /**
346
383
  * 调用OpenAI Api的参数约定
347
384
  */