only_ever_generator 0.4.8 → 0.5.0
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/card_gen/generate_cards.js +8 -199
- package/dist/constants/source_data.js +1253 -883
- package/dist/index.js +20 -20
- package/dist/parse/parse_card/parse_cloze_card.js +86 -0
- package/dist/parse/parse_card/parse_match_card.js +59 -0
- package/dist/parse/parse_card/parse_mcq_card.js +103 -0
- package/dist/parse/parse_card_response.js +82 -272
- package/dist/parse/parse_source_content.js +19 -19
- package/dist/parse/response_format_card.js +311 -149
- package/package.json +1 -1
- package/src/card_gen/generate_cards.ts +22 -237
- package/src/constants/source_data.ts +1478 -936
- package/src/index.ts +22 -20
- package/src/parse/parse_card/parse_cloze_card.ts +90 -0
- package/src/parse/parse_card/parse_match_card.ts +59 -0
- package/src/parse/parse_card/parse_mcq_card.ts +105 -0
- package/src/parse/parse_card_response.ts +88 -282
- package/src/parse/parse_source_content.ts +23 -24
- package/src/parse/response_format_card.ts +371 -194
- package/src/utils/generate_args.ts +1 -3
|
@@ -10,7 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GenerateCards = void 0;
|
|
13
|
-
const
|
|
13
|
+
const parse_card_response_1 = require("../parse/parse_card_response");
|
|
14
14
|
class GenerateCards {
|
|
15
15
|
constructor(openAiService) {
|
|
16
16
|
this.openAiService = openAiService;
|
|
@@ -22,16 +22,16 @@ class GenerateCards {
|
|
|
22
22
|
// console.log("response to card generation ", response);
|
|
23
23
|
response["type"] = isGapFill ? "gap_fill" : "card_gen";
|
|
24
24
|
response.metadata = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
25
|
+
req_time: (_b = response.generated_at) !== null && _b !== void 0 ? _b : new Date(),
|
|
26
|
+
req_type: response.type,
|
|
27
|
+
req_tokens: (_c = response.usage_data) === null || _c === void 0 ? void 0 : _c.prompt_tokens,
|
|
28
|
+
res_tokens: (_d = response.usage_data) === null || _d === void 0 ? void 0 : _d.completion_tokens,
|
|
29
|
+
model: this.openAiService.model,
|
|
30
30
|
};
|
|
31
31
|
if (response.status_code == 200) {
|
|
32
32
|
response.metadata.status = "completed";
|
|
33
|
-
|
|
34
|
-
return
|
|
33
|
+
let parseCard = new parse_card_response_1.ParseCardResponse().parse(response, isGapFill);
|
|
34
|
+
return parseCard;
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
37
37
|
response.metadata.status = "failed";
|
|
@@ -40,196 +40,5 @@ class GenerateCards {
|
|
|
40
40
|
}
|
|
41
41
|
});
|
|
42
42
|
}
|
|
43
|
-
parse(generatedData, isGapFill, headings) {
|
|
44
|
-
let usage_data = generatedData.metadata;
|
|
45
|
-
const status_code = generatedData.status_code;
|
|
46
|
-
try {
|
|
47
|
-
const cardData = [];
|
|
48
|
-
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
49
|
-
const type = generatedData.type;
|
|
50
|
-
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
51
|
-
for (let elem of unparsedTestCards) {
|
|
52
|
-
// if(headings.includes(elem.card_reference)){
|
|
53
|
-
// }else{
|
|
54
|
-
// elem.card_reference = '';
|
|
55
|
-
// }
|
|
56
|
-
if (elem.type == "flash") {
|
|
57
|
-
cardData.push(this.parseFlashCard(elem));
|
|
58
|
-
}
|
|
59
|
-
else if (elem.type == "mcq") {
|
|
60
|
-
cardData.push(this.parseMcqCard(elem));
|
|
61
|
-
}
|
|
62
|
-
else if (elem.type == "cloze") {
|
|
63
|
-
cardData.push(this.parseClozeCard(elem));
|
|
64
|
-
}
|
|
65
|
-
else if (elem.type == "match") {
|
|
66
|
-
cardData.push(this.parseMatchCard(elem));
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
if (!isGapFill) {
|
|
72
|
-
usage_data.status = "failed";
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
return {
|
|
76
|
-
status_code: 200,
|
|
77
|
-
metadata: usage_data,
|
|
78
|
-
type: type,
|
|
79
|
-
missing_concepts: [],
|
|
80
|
-
missing_facts: [],
|
|
81
|
-
cards_data: cardData,
|
|
82
|
-
};
|
|
83
|
-
}
|
|
84
|
-
catch (e) {
|
|
85
|
-
new logger_1.ErrorLogger({
|
|
86
|
-
"type": 'card_parsing',
|
|
87
|
-
"data": e.message,
|
|
88
|
-
"response": generatedData,
|
|
89
|
-
}).log();
|
|
90
|
-
return {
|
|
91
|
-
status_code: 500,
|
|
92
|
-
metadata: usage_data,
|
|
93
|
-
type: generatedData.type,
|
|
94
|
-
};
|
|
95
|
-
// return {
|
|
96
|
-
// status_code: 500,
|
|
97
|
-
// type: 'card_gen',
|
|
98
|
-
// }
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
parseFlashCard(data) {
|
|
102
|
-
let displayTitle = this.generateFlashCardDisplayTitle(data.card_content.front, data.card_content.back);
|
|
103
|
-
let flashCardData = {
|
|
104
|
-
type: {
|
|
105
|
-
category: 'learning',
|
|
106
|
-
sub_type: data.type,
|
|
107
|
-
},
|
|
108
|
-
heading: data.card_reference,
|
|
109
|
-
displayTitle: displayTitle,
|
|
110
|
-
content: {
|
|
111
|
-
front_content: data.card_content.front,
|
|
112
|
-
back_content: data.card_content.back,
|
|
113
|
-
},
|
|
114
|
-
concepts: data.concepts,
|
|
115
|
-
facts: data.facts,
|
|
116
|
-
bloomLevel: data.bloom_level,
|
|
117
|
-
};
|
|
118
|
-
return flashCardData;
|
|
119
|
-
}
|
|
120
|
-
generateFlashCardDisplayTitle(front, back) {
|
|
121
|
-
return `${front} ---- ${back}`;
|
|
122
|
-
}
|
|
123
|
-
parseMcqCard(data) {
|
|
124
|
-
let mcqAnswers = [];
|
|
125
|
-
if (data.card_content.choices !== undefined && data.card_content.choices.length != 0) {
|
|
126
|
-
for (let choice of data.card_content.choices) {
|
|
127
|
-
let answer = {
|
|
128
|
-
answer: choice.choice,
|
|
129
|
-
is_correct: choice.is_correct,
|
|
130
|
-
};
|
|
131
|
-
mcqAnswers.push(answer);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
let displayTitle = this.generateMcqCardDisplayTitle(data.card_content.prompt, mcqAnswers);
|
|
135
|
-
let mcqCard = {
|
|
136
|
-
type: {
|
|
137
|
-
category: 'learning',
|
|
138
|
-
sub_type: data.type,
|
|
139
|
-
},
|
|
140
|
-
heading: data.card_reference,
|
|
141
|
-
displayTitle: displayTitle,
|
|
142
|
-
content: {
|
|
143
|
-
question: data.card_content.prompt,
|
|
144
|
-
answers: mcqAnswers,
|
|
145
|
-
},
|
|
146
|
-
concepts: data.concepts,
|
|
147
|
-
facts: data.facts,
|
|
148
|
-
bloomLevel: data.bloom_level,
|
|
149
|
-
};
|
|
150
|
-
return mcqCard;
|
|
151
|
-
}
|
|
152
|
-
generateMcqCardDisplayTitle(question, answers) {
|
|
153
|
-
let answersString = [];
|
|
154
|
-
if (answers.length != 0) {
|
|
155
|
-
for (let option of answers) {
|
|
156
|
-
let currentIndex = answers.indexOf(option) + 1;
|
|
157
|
-
let temp = `${currentIndex} . ${option.answer} `;
|
|
158
|
-
answersString.push(temp);
|
|
159
|
-
}
|
|
160
|
-
let resultString = answersString.join("");
|
|
161
|
-
let finalDisplayTitle = `${question} ---- ${resultString}`;
|
|
162
|
-
return finalDisplayTitle;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
return question;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
parseClozeCard(data) {
|
|
169
|
-
let displayTitle = this.generateClozeCardDisplayTitle(data.card_content.prompt, data.card_content.options);
|
|
170
|
-
let clozeCardData = {
|
|
171
|
-
type: {
|
|
172
|
-
category: 'learning',
|
|
173
|
-
sub_type: data.type,
|
|
174
|
-
},
|
|
175
|
-
heading: data.card_reference,
|
|
176
|
-
displayTitle: displayTitle,
|
|
177
|
-
content: {
|
|
178
|
-
question: data.card_content.prompt,
|
|
179
|
-
options: data.card_content.options,
|
|
180
|
-
},
|
|
181
|
-
concepts: data.concepts,
|
|
182
|
-
facts: data.facts,
|
|
183
|
-
bloomLevel: data.bloom_level,
|
|
184
|
-
};
|
|
185
|
-
return clozeCardData;
|
|
186
|
-
}
|
|
187
|
-
generateClozeCardDisplayTitle(question, answers) {
|
|
188
|
-
let optionsString = '';
|
|
189
|
-
if (answers.length !== 0) {
|
|
190
|
-
optionsString = answers
|
|
191
|
-
.map((item) => {
|
|
192
|
-
if (item.option !== undefined) {
|
|
193
|
-
return item.option;
|
|
194
|
-
}
|
|
195
|
-
else {
|
|
196
|
-
return '';
|
|
197
|
-
}
|
|
198
|
-
})
|
|
199
|
-
.join(", ");
|
|
200
|
-
}
|
|
201
|
-
return `${question} ---- ${optionsString}`;
|
|
202
|
-
}
|
|
203
|
-
parseMatchCard(cardData) {
|
|
204
|
-
let content = cardData.card_content;
|
|
205
|
-
let displayTitle = this.generateMatchCardDisplayTitle(content);
|
|
206
|
-
let matchCard = {
|
|
207
|
-
type: {
|
|
208
|
-
category: 'learning',
|
|
209
|
-
sub_type: cardData.type,
|
|
210
|
-
},
|
|
211
|
-
heading: cardData.card_reference,
|
|
212
|
-
content: content,
|
|
213
|
-
// content: cardData.card_content,
|
|
214
|
-
displayTitle: displayTitle,
|
|
215
|
-
concepts: cardData.concepts,
|
|
216
|
-
facts: cardData.facts,
|
|
217
|
-
bloomLevel: cardData.bloom_level,
|
|
218
|
-
};
|
|
219
|
-
return matchCard;
|
|
220
|
-
}
|
|
221
|
-
generateMatchCardDisplayTitle(answers) {
|
|
222
|
-
let titles = [];
|
|
223
|
-
let counter = 65;
|
|
224
|
-
for (let data of answers) {
|
|
225
|
-
let value = data.right_item.join(',');
|
|
226
|
-
let leftData = data.left_item;
|
|
227
|
-
let letter = String.fromCharCode(counter);
|
|
228
|
-
titles.push(`${letter}. ${leftData} -- ${value}`);
|
|
229
|
-
counter++;
|
|
230
|
-
}
|
|
231
|
-
let displayTitle = titles.join(",");
|
|
232
|
-
return displayTitle;
|
|
233
|
-
}
|
|
234
43
|
}
|
|
235
44
|
exports.GenerateCards = GenerateCards;
|