only_ever_generator 0.3.0 → 0.3.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.
@@ -94,11 +94,10 @@ class OnlyEverGenerator {
94
94
  }
95
95
  generateCard(prompt, additionalContent, isGapFill) {
96
96
  return __awaiter(this, void 0, void 0, function* () {
97
- let generateCards = new generate_cards_1.GenerateCards(this.openAiService);
98
- let cardResp = yield generateCards.generateCards(prompt !== null && prompt !== void 0 ? prompt : "", this.parsedContent + additionalContent, isGapFill);
97
+ let generateCardsResp = yield new generate_cards_1.GenerateCards(this.openAiService).generateCards(prompt !== null && prompt !== void 0 ? prompt : "", this.parsedContent + additionalContent, isGapFill);
99
98
  // let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
100
99
  // response['type'] = 'card_gen';
101
- return cardResp;
100
+ return generateCardsResp;
102
101
  });
103
102
  }
104
103
  generateTypology(prompt) {
@@ -40,56 +40,54 @@ class GenerateCards {
40
40
  });
41
41
  }
42
42
  parse(generatedData, isGapFill) {
43
- return __awaiter(this, void 0, void 0, function* () {
44
- try {
45
- const cardData = [];
46
- let usage_data = generatedData.metadata;
47
- const status_code = generatedData.status_code;
48
- const missing_concepts = generatedData.generated_content.missing_concepts;
49
- const missing_facts = generatedData.generated_content.missing_facts;
50
- const unparsedTestCards = generatedData.generated_content.test_cards;
51
- const type = generatedData.type;
52
- if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
53
- for (let elem of unparsedTestCards) {
54
- if (elem.type == "flash") {
55
- cardData.push(this.parseFlashCard(elem));
56
- }
57
- else if (elem.type == "mcq") {
58
- cardData.push(this.parseMcqCard(elem));
59
- }
60
- else if (elem.type == "cloze") {
61
- cardData.push(this.parseClozeCard(elem));
62
- }
63
- else if (elem.type == "match") {
64
- cardData.push(this.parseMatchCard(elem));
65
- }
43
+ try {
44
+ const cardData = [];
45
+ let usage_data = generatedData.metadata;
46
+ const status_code = generatedData.status_code;
47
+ const missing_concepts = generatedData.generated_content.missing_concepts;
48
+ const missing_facts = generatedData.generated_content.missing_facts;
49
+ const unparsedTestCards = generatedData.generated_content.test_cards;
50
+ const type = generatedData.type;
51
+ if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
52
+ for (let elem of unparsedTestCards) {
53
+ if (elem.type == "flash") {
54
+ cardData.push(this.parseFlashCard(elem));
66
55
  }
67
- }
68
- else {
69
- if (!isGapFill) {
70
- usage_data.status = "failed";
56
+ else if (elem.type == "mcq") {
57
+ cardData.push(this.parseMcqCard(elem));
58
+ }
59
+ else if (elem.type == "cloze") {
60
+ cardData.push(this.parseClozeCard(elem));
61
+ }
62
+ else if (elem.type == "match") {
63
+ cardData.push(this.parseMatchCard(elem));
71
64
  }
72
65
  }
73
- return {
74
- status_code: isGapFill ? status_code : cardData.length > 0 ? status_code : 500,
75
- metadata: usage_data,
76
- type: type,
77
- missing_concepts: missing_concepts,
78
- missing_facts: missing_facts,
79
- cards_data: cardData,
80
- };
81
66
  }
82
- catch (e) {
83
- yield new logger_1.ErrorLogger({
84
- "type": 'card_parsing',
85
- "data": e.message,
86
- }).log();
87
- return {
88
- status_code: 500,
89
- type: 'card_gen',
90
- };
67
+ else {
68
+ if (!isGapFill) {
69
+ usage_data.status = "failed";
70
+ }
91
71
  }
92
- });
72
+ return {
73
+ status_code: isGapFill ? status_code : cardData.length > 0 ? status_code : 500,
74
+ metadata: usage_data,
75
+ type: type,
76
+ missing_concepts: missing_concepts,
77
+ missing_facts: missing_facts,
78
+ cards_data: cardData,
79
+ };
80
+ }
81
+ catch (e) {
82
+ new logger_1.ErrorLogger({
83
+ "type": 'card_parsing',
84
+ "data": e.message,
85
+ }).log();
86
+ return {
87
+ status_code: 500,
88
+ type: 'card_gen',
89
+ };
90
+ }
93
91
  }
94
92
  parseFlashCard(data) {
95
93
  let displayTitle = this.generateFlashCardDisplayTitle(data.card_content.front, data.card_content.back);
@@ -5,7 +5,6 @@ function parseOpenAiSuccessResponse(responseData) {
5
5
  let choices = JSON.parse(responseData.choices[0].message.content);
6
6
  let usuage = responseData.usage;
7
7
  let createdTime = responseData.created;
8
- console.log(JSON.stringify(choices));
9
8
  return {
10
9
  'status_code': 200,
11
10
  'usage_data': usuage,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "only_ever_generator",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "start": "npm run build && nodemon dist/index.js",
@@ -122,8 +122,7 @@ export class OnlyEverGenerator {
122
122
 
123
123
 
124
124
  async generateCard(prompt: string, additionalContent: string, isGapFill: boolean) {
125
- let generateCards = new GenerateCards(this.openAiService);
126
- let cardResp = await generateCards.generateCards(
125
+ let generateCardsResp = await new GenerateCards(this.openAiService).generateCards(
127
126
  prompt ?? "",
128
127
  this.parsedContent + additionalContent,
129
128
  isGapFill
@@ -131,7 +130,7 @@ export class OnlyEverGenerator {
131
130
 
132
131
  // let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
133
132
  // response['type'] = 'card_gen';
134
- return cardResp;
133
+ return generateCardsResp;
135
134
  }
136
135
 
137
136
 
@@ -28,7 +28,7 @@ export class GenerateCards {
28
28
  }
29
29
  }
30
30
 
31
- async parse(generatedData: any, isGapFill: boolean) {
31
+ parse(generatedData: any, isGapFill: boolean) {
32
32
  try{
33
33
  const cardData = [];
34
34
  let usage_data = generatedData.metadata;
@@ -66,7 +66,7 @@ if(unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
66
66
  cards_data: cardData,
67
67
  };
68
68
  }catch (e:any){
69
- await new ErrorLogger({
69
+ new ErrorLogger({
70
70
  "type": 'card_parsing',
71
71
  "data": e.message,
72
72
  }).log();
@@ -2,7 +2,6 @@ export function parseOpenAiSuccessResponse(responseData: any){
2
2
  let choices = JSON.parse(responseData.choices[0].message.content);
3
3
  let usuage = responseData.usage;
4
4
  let createdTime = responseData.created;
5
- console.log(JSON.stringify(choices));
6
5
  return {
7
6
  'status_code': 200,
8
7
  'usage_data': usuage,