only_ever_generator 0.2.7 → 0.2.9

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 (36) hide show
  1. package/dist/bootstrap/app.js +1 -1
  2. package/dist/card_gen/generate_cards.js +2 -1
  3. package/dist/constants/prompt_data.js +273 -273
  4. package/dist/constants/prompts/card_gen_prompt.js +287 -282
  5. package/dist/constants/prompts/typology_prompt.js +94 -100
  6. package/dist/constants/source_data.js +883 -7
  7. package/dist/index.js +1 -1
  8. package/dist/parse/parse_source_content.js +0 -7
  9. package/package.json +33 -33
  10. package/readme.md +23 -23
  11. package/src/bootstrap/app.ts +150 -154
  12. package/src/card_gen/generate_cards.ts +251 -251
  13. package/src/config.ts +6 -6
  14. package/src/constants/api_constants.ts +2 -2
  15. package/src/constants/prompt_data.ts +296 -296
  16. package/src/constants/prompts/card_gen_prompt.ts +372 -372
  17. package/src/constants/prompts/typology_prompt.ts +196 -202
  18. package/src/constants/source_data.ts +915 -47
  19. package/src/gap_fill/calculate_gap_fill.ts +52 -52
  20. package/src/index.ts +61 -61
  21. package/src/logger.ts +30 -30
  22. package/src/parse/parse_card_response.ts +289 -289
  23. package/src/parse/parse_source_content.ts +88 -94
  24. package/src/parse/response_format_card.ts +210 -210
  25. package/src/parse/response_format_typology.ts +43 -43
  26. package/src/services/open_ai_service.ts +55 -55
  27. package/src/typology_gen/generate_typology.ts +71 -71
  28. package/src/utils/generate_args.ts +28 -28
  29. package/src/utils/parse_openai_response.ts +20 -20
  30. package/tsconfig.json +12 -12
  31. package/dist/class/parse/parse_source_content.js +0 -62
  32. package/dist/class/services/open_ai_service.js +0 -25
  33. package/dist/parse_response/parse_card_response.js +0 -288
  34. package/dist/parse_response/response_format_card.js +0 -210
  35. package/dist/parse_response/response_format_typology.js +0 -47
  36. package/dist/service/open_ai_request.js +0 -57
