only_ever_generator 0.2.7 → 0.2.8

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.
Files changed (32) hide show
  1. package/dist/card_gen/generate_cards.js +1 -0
  2. package/dist/constants/prompt_data.js +273 -273
  3. package/dist/constants/prompts/card_gen_prompt.js +180 -180
  4. package/dist/constants/prompts/typology_prompt.js +93 -93
  5. package/package.json +33 -33
  6. package/readme.md +23 -23
  7. package/src/bootstrap/app.ts +150 -154
  8. package/src/card_gen/generate_cards.ts +251 -251
  9. package/src/config.ts +6 -6
  10. package/src/constants/api_constants.ts +2 -2
  11. package/src/constants/prompt_data.ts +296 -296
  12. package/src/constants/prompts/card_gen_prompt.ts +372 -372
  13. package/src/constants/prompts/typology_prompt.ts +202 -202
  14. package/src/constants/source_data.ts +47 -47
  15. package/src/gap_fill/calculate_gap_fill.ts +52 -52
  16. package/src/index.ts +61 -61
  17. package/src/logger.ts +30 -30
  18. package/src/parse/parse_card_response.ts +289 -289
  19. package/src/parse/parse_source_content.ts +94 -94
  20. package/src/parse/response_format_card.ts +210 -210
  21. package/src/parse/response_format_typology.ts +43 -43
  22. package/src/services/open_ai_service.ts +55 -55
  23. package/src/typology_gen/generate_typology.ts +71 -71
  24. package/src/utils/generate_args.ts +28 -28
  25. package/src/utils/parse_openai_response.ts +20 -20
  26. package/tsconfig.json +12 -12
  27. package/dist/class/parse/parse_source_content.js +0 -62
  28. package/dist/class/services/open_ai_service.js +0 -25
  29. package/dist/parse_response/parse_card_response.js +0 -288
  30. package/dist/parse_response/response_format_card.js +0 -210
  31. package/dist/parse_response/response_format_typology.js +0 -47
  32. package/dist/service/open_ai_request.js +0 -57
