only_ever_generator 0.4.9 → 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.
@@ -1,290 +1,96 @@
1
- const cardResponse = {
2
- "status_code": 200,
3
- "usage_data": {
4
- "prompt_tokens": 9781,
5
- "completion_tokens": 1915,
6
- "total_tokens": 11696
7
- },
8
- "generated_content": {
9
- "missing_concepts": [
10
- "Faraday's laws of electrolysis",
11
- "Humphry Davy",
12
- "Electrolytic cell",
13
- "Decomposition potential",
14
- "Oxidation",
15
- "Reduction",
16
- "Electrolysis of seawater",
17
- "Electrometallurgy",
18
- "Electroplating",
19
- "Electrochemical machining",
20
- "Electrochemistry",
21
- "Electrocatalysis",
22
- "Electrorefining",
23
- "Electrolysis of carbon dioxide",
24
- "Energy changes during electrolysis",
25
- "Electrocrystallization",
26
- "Electrolysis of Iron Ore"
27
- ],
28
- "missing_facts": [
29
- "Michael Faraday introduced the term 'electrolysis' in 1834",
30
- "The first demonstration of key electrolysis concepts was by William Nicholson and Anthony Carlisle in the early nineteenth century",
31
- "Humphry Davy discovered several alkali and alkaline earth metals by electrolysis",
32
- "Electrolysis played a key role in isolating and identifying new elements like lithium, chlorine, and fluorine",
33
- "The Hall–Héroult process led to a significant drop in the price of aluminum",
34
- "Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water",
35
- "The electrolysis of seawater can result in the production of alkali hydroxides",
36
- "Electrometallurgy is used in the production of various metals",
37
- "Electroplating involves the deposition of a thin metal film onto a substrate material",
38
- "Electrochemical machining is used for deburring or etching metal surfaces",
39
- "Electrocatalysis involves the acceleration of electrochemical reactions",
40
- "Electrorefining is used to obtain pure metals from impure ones",
41
- "The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
42
- "Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses",
43
- "Electrocrystallization is a method for obtaining conductive crystals using electrolysis",
44
- "Electrolysis of Iron Ore can eventually result in the reduction of emissions from steel production"
45
- ],
46
- "test_cards": [
47
- {
48
- "type": "flash",
49
- "card_content": {
50
- "front": "Who introduced the term 'electrolysis' and in which year?",
51
- "back": "Michael Faraday introduced the term 'electrolysis' in 1834"
52
- },
53
- "card_reference": "Electrolysis#Etymology",
54
- "concepts": [],
55
- "facts": [
56
- "Michael Faraday introduced the term 'electrolysis' in 1834"
57
- ]
58
- },
59
- {
60
- "type": "flash",
61
- "card_content": {
62
- "front": "What was the significance of the Hall–Héroult process?",
63
- "back": "The Hall–Héroult process led to a significant drop in the price of aluminum"
64
- },
65
- "card_reference": "Electrolysis#Industrial uses",
66
- "concepts": [
67
- "Hall–Héroult process"
68
- ],
69
- "facts": [
70
- "The Hall–Héroult process led to a significant drop in the price of aluminum"
71
- ]
72
- },
73
- {
74
- "type": "mcq",
75
- "card_content": {
76
- "prompt": "What does the electrolysis of water produce?",
77
- "choices": [
78
- {
79
- "choice": "Oxygen and carbon dioxide",
80
- "is_correct": false
81
- },
82
- {
83
- "choice": "Hydrogen and oxygen",
84
- "is_correct": true
85
- },
86
- {
87
- "choice": "Nitrogen and helium",
88
- "is_correct": false
89
- }
90
- ]
91
- },
92
- "card_reference": "Electrolysis#Process of electrolysis",
93
- "concepts": [
94
- "Electrometallurgy"
95
- ],
96
- "facts": [
97
- "Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water"
98
- ]
99
- },
100
- {
101
- "type": "cloze",
102
- "card_content": {
103
- "prompt": "Electrolysis is the passing of a direct electric current through an {{c0:electrolyte}} producing chemical reactions at the electrodes and decomposition of the materials.",
104
- "options": [
105
- {
106
- "option": "electrolyte",
107
- "cloze": "c0"
108
- },
109
- {
110
- "option": "anode",
111
- "cloze": "null"
112
- },
113
- {
114
- "option": "cathode",
115
- "cloze": "null"
116
- }
117
- ]
118
- },
119
- "card_reference": "Electrolysis#Overview",
120
- "concepts": [],
121
- "facts": []
122
- },
123
- {
124
- "type": "match",
125
- "card_content": {
126
- "right_choice 1": "Electrometallurgy",
127
- "right_choice 2": "Electroplating",
128
- "right_choice 3": "Electrochemical machining",
129
- "right_choice 4": "Electrochemistry",
130
- "right_choice 5": "Electrocatalysis",
131
- "right_choice 6": "Electrorefining",
132
- "right_choice 7": "Electrolysis of carbon dioxide",
133
- "right_choice 8": "Energy changes during electrolysis",
134
- "Electrometallurgy": "The process of producing metals using electricity",
135
- "Electroplating": "Deposition of thin metal film onto a substrate material",
136
- "Electrochemical machining": "Deburring or etching metal surfaces",
137
- "Electrochemistry": "Study of the interchange of chemical and electrical energy",
138
- "Electrocatalysis": "Acceleration of electrochemical reactions",
139
- "Electrorefining": "Obtaining pure metals from impure ones"
140
- },
141
- "card_reference": "Electrolysis#Industrial uses",
142
- "concepts": [
143
- "Electrometallurgy",
144
- "Electroplating",
145
- "Electrochemical machining",
146
- "Electrochemistry",
147
- "Electrocatalysis",
148
- "Electrorefining",
149
- "Electrolysis of carbon dioxide",
150
- "Energy changes during electrolysis"
151
- ],
152
- "facts": [
153
- "Electrometallurgy is used in the production of various metals",
154
- "Electroplating involves the deposition of a thin metal film onto a substrate material",
155
- "Electrochemical machining is used for deburring or etching metal surfaces",
156
- "Electrochemistry is the study of the interchange of chemical and electrical energy",
157
- "Electrocatalysis involves the acceleration of electrochemical reactions",
158
- "Electrorefining is used to obtain pure metals from impure ones",
159
- "The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
160
- "Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses"
161
- ]
162
- },
163
- {
164
- "type": "mcq",
165
- "card_content": {
166
- "prompt": "What is a key application of electrolysis?",
167
- "choices": [
168
- {
169
- "choice": "Production of metal from ore",
170
- "is_correct": false
171
- },
172
- {
173
- "choice": "Pulsing current results",
174
- "is_correct": false
175
- },
176
- {
177
- "choice": "Generating electrical potential",
178
- "is_correct": false
179
- },
180
- {
181
- "choice": "Production of chlorine and sodium hydroxide",
182
- "is_correct": true
183
- }
184
- ]
185
- },
186
- "card_reference": "Electrolysis#Industrial uses",
187
- "concepts": [
188
- "Electrochemistry",
189
- "Electrocatalysis",
190
- "Electrorefining"
191
- ],
192
- "facts": [
193
- "Production of chlorine and sodium hydroxide, called the Chloralkali process"
194
- ]
195
- },
196
- {
197
- "type": "cloze",
198
- "card_content": {
199
- "prompt": "Oxidation of ions or neutral molecules occurs at the {{c0:anode}}. Reduction of ions or neutral molecules occurs at the {{c1:cathode}}.",
200
- "options": [
201
- {
202
- "option": "anode",
203
- "cloze": "c0"
204
- },
205
- {
206
- "option": "cathode",
207
- "cloze": "c1"
208
- },
209
- {
210
- "option": "electrolyte",
211
- "cloze": "null"
212
- }
213
- ]
214
- },
215
- "card_reference": "Electrolysis#Oxidation and reduction at the electrodes",
216
- "concepts": [
217
- "Oxidation",
218
- "Reduction"
219
- ],
220
- "facts": []
221
- },
222
- {
223
- "type": "match",
224
- "card_content": {
225
- "right_choice 1": "Electrolysis",
226
- "right_choice 2": "Electrocrystallization",
227
- "right_choice 3": "Electrolysis of Iron Ore",
228
- "right_choice 4": "Electrolysis of seawater",
229
- "right_choice 5": "Electrometallurgy"
230
- },
231
- "card_reference": "Electrolysis#Research trends",
232
- "concepts": [
233
- "Electrolysis",
234
- "Electrocrystallization",
235
- "Electrolysis of Iron Ore",
236
- "Electrolysis of seawater",
237
- "Electrometallurgy"
238
- ],
239
- "facts": []
240
- }
241
- ]
242
- },
243
- "generated_at": 1718625081,
244
- "type": "card_gen"
245
- };
246
-
247
- export class ParseCardResponse{
248
- public generatedData: any;
249
- constructor(generatedData: any){
250
- this.generatedData = generatedData;
251
- }
252
-
253
- parse(){
254
- const cardData = [];
255
- const usage_data = this.generatedData.usage_data;
256
- const created_at = this.generatedData.created_at;
257
- const unparsedTestCards = this.generatedData.test_cards;
1
+ import { ErrorLogger } from "../logger";
2
+ import { ParseClozeCard } from "./parse_card/parse_cloze_card";
3
+ import { ParseMatchCard } from "./parse_card/parse_match_card";
4
+ import { ParseMcqCard } from "./parse_card/parse_mcq_card";
258
5
 
259
- for(let elem of unparsedTestCards){
260
- if(elem.type == 'flash'){
261
- cardData.push(this.parseFlashCard(elem));
262
- } else if(elem.type == 'mcq'){
263
- cardData.push(this.parseFlashCard(elem));
264
- }else if(elem.type =='cloze'){
265
- cardData.push(this.parseClozeCard(elem));
266
- }else if(elem.type =='match'){
267
- cardData.push(this.parseMatchCard(elem));
6
+ export class ParseCardResponse {
7
+ parse(generatedData: any, isGapFill: boolean) {
8
+ let usage_data = generatedData.metadata;
9
+ try {
10
+ const cardData = [];
11
+ const unparsedTestCards = generatedData.generated_content.test_cards;
12
+ const type = generatedData.type;
13
+ if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
14
+ for (let elem of unparsedTestCards) {
15
+ if (elem.type == "flash") {
16
+ const flashCard = this.parseFlashCard(elem);
17
+ if (flashCard != null && flashCard) {
18
+ this.parseFlashCard(flashCard);
268
19
  }
20
+ } else if (elem.type == "mcq") {
21
+ const mcqCard = new ParseMcqCard().parse(elem);
22
+ if (mcqCard != null && mcqCard) {
23
+ cardData.push(mcqCard);
24
+ }
25
+ } else if (elem.type == "cloze") {
26
+ const clozeCard = new ParseClozeCard().parse(elem);
27
+ if (clozeCard && clozeCard != null) {
28
+ cardData.push(clozeCard);
29
+ }
30
+ } else if (elem.type == "match") {
31
+ const matchCard = new ParseMatchCard().parse(elem);
32
+ if (matchCard && matchCard != null) {
33
+ cardData.push(matchCard);
34
+ }
35
+ }
269
36
  }
270
- usage_data['created_at'] = created_at;
271
- usage_data['type']= 'card_gen';
272
- return {
273
- 'usage_data': usage_data,
274
- 'cards_data': cardData
37
+ } else {
38
+ if (!isGapFill) {
39
+ usage_data.status = "failed";
275
40
  }
41
+ }
42
+
43
+ return {
44
+ status_code: 200,
45
+ metadata: usage_data,
46
+ type: type,
47
+ missing_concepts: [],
48
+ missing_facts: [],
49
+ cards_data: cardData,
50
+ };
51
+ } catch (e: any) {
52
+ new ErrorLogger({
53
+ type: "card_parsing",
54
+ data: e.message,
55
+ response: generatedData,
56
+ }).log();
57
+ return {
58
+ status_code: 500,
59
+ metadata: usage_data,
60
+ type: generatedData.type,
61
+ };
276
62
  }
63
+ }
277
64
 
278
- parseFlashCard(data:any){
65
+ parseFlashCard(data: any) {
66
+ try {
67
+ let displayTitle = this.generateFlashCardDisplayTitle(
68
+ data.card_content.front,
69
+ data.card_content.back
70
+ );
71
+ let flashCardData = {
72
+ type: {
73
+ category: "learning",
74
+ sub_type: data.type,
75
+ },
76
+ heading: data.card_reference,
77
+ displayTitle: displayTitle,
78
+ content: {
79
+ front_content: data.card_content.front,
80
+ back_content: data.card_content.back,
81
+ },
82
+ concepts: data.concepts,
83
+ facts: data.facts,
84
+ bloomLevel: data.bloom_level,
85
+ };
279
86
 
87
+ return flashCardData;
88
+ } catch (e) {
89
+ return null;
280
90
  }
281
- parseMcqCard(data:any){
282
-
283
- }
284
- parseClozeCard(data:any){
285
-
286
- }
287
- parseMatchCard(data:any){
288
-
289
- }
290
- }
91
+ }
92
+
93
+ generateFlashCardDisplayTitle(front: string, back: string) {
94
+ return `${front} ---- ${back}`;
95
+ }
96
+ }