@@ -1,95 +1,89 @@
1
- export class ParseSourceContent{
2
- public content: any;
3
-
4
- titles_to_remove = ['See also', 'References', 'Further reading', 'External links', 'Notes and references', 'Bibliography', 'Notes', 'Cited sources'];
5
-
6
- constructor(sourceContent:any){
7
- this.content = sourceContent;
8
- }
9
-
10
- parseData() {
11
- // if(this.content.type == 'source') {
12
- let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(this.content.content);
13
- let afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
14
- let taxonomy;
15
- if(this.content.taxonomy){
16
- taxonomy = this.content.taxonomy
17
- }else{
18
- taxonomy = null;
19
- }
20
- return {
21
- type: this.content.type,
22
- title: this.content.title,
23
- content: afterSanitized,
24
- headings: this.content.headings,
25
- taxonomy: this.content.taxonomy,
26
- }
27
- // } else if(this.content.type == 'cards'){
28
- // return {
29
- // type :'card',
30
- // title: this.content.title,
31
- // content: afterSanitized,
32
- // headings: this.content.headings
33
- // taxonomy: this.content.taxonomy,
34
- // };
35
- // }
36
-
37
- // return JSON.stringify(afterSanitized);
38
- }
39
-
40
- removeSectionsByTitle(data: Array<any>){
41
- let dataAfterRemoving = [];
42
- for(let elem of data){
43
- if(elem.block_type == 'heading' && this.titles_to_remove.includes(elem.content)){
44
- continue;
45
- }
46
- if(elem.children){
47
- elem.children = this.removeSectionsByTitle(elem.children)
48
- }
49
- dataAfterRemoving.push(elem)
50
-
51
- }
52
- return dataAfterRemoving;
53
- }
54
-
55
-
56
- sanitizeWikiContent(content: String) {
57
- // Remove newline characters
58
- content = content.replace(/\\n/g, ' ');
59
-
60
- // Remove internal link references, keeping only the link text
61
- // Pattern explanation: [[link|text|index|wiki]] --> text
62
- content = content.replace(/\[\[.*?\|(.*?)\|.*?\|wiki\]\]/g, '$1');
63
-
64
- // Remove external links, keeping only the link text
65
- // Pattern explanation: [url text] --> text
66
- content = content.replace(/\[http[s]?:\/\/[^\s]+ ([^\]]+)\]/g, '$1');
67
-
68
- // Remove Markdown link references, keeping only the link text
69
- // Pattern explanation: ![link text](url) --> link text
70
- content = content.replace(/\!\[([^\]]+)\]\([^\)]+\)/g, '$1');
71
-
72
- return content;
73
- }
74
-
75
- sanitizeBlocks(blocks: Array<any>) {
76
- let sanitizedBlocks = <any>[] ;
77
- blocks.forEach(block => {
78
- let sanitizedBlock: any = {};
79
- for (let key in block) {
80
- let value = block[key];
81
- if (typeof value === 'string') {
82
- sanitizedBlock[key] = this.sanitizeWikiContent(value);
83
- } else if (Array.isArray(value)) {
84
- sanitizedBlock[key] = this.sanitizeBlocks(value);
85
- } else {
86
- sanitizedBlock[key] = value;
87
- }
88
- }
89
- sanitizedBlocks.push(sanitizedBlock);
90
- });
91
- return sanitizedBlocks;
92
- }
93
-
94
-
1
+ export class ParseSourceContent{
2
+ public content: any;
3
+
4
+ titles_to_remove = ['See also', 'References', 'Further reading', 'External links', 'Notes and references', 'Bibliography', 'Notes', 'Cited sources'];
5
+
6
+ constructor(sourceContent:any){
7
+ this.content = sourceContent;
8
+ }
9
+
10
+ parseData() {
11
+ // if(this.content.type == 'source') {
12
+ let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(this.content.content);
13
+ let afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
14
+ return {
15
+ type: this.content.type,
16
+ title: this.content.title,
17
+ content: afterSanitized,
18
+ headings: this.content.headings,
19
+ taxonomy: this.content.taxonomy,
20
+ }
21
+ // } else if(this.content.type == 'cards'){
22
+ // return {
23
+ // type :'card',
24
+ // title: this.content.title,
25
+ // content: afterSanitized,
26
+ // headings: this.content.headings
27
+ // taxonomy: this.content.taxonomy,
28
+ // };
29
+ // }
30
+
31
+ // return JSON.stringify(afterSanitized);
32
+ }
33
+
34
+ removeSectionsByTitle(data: Array<any>){
35
+ let dataAfterRemoving = [];
36
+ for(let elem of data){
37
+ if(elem.block_type == 'heading' && this.titles_to_remove.includes(elem.content)){
38
+ continue;
39
+ }
40
+ if(elem.children){
41
+ elem.children = this.removeSectionsByTitle(elem.children)
42
+ }
43
+ dataAfterRemoving.push(elem)
44
+
45
+ }
46
+ return dataAfterRemoving;
47
+ }
48
+
49
+
50
+ sanitizeWikiContent(content: String) {
51
+ // Remove newline characters
52
+ content = content.replace(/\\n/g, ' ');
53
+
54
+ // Remove internal link references, keeping only the link text
55
+ // Pattern explanation: [[link|text|index|wiki]] --> text
56
+ content = content.replace(/\[\[.*?\|(.*?)\|.*?\|wiki\]\]/g, '$1');
57
+
58
+ // Remove external links, keeping only the link text
59
+ // Pattern explanation: [url text] --> text
60
+ content = content.replace(/\[http[s]?:\/\/[^\s]+ ([^\]]+)\]/g, '$1');
61
+
62
+ // Remove Markdown link references, keeping only the link text
63
+ // Pattern explanation: ![link text](url) --> link text
64
+ content = content.replace(/\!\[([^\]]+)\]\([^\)]+\)/g, '$1');
65
+
66
+ return content;
67
+ }
68
+
69
+ sanitizeBlocks(blocks: Array<any>) {
70
+ let sanitizedBlocks = <any>[] ;
71
+ blocks.forEach(block => {
72
+ let sanitizedBlock: any = {};
73
+ for (let key in block) {
74
+ let value = block[key];
75
+ if (typeof value === 'string') {
76
+ sanitizedBlock[key] = this.sanitizeWikiContent(value);
77
+ } else if (Array.isArray(value)) {
78
+ sanitizedBlock[key] = this.sanitizeBlocks(value);
79
+ } else {
80
+ sanitizedBlock[key] = value;
81
+ }
82
+ }
83
+ sanitizedBlocks.push(sanitizedBlock);
84
+ });
85
+ return sanitizedBlocks;
86
+ }
87
+
88
+
95
89
  }
