doomiaichat 3.0.0 → 3.0.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/openai.d.ts CHANGED
@@ -76,14 +76,7 @@ export default class OpenAIGpt extends GptBase {
76
76
  * @param {*} count
77
77
  * @param {*} axiosOption
78
78
  * @returns
79
- */ generateQuestionsFromContent(content: string, count?: number, axiosOption?: any): Promise<ChatReponse>;
80
- /**
81
- * 从指定的文本内容中生成相关的问答
82
- * @param {*} content
83
- * @param {*} count
84
- * @param {*} axiosOption
85
- * @returns
86
- */ generateQuestionsFromContent_Orgin(content: string, count?: number, promotion?: string | null, sliceslength?: number, axiosOption?: any): Promise<ChatReponse>;
79
+ */ generateQuestionsFromContent(content: string, count?: number, everyContentLength?: number, axiosOption?: any): Promise<ChatReponse>;
87
80
  /**
88
81
  * 解析Faq返回的问题
89
82
  * @param {*} messages
@@ -98,7 +91,7 @@ export default class OpenAIGpt extends GptBase {
98
91
  * section: {type:[0,1,2,3]为单选、多选、判断、填空题型 count:生成多少道 score:本段分数}
99
92
  * @param {*} axiosOption
100
93
  * @returns
101
- */ generateExaminationPaperFromContent(content: string, paperOption?: any, axiosOption?: any): Promise<ExaminationPaperResult>;
94
+ */ generateExaminationPaperFromContent(content: string, paperOption?: any, everyContentLength?: number, axiosOption?: any): Promise<ExaminationPaperResult>;
102
95
  /**
103
96
  * 从答复中得到题目
104
97
  * @param {*} result
package/dist/openai.js CHANGED
@@ -15,7 +15,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  const azure_openai_1 = require("azure-openai");
16
16
  // import { EventEmitter } from "events";
17
17
  const gptbase_1 = __importDefault(require("./gptbase"));
18
- const SECTION_LENGTH = 1600; ///每2400个字符分成一组
18
+ const SECTION_LENGTH = 1024; ///每2400个字符分成一组
19
19
  const MESSAGE_LENGTH = 1; ///每次送8句话给openai 进行解析,送多了,会报错
20
20
  //请将答案放在最后,标记为答案:()
21
21
  const QUESTION_TEXT_MAPPING = {
@@ -119,7 +119,6 @@ class OpenAIGpt extends gptbase_1.default {
119
119
  try {
120
120
  let finishreason = null, usage = null;
121
121
  const response = yield this.aiApi.createChatCompletion({
122
- // engine: callChatOption?.engine||this.engine,
123
122
  model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
124
123
  messages: message,
125
124
  stream: true,
@@ -130,7 +129,6 @@ class OpenAIGpt extends gptbase_1.default {
130
129
  const lines = data.toString().split('\n').filter((line) => line.trim() !== '');
131
130
  for (const line of lines) {
132
131
  const message = line.replace(/^data: /, '');
133
- // console.log('message', message)
134
132
  if (message === '[DONE]') {
135
133
  this.emit('chatdone', { successed: true, finish_reason: finishreason, usage });
136
134
  return; // Stream finished
@@ -144,16 +142,13 @@ class OpenAIGpt extends gptbase_1.default {
144
142
  this.emit('chattext', { successed: true, text: parsed.choices[0].delta.content, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage });
145
143
  }
146
144
  catch (error) {
147
- this.emit('chaterror', { successed: false, error: 'no text in chat', message });
148
- //console.error('Could not JSON parse stream message', message, error);
145
+ this.emit('chaterror', { successed: false, error: 'JSON parse stream message', message });
149
146
  }
150
147
  }
151
148
  });
152
149
  }
153
150
  catch (error) {
154
151
  this.emit('error', { successed: false, error: 'call axios faied ' + error });
155
- //console.log('result is error ', error)
156
- // return { successed: false, error };
157
152
  }
158
153
  });
159
154
  }
@@ -303,9 +298,9 @@ class OpenAIGpt extends gptbase_1.default {
303
298
  * @param {*} axiosOption
304
299
  * @returns
305
300
  */ //并在答案末尾处必须给出答案内容中的关键词
306
- generateQuestionsFromContent(content, count = 1, axiosOption = {}) {
301
+ generateQuestionsFromContent(content, count = 1, everyContentLength = SECTION_LENGTH, axiosOption = {}) {
307
302
  return __awaiter(this, void 0, void 0, function* () {
308
- let arrContent = this.splitLongText(content, 300);
303
+ let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
309
304
  ///没20句话分为一组,适应大文件内容多次请求组合结果
310
305
  ///每一句话需要产生的题目
311
306
  let questions4EverySentense = count / arrContent.length; //Math.ceil(arrContent.length / 20);
@@ -313,7 +308,7 @@ class OpenAIGpt extends gptbase_1.default {
313
308
  while (arrContent.length > 0 && gotted < count) {
314
309
  questions4EverySentense = (count - gotted) / arrContent.length;
315
310
  ////每次最多送MESSAGE_LENGTH句话给openai
316
- let subarray = arrContent.slice(0, 4);
311
+ let subarray = arrContent.slice(0, 1);
317
312
  let itemCount = Math.min(Math.ceil(subarray.length * questions4EverySentense), count - gotted);
318
313
  //subarray.push({ role: 'user', content:'请根据上述内容,给出一道提问与答案以及答案关键词,按照先问题内容,再标准答案,再关键词的顺序输出,关键词之间用、分开'})
319
314
  subarray.unshift({ role: 'system', content: `你是一位专业培训师,从以下内容中提取${itemCount}条提问及答案,并从答案内容提取出至少2个关键词,最终结果按照[{"question":"提问内容","answer":"答案内容","keywords":["关键词1","关键词2"]}]的JSON数组结构输出。` });
@@ -339,38 +334,6 @@ class OpenAIGpt extends gptbase_1.default {
339
334
  return { successed: true, message: faqs.slice(0, count) };
340
335
  });
341
336
  }
342
- /**
343
- * 从指定的文本内容中生成相关的问答
344
- * @param {*} content
345
- * @param {*} count
346
- * @param {*} axiosOption
347
- * @returns
348
- */ //并在答案末尾处必须给出答案内容中的关键词
349
- generateQuestionsFromContent_Orgin(content, count = 1, promotion = null, sliceslength = SECTION_LENGTH, axiosOption = {}) {
350
- return __awaiter(this, void 0, void 0, function* () {
351
- let arrContent = this.splitLongText(content, sliceslength || 300);
352
- ///没20句话分为一组,适应大文件内容多次请求组合结果
353
- ///每一句话需要产生的题目
354
- let questions4EverySentense = count / arrContent.length; //Math.ceil(arrContent.length / 20);
355
- let faqs = [], gotted = 0;
356
- while (arrContent.length > 0 && gotted < count) {
357
- questions4EverySentense = (count - gotted) / arrContent.length;
358
- ////每次最多送MESSAGE_LENGTH句话给openai
359
- let subarray = arrContent.slice(0, 4);
360
- let itemCount = Math.min(Math.ceil(subarray.length * questions4EverySentense), count - gotted);
361
- subarray.unshift({ role: 'system', content: promotion || `你是一位专业培训师,从以下内容中提取${itemCount}条提问及答案,并从答案内容提取出至少2个关键词,最终结果按照[{"question":"提问内容","answer":"答案内容","keywords":["关键词1","关键词2"]}]的JSON数组结构输出。` });
362
- let result = yield this.chatRequest(subarray, { replyCounts: 1 }, axiosOption);
363
- if (result.successed && result.message) {
364
- let answer = result.message.map(i => { return i.message.content.trim().replace(/\t|\n|\v|\r|\f/g, ''); });
365
- faqs = faqs.concat(answer);
366
- }
367
- ////删除已经处理的文本
368
- arrContent.splice(0, 4);
369
- }
370
- arrContent = []; /// 释放内存
371
- return { successed: true, message: faqs };
372
- });
373
- }
374
337
  /**
375
338
  * 解析Faq返回的问题
376
339
  * @param {*} messages
@@ -417,10 +380,10 @@ class OpenAIGpt extends gptbase_1.default {
417
380
  * @param {*} axiosOption
418
381
  * @returns
419
382
  */ //并在答案末尾处必须给出答案内容中的关键词
420
- generateExaminationPaperFromContent(content, paperOption = {}, axiosOption = {}) {
383
+ generateExaminationPaperFromContent(content, paperOption = {}, everyContentLength = SECTION_LENGTH, axiosOption = {}) {
421
384
  var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
422
385
  return __awaiter(this, void 0, void 0, function* () {
423
- let arrContent = this.splitLongText(content, 1024);
386
+ let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
424
387
  let sectionCount = {
425
388
  singlechoice: (((_a = paperOption.singlechoice) === null || _a === void 0 ? void 0 : _a.count) || 0) / arrContent.length,
426
389
  multiplechoice: (((_b = paperOption.multiplechoice) === null || _b === void 0 ? void 0 : _b.count) || 0) / arrContent.length,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "3.0.0",
3
+ "version": "3.0.1",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/openai.ts CHANGED
@@ -2,7 +2,7 @@ import { Configuration, OpenAIApi, ChatCompletionRequestMessage } from "azure-op
2
2
  // import { EventEmitter } from "events";
3
3
  import GptBase from "./gptbase"
4
4
  import { OpenAIApiParameters, ChatReponse, OutlineSummaryItem, SummaryReponse, FaqItem, ExaminationPaperResult, EmotionResult, SimilarityResult, QuestionItem, CommentResult, EmbeddingResult } from './declare'
5
- const SECTION_LENGTH = 1600; ///每2400个字符分成一组
5
+ const SECTION_LENGTH = 1024; ///每2400个字符分成一组
6
6
  const MESSAGE_LENGTH = 1; ///每次送8句话给openai 进行解析,送多了,会报错
7
7
  //请将答案放在最后,标记为答案:()
8
8
  const QUESTION_TEXT_MAPPING: any = {
@@ -270,8 +270,8 @@ export default class OpenAIGpt extends GptBase {
270
270
  * @param {*} axiosOption
271
271
  * @returns
272
272
  *///并在答案末尾处必须给出答案内容中的关键词
273
- async generateQuestionsFromContent(content: string, count: number = 1, axiosOption: any = {}): Promise<ChatReponse> {
274
- let arrContent = this.splitLongText(content, 300);
273
+ async generateQuestionsFromContent(content: string, count: number = 1, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ChatReponse> {
274
+ let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
275
275
  ///没20句话分为一组,适应大文件内容多次请求组合结果
276
276
  ///每一句话需要产生的题目
277
277
  let questions4EverySentense: number = count / arrContent.length; //Math.ceil(arrContent.length / 20);
@@ -279,7 +279,7 @@ export default class OpenAIGpt extends GptBase {
279
279
  while (arrContent.length > 0 && gotted < count) {
280
280
  questions4EverySentense = (count - gotted) / arrContent.length
281
281
  ////每次最多送MESSAGE_LENGTH句话给openai
282
- let subarray = arrContent.slice(0, 4);
282
+ let subarray = arrContent.slice(0, 1);
283
283
  let itemCount = Math.min(Math.ceil(subarray.length * questions4EverySentense), count - gotted);
284
284
  //subarray.push({ role: 'user', content:'请根据上述内容,给出一道提问与答案以及答案关键词,按照先问题内容,再标准答案,再关键词的顺序输出,关键词之间用、分开'})
285
285
  subarray.unshift({ role: 'system', content: `你是一位专业培训师,从以下内容中提取${itemCount}条提问及答案,并从答案内容提取出至少2个关键词,最终结果按照[{"question":"提问内容","answer":"答案内容","keywords":["关键词1","关键词2"]}]的JSON数组结构输出。` })
@@ -307,36 +307,6 @@ export default class OpenAIGpt extends GptBase {
307
307
  return { successed: true, message: faqs.slice(0, count) };
308
308
  }
309
309
 
310
- /**
311
- * 从指定的文本内容中生成相关的问答
312
- * @param {*} content
313
- * @param {*} count
314
- * @param {*} axiosOption
315
- * @returns
316
- *///并在答案末尾处必须给出答案内容中的关键词
317
- async generateQuestionsFromContent_Orgin(content: string, count: number = 1, promotion: string | null = null, sliceslength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ChatReponse> {
318
- let arrContent = this.splitLongText(content, sliceslength || 300);
319
- ///没20句话分为一组,适应大文件内容多次请求组合结果
320
- ///每一句话需要产生的题目
321
- let questions4EverySentense: number = count / arrContent.length; //Math.ceil(arrContent.length / 20);
322
- let faqs: any[] = [], gotted: number = 0;
323
- while (arrContent.length > 0 && gotted < count) {
324
- questions4EverySentense = (count - gotted) / arrContent.length
325
- ////每次最多送MESSAGE_LENGTH句话给openai
326
- let subarray = arrContent.slice(0, 4);
327
- let itemCount = Math.min(Math.ceil(subarray.length * questions4EverySentense), count - gotted);
328
- subarray.unshift({ role: 'system', content: promotion || `你是一位专业培训师,从以下内容中提取${itemCount}条提问及答案,并从答案内容提取出至少2个关键词,最终结果按照[{"question":"提问内容","answer":"答案内容","keywords":["关键词1","关键词2"]}]的JSON数组结构输出。` })
329
- let result = await this.chatRequest(subarray, { replyCounts: 1 }, axiosOption);
330
- if (result.successed && result.message) {
331
- let answer = result.message.map(i => { return i.message.content.trim().replace(/\t|\n|\v|\r|\f/g, '') })
332
- faqs = faqs.concat(answer);
333
- }
334
- ////删除已经处理的文本
335
- arrContent.splice(0, 4);
336
- }
337
- arrContent = []; /// 释放内存
338
- return { successed: true, message: faqs };
339
- }
340
310
  /**
341
311
  * 解析Faq返回的问题
342
312
  * @param {*} messages
@@ -382,8 +352,8 @@ export default class OpenAIGpt extends GptBase {
382
352
  * @param {*} axiosOption
383
353
  * @returns
384
354
  *///并在答案末尾处必须给出答案内容中的关键词
385
- async generateExaminationPaperFromContent(content: string, paperOption: any = {}, axiosOption: any = {}): Promise<ExaminationPaperResult> {
386
- let arrContent = this.splitLongText(content, 1024);
355
+ async generateExaminationPaperFromContent(content: string, paperOption: any = {}, everyContentLength: number = SECTION_LENGTH, axiosOption: any = {}): Promise<ExaminationPaperResult> {
356
+ let arrContent = this.splitLongText(content, everyContentLength || SECTION_LENGTH);
387
357
  let sectionCount: any = {
388
358
  singlechoice: (paperOption.singlechoice?.count || 0) / arrContent.length,
389
359
  multiplechoice: (paperOption.multiplechoice?.count || 0) / arrContent.length,