@@ -1,288 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ParseCardResponse = void 0;
4
- const cardResponse = {
5
- "status_code": 200,
6
- "usage_data": {
7
- "prompt_tokens": 9781,
8
- "completion_tokens": 1915,
9
- "total_tokens": 11696
10
- },
11
- "generated_content": {
12
- "missing_concepts": [
13
- "Faraday's laws of electrolysis",
14
- "Humphry Davy",
15
- "Electrolytic cell",
16
- "Decomposition potential",
17
- "Oxidation",
18
- "Reduction",
19
- "Electrolysis of seawater",
20
- "Electrometallurgy",
21
- "Electroplating",
22
- "Electrochemical machining",
23
- "Electrochemistry",
24
- "Electrocatalysis",
25
- "Electrorefining",
26
- "Electrolysis of carbon dioxide",
27
- "Energy changes during electrolysis",
28
- "Electrocrystallization",
29
- "Electrolysis of Iron Ore"
30
- ],
31
- "missing_facts": [
32
- "Michael Faraday introduced the term 'electrolysis' in 1834",
33
- "The first demonstration of key electrolysis concepts was by William Nicholson and Anthony Carlisle in the early nineteenth century",
34
- "Humphry Davy discovered several alkali and alkaline earth metals by electrolysis",
35
- "Electrolysis played a key role in isolating and identifying new elements like lithium, chlorine, and fluorine",
36
- "The Hall–Héroult process led to a significant drop in the price of aluminum",
37
- "Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water",
38
- "The electrolysis of seawater can result in the production of alkali hydroxides",
39
- "Electrometallurgy is used in the production of various metals",
40
- "Electroplating involves the deposition of a thin metal film onto a substrate material",
41
- "Electrochemical machining is used for deburring or etching metal surfaces",
42
- "Electrocatalysis involves the acceleration of electrochemical reactions",
43
- "Electrorefining is used to obtain pure metals from impure ones",
44
- "The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
45
- "Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses",
46
- "Electrocrystallization is a method for obtaining conductive crystals using electrolysis",
47
- "Electrolysis of Iron Ore can eventually result in the reduction of emissions from steel production"
48
- ],
49
- "test_cards": [
50
- {
51
- "type": "flash",
52
- "card_content": {
53
- "front": "Who introduced the term 'electrolysis' and in which year?",
54
- "back": "Michael Faraday introduced the term 'electrolysis' in 1834"
55
- },
56
- "card_reference": "Electrolysis#Etymology",
57
- "concepts": [],
58
- "facts": [
59
- "Michael Faraday introduced the term 'electrolysis' in 1834"
60
- ]
61
- },
62
- {
63
- "type": "flash",
64
- "card_content": {
65
- "front": "What was the significance of the Hall–Héroult process?",
66
- "back": "The Hall–Héroult process led to a significant drop in the price of aluminum"
67
- },
68
- "card_reference": "Electrolysis#Industrial uses",
69
- "concepts": [
70
- "Hall–Héroult process"
71
- ],
72
- "facts": [
73
- "The Hall–Héroult process led to a significant drop in the price of aluminum"
74
- ]
75
- },
76
- {
77
- "type": "mcq",
78
- "card_content": {
79
- "prompt": "What does the electrolysis of water produce?",
80
- "choices": [
81
- {
82
- "choice": "Oxygen and carbon dioxide",
83
- "is_correct": false
84
- },
85
- {
86
- "choice": "Hydrogen and oxygen",
87
- "is_correct": true
88
- },
89
- {
90
- "choice": "Nitrogen and helium",
91
- "is_correct": false
92
- }
93
- ]
94
- },
95
- "card_reference": "Electrolysis#Process of electrolysis",
96
- "concepts": [
97
- "Electrometallurgy"
98
- ],
99
- "facts": [
100
- "Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water"
101
- ]
102
- },
103
- {
104
- "type": "cloze",
105
- "card_content": {
106
- "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.",
107
- "options": [
108
- {
109
- "option": "electrolyte",
110
- "cloze": "c0"
111
- },
112
- {
113
- "option": "anode",
114
- "cloze": "null"
115
- },
116
- {
117
- "option": "cathode",
118
- "cloze": "null"
119
- }
120
- ]
121
- },
122
- "card_reference": "Electrolysis#Overview",
123
- "concepts": [],
124
- "facts": []
125
- },
126
- {
127
- "type": "match",
128
- "card_content": {
129
- "right_choice 1": "Electrometallurgy",
130
- "right_choice 2": "Electroplating",
131
- "right_choice 3": "Electrochemical machining",
132
- "right_choice 4": "Electrochemistry",
133
- "right_choice 5": "Electrocatalysis",
134
- "right_choice 6": "Electrorefining",
135
- "right_choice 7": "Electrolysis of carbon dioxide",
136
- "right_choice 8": "Energy changes during electrolysis",
137
- "Electrometallurgy": "The process of producing metals using electricity",
138
- "Electroplating": "Deposition of thin metal film onto a substrate material",
139
- "Electrochemical machining": "Deburring or etching metal surfaces",
140
- "Electrochemistry": "Study of the interchange of chemical and electrical energy",
141
- "Electrocatalysis": "Acceleration of electrochemical reactions",
142
- "Electrorefining": "Obtaining pure metals from impure ones"
143
- },
144
- "card_reference": "Electrolysis#Industrial uses",
145
- "concepts": [
146
- "Electrometallurgy",
147
- "Electroplating",
148
- "Electrochemical machining",
149
- "Electrochemistry",
150
- "Electrocatalysis",
151
- "Electrorefining",
152
- "Electrolysis of carbon dioxide",
153
- "Energy changes during electrolysis"
154
- ],
155
- "facts": [
156
- "Electrometallurgy is used in the production of various metals",
157
- "Electroplating involves the deposition of a thin metal film onto a substrate material",
158
- "Electrochemical machining is used for deburring or etching metal surfaces",
159
- "Electrochemistry is the study of the interchange of chemical and electrical energy",
160
- "Electrocatalysis involves the acceleration of electrochemical reactions",
161
- "Electrorefining is used to obtain pure metals from impure ones",
162
- "The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
163
- "Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses"
164
- ]
165
- },
166
- {
167
- "type": "mcq",
168
- "card_content": {
169
- "prompt": "What is a key application of electrolysis?",
170
- "choices": [
171
- {
172
- "choice": "Production of metal from ore",
173
- "is_correct": false
174
- },
175
- {
176
- "choice": "Pulsing current results",
177
- "is_correct": false
178
- },
179
- {
180
- "choice": "Generating electrical potential",
181
- "is_correct": false
182
- },
183
- {
184
- "choice": "Production of chlorine and sodium hydroxide",
185
- "is_correct": true
186
- }
187
- ]
188
- },
189
- "card_reference": "Electrolysis#Industrial uses",
190
- "concepts": [
191
- "Electrochemistry",
192
- "Electrocatalysis",
193
- "Electrorefining"
194
- ],
195
- "facts": [
196
- "Production of chlorine and sodium hydroxide, called the Chloralkali process"
197
- ]
198
- },
199
- {
200
- "type": "cloze",
201
- "card_content": {
202
- "prompt": "Oxidation of ions or neutral molecules occurs at the {{c0:anode}}. Reduction of ions or neutral molecules occurs at the {{c1:cathode}}.",
203
- "options": [
204
- {
205
- "option": "anode",
206
- "cloze": "c0"
207
- },
208
- {
209
- "option": "cathode",
210
- "cloze": "c1"
211
- },
212
- {
213
- "option": "electrolyte",
214
- "cloze": "null"
215
- }
216
- ]
217
- },
218
- "card_reference": "Electrolysis#Oxidation and reduction at the electrodes",
219
- "concepts": [
220
- "Oxidation",
221
- "Reduction"
222
- ],
223
- "facts": []
224
- },
225
- {
226
- "type": "match",
227
- "card_content": {
228
- "right_choice 1": "Electrolysis",
229
- "right_choice 2": "Electrocrystallization",
230
- "right_choice 3": "Electrolysis of Iron Ore",
231
- "right_choice 4": "Electrolysis of seawater",
232
- "right_choice 5": "Electrometallurgy"
233
- },
234
- "card_reference": "Electrolysis#Research trends",
235
- "concepts": [
236
- "Electrolysis",
237
- "Electrocrystallization",
238
- "Electrolysis of Iron Ore",
239
- "Electrolysis of seawater",
240
- "Electrometallurgy"
241
- ],
242
- "facts": []
243
- }
244
- ]
245
- },
246
- "generated_at": 1718625081,
247
- "type": "card_gen"
248
- };
249
- class ParseCardResponse {
250
- constructor(generatedData) {
251
- this.generatedData = generatedData;
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;
258
- for (let elem of unparsedTestCards) {
259
- if (elem.type == 'flash') {
260
- cardData.push(this.parseFlashCard(elem));
261
- }
262
- else if (elem.type == 'mcq') {
263
- cardData.push(this.parseFlashCard(elem));
264
- }
265
- else if (elem.type == 'cloze') {
266
- cardData.push(this.parseClozeCard(elem));
267
- }
268
- else if (elem.type == 'match') {
269
- cardData.push(this.parseMatchCard(elem));
270
- }
271
- }
272
- usage_data['created_at'] = created_at;
273
- usage_data['type'] = 'card_gen';
274
- return {
275
- 'usage_data': usage_data,
276
- 'cards_data': cardData
277
- };
278
- }
279
- parseFlashCard(data) {
280
- }
281
- parseMcqCard(data) {
282
- }
283
- parseClozeCard(data) {
284
- }
285
- parseMatchCard(data) {
286
- }
287
- }
288
- exports.ParseCardResponse = ParseCardResponse;
@@ -1,210 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseResponse = exports.returnResponse = void 0;
4
- const responseData = {
5
- "flash_cards": [
6
- {
7
- "question": "What is the primary function of the 'Electrolysis'?",
8
- "answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
9
- "heading": "Overview"
10
- },
11
- {
12
- "question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
13
- "answer": "Michael Faraday discovered two laws of electrolysis.",
14
- "heading": "History"
15
- },
16
- {
17
- "question": "What can electrolysis be used for in the manufacturing sector?",
18
- "answer": "Electrolysis can be used for electroplating and electrochemical machining.",
19
- "heading": "Manufacturing processes"
20
- },
21
- {
22
- "question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
23
- "answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
24
- "heading": "Decomposition potential"
25
- }
26
- ],
27
- "mcqs": [
28
- {
29
- "question": "What is the primary purpose of 'Electrometallurgy'?",
30
- "answers": [
31
- {
32
- "answer": "Production of aluminium",
33
- "is_correct": true
34
- },
35
- {
36
- "answer": "Chlorine production",
37
- "is_correct": false
38
- },
39
- {
40
- "answer": "Purifying copper",
41
- "is_correct": false
42
- },
43
- {
44
- "answer": "Rust removal",
45
- "is_correct": false
46
- },
47
- {
48
- "answer": "Hydrogen production",
49
- "is_correct": false
50
- }
51
- ],
52
- "heading": "Industrial uses"
53
- },
54
- {
55
- "question": "What can electrolysis be used for in the context of batteries?",
56
- "answers": [
57
- {
58
- "answer": "Spontaneous redox reactions",
59
- "is_correct": true
60
- },
61
- {
62
- "answer": "Energy-releasing reactions",
63
- "is_correct": false
64
- },
65
- {
66
- "answer": "Disinfectant production",
67
- "is_correct": false
68
- },
69
- {
70
- "answer": "Fuel production",
71
- "is_correct": false
72
- },
73
- {
74
- "answer": "Gas diffusion in reactors",
75
- "is_correct": false
76
- }
77
- ],
78
- "heading": "Related processes"
79
- }
80
- ],
81
- "cloze_cards": [
82
- {
83
- "question": "Electrolysis is the passing of a {{c0:direct electric current}} through an {{c1:electrolyte}} producing {{c2:chemical reactions}} at the {{c3:electrodes}} and {{c4:decomposition}} of the materials.",
84
- "options": [
85
- {
86
- "option": "direct electric current",
87
- "cloze": "c0"
88
- },
89
- {
90
- "option": "electrolyte",
91
- "cloze": "c1"
92
- },
93
- {
94
- "option": "chemical reactions",
95
- "cloze": "c2"
96
- },
97
- {
98
- "option": "electrodes",
99
- "cloze": "c3"
100
- },
101
- {
102
- "option": "decomposition",
103
- "cloze": "c4"
104
- },
105
- {
106
- "option": "metallic objects",
107
- "cloze": null
108
- }
109
- ]
110
- },
111
- {
112
- "question": "In electrolysis, the decomposition potential or decomposition voltage refers to the minimum voltage between {{c0:anode}} and {{c1:cathode}} of an electrolytic cell needed for electrolysis to occur.",
113
- "options": [
114
- {
115
- "option": "anode",
116
- "cloze": "c0"
117
- },
118
- {
119
- "option": "cathode",
120
- "cloze": "c1"
121
- },
122
- {
123
- "option": "electrolyte",
124
- "cloze": null
125
- },
126
- {
127
- "option": "chemical reactions",
128
- "cloze": null
129
- },
130
- {
131
- "option": "oxygen",
132
- "cloze": null
133
- },
134
- {
135
- "option": "hydrogen",
136
- "cloze": null
137
- }
138
- ]
139
- }
140
- ]
141
- };
142
- function returnResponse() {
143
- return responseData;
144
- }
145
- exports.returnResponse = returnResponse;
146
- function parseResponse() {
147
- let cardData = [];
148
- let data = returnResponse();
149
- let keys = Object.keys(data);
150
- if (keys) {
151
- for (let elem of keys) {
152
- if (elem == 'flash_cards') {
153
- cardData.push(...parseFlashCard(data.flash_cards));
154
- }
155
- else if (elem == 'cloze_cards') {
156
- cardData.push(...parseClozeCards(data.cloze_cards));
157
- }
158
- else if (elem == 'mcqs') {
159
- cardData.push(...parseMcq(data.mcqs));
160
- }
161
- }
162
- }
163
- return cardData;
164
- }
165
- exports.parseResponse = parseResponse;
166
- /// takes array of
167
- function parseFlashCard(cards) {
168
- let flashCardData = [];
169
- for (let elem of cards) {
170
- flashCardData.push({
171
- "type": "flash",
172
- "heading": elem.heading,
173
- "content": JSON.stringify({
174
- "front_content": elem.question,
175
- "back_content": elem.answer
176
- })
177
- });
178
- }
179
- return flashCardData;
180
- }
181
- /// takes array of
182
- function parseMcq(cardsData) {
183
- let mcqCards = [];
184
- for (let elem of cardsData) {
185
- mcqCards.push({
186
- "type": "mcq",
187
- "heading": elem.heading,
188
- "content": JSON.stringify({
189
- "question": elem.question,
190
- "answers": elem.answers
191
- })
192
- });
193
- }
194
- return mcqCards;
195
- }
196
- /// takes array of
197
- function parseClozeCards(cardsData) {
198
- let clozeCards = [];
199
- for (let elem of cardsData) {
200
- clozeCards.push({
201
- "type": "cloze",
202
- "heading": elem.heading,
203
- "content": JSON.stringify({
204
- "question": elem.question,
205
- "options": elem.options
206
- })
207
- });
208
- }
209
- return clozeCards;
210
- }
@@ -1,47 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.returnTypologyData = void 0;
4
- const typologyResponse = {
5
- "usage_data": {
6
- "prompt_tokens": 11611,
7
- "completion_tokens": 441,
8
- "total_tokens": 12052
9
- },
10
- "generated_content": {
11
- "field": [
12
- "Sciences",
13
- "Technology & Engineering",
14
- "Education, Learning & Personal Development"
15
- ],
16
- "concepts": [
17
- "Electrolysis",
18
- "Faraday's Laws of Electrolysis",
19
- "Electrolytic Cell",
20
- "Decomposition Potential",
21
- "Oxidation and Reduction at the Electrodes",
22
- "Electrolysis of Water",
23
- "Electrolysis of Carbon Dioxide",
24
- "Electrocrystallization"
25
- ],
26
- "facts": [
27
- "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
28
- "In electrolysis, the quantity of the products is proportional to the current, and when two or more electrolytic cells are connected in series to the same power source, the products produced in the cells are proportional to their equivalent weight.",
29
- "The main components required to achieve electrolysis are an electrolyte, electrodes, and an external power source.",
30
- "Faraday's laws of electrolysis detail the amount of the products of electrolysis is related to the number of electrons in the reaction at the electrodes.",
31
- "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell that is needed for electrolysis to occur.",
32
- "The electrochemical reduction of carbon dioxide can produce value-added chemicals such as methane, ethylene, and ethanol."
33
- ],
34
- "generate_cards": true,
35
- "summary_cards": [
36
- "Electrolysis is the process of passing direct electric current through an electrolyte, resulting in chemical reactions and the decomposition of materials.",
37
- "Faraday's laws of electrolysis determine the relationship between the amounts of products generated and the electrons involved in the reaction at the electrodes.",
38
- "Decomposition potential is the minimum voltage required between anode and cathode for electrolysis to occur.",
39
- "The electrochemical reduction of carbon dioxide is a potential method for producing valuable chemicals such as methane, ethylene, and ethanol."
40
- ]
41
- },
42
- "generated_at": "Tue, 20 Jan 1970 21:17:46 GMT"
43
- };
44
- function returnTypologyData() {
45
- return typologyResponse;
46
- }
47
- exports.returnTypologyData = returnTypologyData;
@@ -1,57 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
- Object.defineProperty(exports, "__esModule", { value: true });
15
- exports.openAIRequest = void 0;
16
- const axios_1 = __importDefault(require("axios"));
17
- const parse_openai_response_js_1 = require("../utils/parse_openai_response.js");
18
- function openAIRequest(content, prompt, token, model) {
19
- return __awaiter(this, void 0, void 0, function* () {
20
- try {
21
- let message = [
22
- {
23
- "role": "system", "content": prompt
24
- }, {
25
- "role": "user", "content": content
26
- }
27
- ];
28
- const url = 'https://api.openai.com/v1/chat/completions';
29
- let response = yield axios_1.default.post(url,
30
- //data
31
- {
32
- "model": model,
33
- "messages": message,
34
- "response_format": { "type": "json_object" },
35
- },
36
- ///config
37
- {
38
- headers: {
39
- Authorization: "Bearer " + token,
40
- "Content-Type": ['application/json']
41
- },
42
- });
43
- if (response.status == 200) {
44
- console.log('success');
45
- return (0, parse_openai_response_js_1.parseOpenAiSuccessResponse)(response.data);
46
- }
47
- else {
48
- console.log('failed');
49
- return response.statusText;
50
- }
51
- }
52
- catch (err) {
53
- return (0, parse_openai_response_js_1.parseOpenAiFailureResponse)(err.response);
54
- }
55
- });
56
- }
57
- exports.openAIRequest = openAIRequest;