@@ -1,211 +1,211 @@
1
- const responseData = {
2
- "flash_cards": [
3
- {
4
- "question": "What is the primary function of the 'Electrolysis'?",
5
- "answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
6
- "heading": "Overview"
7
- },
8
- {
9
- "question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
10
- "answer": "Michael Faraday discovered two laws of electrolysis.",
11
- "heading": "History"
12
- },
13
- {
14
- "question": "What can electrolysis be used for in the manufacturing sector?",
15
- "answer": "Electrolysis can be used for electroplating and electrochemical machining.",
16
- "heading": "Manufacturing processes"
17
- },
18
- {
19
- "question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
20
- "answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
21
- "heading": "Decomposition potential"
22
- }
23
- ],
24
- "mcqs": [
25
- {
26
- "question": "What is the primary purpose of 'Electrometallurgy'?",
27
- "answers": [
28
- {
29
- "answer": "Production of aluminium",
30
- "is_correct": true
31
- },
32
- {
33
- "answer": "Chlorine production",
34
- "is_correct": false
35
- },
36
- {
37
- "answer": "Purifying copper",
38
- "is_correct": false
39
- },
40
- {
41
- "answer": "Rust removal",
42
- "is_correct": false
43
- },
44
- {
45
- "answer": "Hydrogen production",
46
- "is_correct": false
47
- }
48
- ],
49
- "heading": "Industrial uses"
50
- },
51
- {
52
- "question": "What can electrolysis be used for in the context of batteries?",
53
- "answers": [
54
- {
55
- "answer": "Spontaneous redox reactions",
56
- "is_correct": true
57
- },
58
- {
59
- "answer": "Energy-releasing reactions",
60
- "is_correct": false
61
- },
62
- {
63
- "answer": "Disinfectant production",
64
- "is_correct": false
65
- },
66
- {
67
- "answer": "Fuel production",
68
- "is_correct": false
69
- },
70
- {
71
- "answer": "Gas diffusion in reactors",
72
- "is_correct": false
73
- }
74
- ],
75
- "heading": "Related processes"
76
- }
77
- ],
78
- "cloze_cards": [
79
- {
80
- "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.",
81
- "options": [
82
- {
83
- "option": "direct electric current",
84
- "cloze": "c0"
85
- },
86
- {
87
- "option": "electrolyte",
88
- "cloze": "c1"
89
- },
90
- {
91
- "option": "chemical reactions",
92
- "cloze": "c2"
93
- },
94
- {
95
- "option": "electrodes",
96
- "cloze": "c3"
97
- },
98
- {
99
- "option": "decomposition",
100
- "cloze": "c4"
101
- },
102
- {
103
- "option": "metallic objects",
104
- "cloze": null
105
- }
106
- ]
107
- },
108
- {
109
- "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.",
110
- "options": [
111
- {
112
- "option": "anode",
113
- "cloze": "c0"
114
- },
115
- {
116
- "option": "cathode",
117
- "cloze": "c1"
118
- },
119
- {
120
- "option": "electrolyte",
121
- "cloze": null
122
- },
123
- {
124
- "option": "chemical reactions",
125
- "cloze": null
126
- },
127
- {
128
- "option": "oxygen",
129
- "cloze": null
130
- },
131
- {
132
- "option": "hydrogen",
133
- "cloze": null
134
- }
135
- ]
136
- }
137
- ]
138
- };
139
-
140
-
141
- export function returnResponse(){
142
- return responseData;
143
- }
144
-
145
- export function parseResponse(){
146
- let cardData = [];
147
- let data = returnResponse();
148
- let keys = Object.keys(data);
149
- if(keys){
150
- for(let elem of keys){
151
- if(elem == 'flash_cards'){
152
- cardData.push(...parseFlashCard(data.flash_cards))
153
- }else if(elem == 'cloze_cards'){
154
- cardData.push(...parseClozeCards(data.cloze_cards))
155
- }else if(elem == 'mcqs'){
156
- cardData.push(...parseMcq(data.mcqs))
157
- }
158
- }
159
- }
160
- return cardData;
161
- }
162
- /// takes array of
163
- function parseFlashCard(cards: Array<any>){
164
- let flashCardData = [];
165
- for(let elem of cards){
166
- flashCardData.push({
167
- "type":"flash",
168
- "heading": elem.heading,
169
- "content": JSON.stringify({
170
- "front_content": elem.question,
171
- "back_content": elem.answer
172
- })
173
- });
174
- }
175
- return flashCardData;
176
-
177
- }
178
-
179
- /// takes array of
180
- function parseMcq(cardsData: Array<any>){
181
- let mcqCards= [];
182
- for(let elem of cardsData){
183
- mcqCards.push({
184
- "type":"mcq",
185
- "heading": elem.heading,
186
- "content": JSON.stringify({
187
- "question": elem.question,
188
- "answers": elem.answers
189
- })
190
- });
191
- }
192
- return mcqCards;
193
-
194
- }
195
-
196
- /// takes array of
197
- function parseClozeCards(cardsData: Array<any>){
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
+ const responseData = {
2
+ "flash_cards": [
3
+ {
4
+ "question": "What is the primary function of the 'Electrolysis'?",
5
+ "answer": "Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
6
+ "heading": "Overview"
7
+ },
8
+ {
9
+ "question": "What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
10
+ "answer": "Michael Faraday discovered two laws of electrolysis.",
11
+ "heading": "History"
12
+ },
13
+ {
14
+ "question": "What can electrolysis be used for in the manufacturing sector?",
15
+ "answer": "Electrolysis can be used for electroplating and electrochemical machining.",
16
+ "heading": "Manufacturing processes"
17
+ },
18
+ {
19
+ "question": "In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
20
+ "answer": "Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
21
+ "heading": "Decomposition potential"
22
+ }
23
+ ],
24
+ "mcqs": [
25
+ {
26
+ "question": "What is the primary purpose of 'Electrometallurgy'?",
27
+ "answers": [
28
+ {
29
+ "answer": "Production of aluminium",
30
+ "is_correct": true
31
+ },
32
+ {
33
+ "answer": "Chlorine production",
34
+ "is_correct": false
35
+ },
36
+ {
37
+ "answer": "Purifying copper",
38
+ "is_correct": false
39
+ },
40
+ {
41
+ "answer": "Rust removal",
42
+ "is_correct": false
43
+ },
44
+ {
45
+ "answer": "Hydrogen production",
46
+ "is_correct": false
47
+ }
48
+ ],
49
+ "heading": "Industrial uses"
50
+ },
51
+ {
52
+ "question": "What can electrolysis be used for in the context of batteries?",
53
+ "answers": [
54
+ {
55
+ "answer": "Spontaneous redox reactions",
56
+ "is_correct": true
57
+ },
58
+ {
59
+ "answer": "Energy-releasing reactions",
60
+ "is_correct": false
61
+ },
62
+ {
63
+ "answer": "Disinfectant production",
64
+ "is_correct": false
65
+ },
66
+ {
67
+ "answer": "Fuel production",
68
+ "is_correct": false
69
+ },
70
+ {
71
+ "answer": "Gas diffusion in reactors",
72
+ "is_correct": false
73
+ }
74
+ ],
75
+ "heading": "Related processes"
76
+ }
77
+ ],
78
+ "cloze_cards": [
79
+ {
80
+ "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.",
81
+ "options": [
82
+ {
83
+ "option": "direct electric current",
84
+ "cloze": "c0"
85
+ },
86
+ {
87
+ "option": "electrolyte",
88
+ "cloze": "c1"
89
+ },
90
+ {
91
+ "option": "chemical reactions",
92
+ "cloze": "c2"
93
+ },
94
+ {
95
+ "option": "electrodes",
96
+ "cloze": "c3"
97
+ },
98
+ {
99
+ "option": "decomposition",
100
+ "cloze": "c4"
101
+ },
102
+ {
103
+ "option": "metallic objects",
104
+ "cloze": null
105
+ }
106
+ ]
107
+ },
108
+ {
109
+ "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.",
110
+ "options": [
111
+ {
112
+ "option": "anode",
113
+ "cloze": "c0"
114
+ },
115
+ {
116
+ "option": "cathode",
117
+ "cloze": "c1"
118
+ },
119
+ {
120
+ "option": "electrolyte",
121
+ "cloze": null
122
+ },
123
+ {
124
+ "option": "chemical reactions",
125
+ "cloze": null
126
+ },
127
+ {
128
+ "option": "oxygen",
129
+ "cloze": null
130
+ },
131
+ {
132
+ "option": "hydrogen",
133
+ "cloze": null
134
+ }
135
+ ]
136
+ }
137
+ ]
138
+ };
139
+
140
+
141
+ export function returnResponse(){
142
+ return responseData;
143
+ }
144
+
145
+ export function parseResponse(){
146
+ let cardData = [];
147
+ let data = returnResponse();
148
+ let keys = Object.keys(data);
149
+ if(keys){
150
+ for(let elem of keys){
151
+ if(elem == 'flash_cards'){
152
+ cardData.push(...parseFlashCard(data.flash_cards))
153
+ }else if(elem == 'cloze_cards'){
154
+ cardData.push(...parseClozeCards(data.cloze_cards))
155
+ }else if(elem == 'mcqs'){
156
+ cardData.push(...parseMcq(data.mcqs))
157
+ }
158
+ }
159
+ }
160
+ return cardData;
161
+ }
162
+ /// takes array of
163
+ function parseFlashCard(cards: Array<any>){
164
+ let flashCardData = [];
165
+ for(let elem of cards){
166
+ flashCardData.push({
167
+ "type":"flash",
168
+ "heading": elem.heading,
169
+ "content": JSON.stringify({
170
+ "front_content": elem.question,
171
+ "back_content": elem.answer
172
+ })
173
+ });
174
+ }
175
+ return flashCardData;
176
+
177
+ }
178
+
179
+ /// takes array of
180
+ function parseMcq(cardsData: Array<any>){
181
+ let mcqCards= [];
182
+ for(let elem of cardsData){
183
+ mcqCards.push({
184
+ "type":"mcq",
185
+ "heading": elem.heading,
186
+ "content": JSON.stringify({
187
+ "question": elem.question,
188
+ "answers": elem.answers
189
+ })
190
+ });
191
+ }
192
+ return mcqCards;
193
+
194
+ }
195
+
196
+ /// takes array of
197
+ function parseClozeCards(cardsData: Array<any>){
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
+
211
211
  }