only_ever_generator 1.0.3 → 1.0.5
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/bootstrap/app.d.ts +91 -0
- package/dist/bootstrap/app.d.ts.map +1 -0
- package/dist/bootstrap/app.js +120 -84
- package/dist/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.d.ts +7 -0
- package/dist/card_gen/generate_cards.d.ts.map +1 -0
- package/dist/card_gen/generate_cards.js +60 -0
- package/dist/card_gen/generate_cards.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +4 -1
- package/dist/config.js.map +1 -0
- package/dist/constants/api_constants.d.ts +3 -0
- package/dist/constants/api_constants.d.ts.map +1 -0
- package/dist/constants/api_constants.js +11 -0
- package/dist/constants/api_constants.js.map +1 -0
- package/dist/constants/prompt_data.d.ts +5 -0
- package/dist/constants/prompt_data.d.ts.map +1 -0
- package/dist/constants/prompt_data.js +303 -0
- package/dist/constants/prompt_data.js.map +1 -0
- package/dist/constants/prompts/card_gen_prompt.d.ts +2 -0
- package/dist/constants/prompts/card_gen_prompt.d.ts.map +1 -0
- package/dist/constants/prompts/card_gen_prompt.js +100 -203
- package/dist/constants/prompts/card_gen_prompt.js.map +1 -0
- package/dist/constants/prompts/typology_prompt.d.ts +2 -0
- package/dist/constants/prompts/typology_prompt.d.ts.map +1 -0
- package/dist/constants/prompts/typology_prompt.js +78 -34
- package/dist/constants/prompts/typology_prompt.js.map +1 -0
- package/dist/constants/source_data.d.ts +173 -0
- package/dist/constants/source_data.d.ts.map +1 -0
- package/dist/constants/source_data.js +962 -10
- package/dist/constants/source_data.js.map +1 -0
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts +33 -0
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/global_consolidation.js +76 -0
- package/dist/embedding_generation/consolidation/global_consolidation.js.map +1 -0
- package/dist/embedding_generation/consolidation/local_consolidation.d.ts +39 -0
- package/dist/embedding_generation/consolidation/local_consolidation.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/local_consolidation.js +105 -0
- package/dist/embedding_generation/consolidation/local_consolidation.js.map +1 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.d.ts +46 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.js +69 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.js.map +1 -0
- package/dist/embedding_generation/generate_embeddings.d.ts +28 -0
- package/dist/embedding_generation/generate_embeddings.d.ts.map +1 -0
- package/dist/embedding_generation/generate_embeddings.js +54 -0
- package/dist/embedding_generation/generate_embeddings.js.map +1 -0
- package/dist/embedding_generation/parse_embedding_response.d.ts +26 -0
- package/dist/embedding_generation/parse_embedding_response.d.ts.map +1 -0
- package/dist/embedding_generation/parse_embedding_response.js +29 -0
- package/dist/embedding_generation/parse_embedding_response.js.map +1 -0
- package/dist/gap_fill/calculate_gap_fill.d.ts +5 -0
- package/dist/gap_fill/calculate_gap_fill.d.ts.map +1 -0
- package/dist/gap_fill/calculate_gap_fill.js +43 -0
- package/dist/gap_fill/calculate_gap_fill.js.map +1 -0
- package/dist/helper/qdrant_db_methods.d.ts +40 -0
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -0
- package/dist/helper/qdrant_db_methods.js +63 -0
- package/dist/helper/qdrant_db_methods.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -149
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +42 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts +10 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.js +126 -0
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts +19 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.js +34 -0
- package/dist/parse/parse_card/parse_flash_cards.js.map +1 -0
- package/dist/parse/parse_card/parse_match_card.d.ts +16 -0
- package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_match_card.js +82 -0
- package/dist/parse/parse_card/parse_match_card.js.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts +24 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.js +104 -0
- package/dist/parse/parse_card/parse_mcq_card.js.map +1 -0
- package/dist/parse/parse_card_response.d.ts +19 -0
- package/dist/parse/parse_card_response.d.ts.map +1 -0
- package/dist/parse/parse_card_response.js +100 -0
- package/dist/parse/parse_card_response.js.map +1 -0
- package/dist/parse/parse_source_content.d.ts +25 -0
- package/dist/parse/parse_source_content.d.ts.map +1 -0
- package/dist/parse/parse_source_content.js +186 -0
- package/dist/parse/parse_source_content.js.map +1 -0
- package/dist/parse/response_format_card.d.ts +177 -0
- package/dist/parse/response_format_card.d.ts.map +1 -0
- package/dist/parse/response_format_card.js +372 -0
- package/dist/parse/response_format_card.js.map +1 -0
- package/dist/parse/response_format_typology.d.ts +2 -0
- package/dist/parse/response_format_typology.d.ts.map +1 -0
- package/dist/{parse_response → parse}/response_format_typology.js +18 -18
- package/dist/parse/response_format_typology.js.map +1 -0
- package/dist/services/open_ai_service.d.ts +16 -0
- package/dist/services/open_ai_service.d.ts.map +1 -0
- package/dist/services/open_ai_service.js +92 -0
- package/dist/services/open_ai_service.js.map +1 -0
- package/dist/services/qdrant_service.d.ts +4 -0
- package/dist/services/qdrant_service.d.ts.map +1 -0
- package/dist/services/qdrant_service.js +14 -0
- package/dist/services/qdrant_service.js.map +1 -0
- package/dist/typology-parsed-response.d.ts +62 -0
- package/dist/typology-parsed-response.d.ts.map +1 -0
- package/dist/typology-parsed-response.js +1936 -0
- package/dist/typology-parsed-response.js.map +1 -0
- package/dist/typology_gen/generate_typology.d.ts +29 -0
- package/dist/typology_gen/generate_typology.d.ts.map +1 -0
- package/dist/typology_gen/generate_typology.js +92 -15
- package/dist/typology_gen/generate_typology.js.map +1 -0
- package/dist/utils/generate_args.d.ts +8 -0
- package/dist/utils/generate_args.d.ts.map +1 -0
- package/dist/utils/generate_args.js +28 -0
- package/dist/utils/generate_args.js.map +1 -0
- package/dist/utils/parse_openai_response.d.ts +11 -0
- package/dist/utils/parse_openai_response.d.ts.map +1 -0
- package/dist/utils/parse_openai_response.js +11 -10
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +19 -7
- package/prompts.json +23 -0
- package/readme.md +16 -13
- package/src/bootstrap/app.ts +167 -107
- package/src/card_gen/generate_cards.ts +58 -0
- package/src/config.ts +5 -3
- package/src/constants/api_constants.ts +7 -0
- package/src/constants/prompt_data.ts +301 -0
- package/src/constants/prompts/card_gen_prompt.ts +101 -208
- package/src/constants/prompts/typology_prompt.ts +81 -33
- package/src/constants/source_data.ts +1029 -23
- package/src/embedding_generation/consolidation/global_consolidation.ts +94 -0
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -0
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -0
- package/src/embedding_generation/generate_embeddings.ts +41 -0
- package/src/embedding_generation/parse_embedding_response.ts +31 -0
- package/src/gap_fill/calculate_gap_fill.ts +50 -0
- package/src/helper/qdrant_db_methods.ts +77 -0
- package/src/index.ts +98 -164
- package/src/logger.ts +30 -0
- package/src/parse/parse_card/parse_cloze_card.ts +136 -0
- package/src/parse/parse_card/parse_flash_cards.ts +33 -0
- package/src/parse/parse_card/parse_match_card.ts +94 -0
- package/src/parse/parse_card/parse_mcq_card.ts +105 -0
- package/src/parse/parse_card_response.ts +117 -0
- package/src/parse/parse_source_content.ts +202 -0
- package/src/parse/response_format_card.ts +386 -0
- package/src/parse/response_format_typology.ts +44 -0
- package/src/services/open_ai_service.ts +88 -0
- package/src/services/qdrant_service.ts +10 -0
- package/src/typology-parsed-response.ts +1932 -0
- package/src/typology_gen/generate_typology.ts +101 -12
- package/src/utils/generate_args.ts +29 -0
- package/src/utils/parse_openai_response.ts +17 -19
- package/tsconfig.json +8 -3
- package/dist/class/parse/parse_source_content.js +0 -62
- package/dist/class/services/open_ai_service.js +0 -25
- package/dist/parse_response/response_format_card.js +0 -210
- package/dist/service/open_ai_request.js +0 -58
- package/src/class/parse/parse_source_content.ts +0 -71
- package/src/class/services/open_ai_service.ts +0 -18
- package/src/parse_response/response_format_card.ts +0 -211
- package/src/parse_response/response_format_typology.ts +0 -44
- package/src/service/open_ai_request.ts +0 -46
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { ErrorLogger } from "../logger";
|
|
2
|
+
import { ParseClozeCard } from "./parse_card/parse_cloze_card";
|
|
3
|
+
import { ParseFlashCard } from "./parse_card/parse_flash_cards";
|
|
4
|
+
import { ParseMatchCard } from "./parse_card/parse_match_card";
|
|
5
|
+
import { ParseMcqCard } from "./parse_card/parse_mcq_card";
|
|
6
|
+
|
|
7
|
+
export class ParseCardResponse {
|
|
8
|
+
parse(generatedData: any, isGapFill: boolean, sourceTaxonomy: any) {
|
|
9
|
+
let usage_data = generatedData.metadata;
|
|
10
|
+
try {
|
|
11
|
+
const cardData = [];
|
|
12
|
+
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
13
|
+
const type = generatedData.type;
|
|
14
|
+
|
|
15
|
+
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
16
|
+
for (let elem of unparsedTestCards) {
|
|
17
|
+
const managedCardConcepts = this._mapIdToConcepts(
|
|
18
|
+
elem.concepts_facts,
|
|
19
|
+
sourceTaxonomy.concepts_facts
|
|
20
|
+
);
|
|
21
|
+
elem.concepts = managedCardConcepts;
|
|
22
|
+
if (elem.type == "flash") {
|
|
23
|
+
const flashCard = new ParseFlashCard().parse(elem);
|
|
24
|
+
if (flashCard != null && flashCard) {
|
|
25
|
+
flashCard.heading = this._getCardReference(
|
|
26
|
+
flashCard,
|
|
27
|
+
sourceTaxonomy
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
cardData.push(flashCard);
|
|
31
|
+
}
|
|
32
|
+
} else if (elem.type == "mcq") {
|
|
33
|
+
const mcqCard = new ParseMcqCard().parse(elem);
|
|
34
|
+
if (mcqCard != null && mcqCard) {
|
|
35
|
+
mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
|
|
36
|
+
cardData.push(mcqCard);
|
|
37
|
+
}
|
|
38
|
+
} else if (elem.type == "cloze") {
|
|
39
|
+
const clozeCard = new ParseClozeCard().parse(elem);
|
|
40
|
+
if (clozeCard && clozeCard != null) {
|
|
41
|
+
clozeCard.heading = this._getCardReference(
|
|
42
|
+
clozeCard,
|
|
43
|
+
sourceTaxonomy
|
|
44
|
+
);
|
|
45
|
+
cardData.push(clozeCard);
|
|
46
|
+
}
|
|
47
|
+
} else if (elem.type == "match") {
|
|
48
|
+
const matchCard = new ParseMatchCard().parse(elem);
|
|
49
|
+
if (matchCard && matchCard != null) {
|
|
50
|
+
matchCard.heading = this._getCardReference(
|
|
51
|
+
matchCard,
|
|
52
|
+
sourceTaxonomy
|
|
53
|
+
);
|
|
54
|
+
cardData.push(matchCard);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
} else {
|
|
59
|
+
if (!isGapFill) {
|
|
60
|
+
usage_data.status = "failed";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
if (cardData.length == 0) {
|
|
64
|
+
usage_data.status = "failed";
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return {
|
|
68
|
+
status_code: cardData.length == 0 ? 400 : 200,
|
|
69
|
+
metadata: usage_data,
|
|
70
|
+
type: type,
|
|
71
|
+
|
|
72
|
+
cards_data: cardData,
|
|
73
|
+
};
|
|
74
|
+
} catch (e: any) {
|
|
75
|
+
return {
|
|
76
|
+
status_code: 500,
|
|
77
|
+
metadata: usage_data,
|
|
78
|
+
type: generatedData.type,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
_getCardReference(generatedCardData: any, sourceTaxonomy: any) {
|
|
84
|
+
const cardConcepts = (generatedCardData.concepts ?? []).map(
|
|
85
|
+
(e: any) => e.text
|
|
86
|
+
);
|
|
87
|
+
|
|
88
|
+
const sourceConceptsFacts = sourceTaxonomy.concepts_facts ?? [];
|
|
89
|
+
const firstMatchedConcept = sourceConceptsFacts.find((elem: any) =>
|
|
90
|
+
cardConcepts.includes(elem.text)
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (firstMatchedConcept) {
|
|
94
|
+
return firstMatchedConcept.reference;
|
|
95
|
+
} else {
|
|
96
|
+
return "";
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
_mapIdToConcepts(cardConcepts: any[], sourceConceptsFacts: any[]) {
|
|
101
|
+
// const cardData = cardC
|
|
102
|
+
const managedCardConcepts = [];
|
|
103
|
+
for (const cardConcept of cardConcepts) {
|
|
104
|
+
const matchedConcept = sourceConceptsFacts.find(
|
|
105
|
+
(e: any) =>
|
|
106
|
+
e.text.toLowerCase().trim() == cardConcept.text.toLowerCase().trim()
|
|
107
|
+
);
|
|
108
|
+
if (matchedConcept) {
|
|
109
|
+
managedCardConcepts.push({
|
|
110
|
+
id: matchedConcept.id,
|
|
111
|
+
text: matchedConcept.text,
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return managedCardConcepts;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
export class ParseSourceContent {
|
|
2
|
+
public content: any;
|
|
3
|
+
/// Format of Content
|
|
4
|
+
// content: {
|
|
5
|
+
// title: source.title,
|
|
6
|
+
// headings: source.headings,
|
|
7
|
+
// content: source.content,
|
|
8
|
+
// fields: fields,
|
|
9
|
+
// taxonomy: source.source_taxonomy,
|
|
10
|
+
// type: source.source_type
|
|
11
|
+
// },
|
|
12
|
+
|
|
13
|
+
titles_to_remove = [
|
|
14
|
+
"See also",
|
|
15
|
+
"References",
|
|
16
|
+
"Further reading",
|
|
17
|
+
"External links",
|
|
18
|
+
"Notes and references",
|
|
19
|
+
"Bibliography",
|
|
20
|
+
"Notes",
|
|
21
|
+
"Cited sources",
|
|
22
|
+
];
|
|
23
|
+
block_types_toremove = ["table", "empty_line"];
|
|
24
|
+
constructor(sourceContent: any) {
|
|
25
|
+
this.content = sourceContent;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
parseData() {
|
|
29
|
+
let sourceType = this.content.type;
|
|
30
|
+
let afterSanitized;
|
|
31
|
+
if (sourceType == "video") {
|
|
32
|
+
afterSanitized = this.parseVideoContent(this.content.content);
|
|
33
|
+
} else {
|
|
34
|
+
let dataAfterRemovingUnWantedBlocks = this.removeSectionsByTitle(
|
|
35
|
+
this.content.content
|
|
36
|
+
);
|
|
37
|
+
afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
type: this.content.type,
|
|
41
|
+
title: this.content.title,
|
|
42
|
+
content: afterSanitized,
|
|
43
|
+
headings: this.content.headings,
|
|
44
|
+
taxonomy: this.content.taxonomy,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
removeSectionsByTitle(data: Array<any>) {
|
|
49
|
+
let dataAfterRemoving = [];
|
|
50
|
+
for (let elem of data) {
|
|
51
|
+
if (
|
|
52
|
+
elem.block_type == "heading" &&
|
|
53
|
+
this.titles_to_remove.includes(elem.content)
|
|
54
|
+
) {
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
/// remove unwanted blcok types , for now `table` and `empty_line`
|
|
58
|
+
if (this.block_types_toremove.includes(elem.block_type)) {
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (elem.children) {
|
|
62
|
+
elem.children = this.removeSectionsByTitle(elem.children);
|
|
63
|
+
}
|
|
64
|
+
dataAfterRemoving.push(elem);
|
|
65
|
+
}
|
|
66
|
+
return dataAfterRemoving;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
sanitizeTextContent(content: String) {
|
|
70
|
+
// Remove newline characters
|
|
71
|
+
content = content.replace(/\\n/g, " ");
|
|
72
|
+
|
|
73
|
+
// Remove internal link references, keeping only the link text
|
|
74
|
+
// Pattern explanation: [[link|text|index|wiki]] --> text
|
|
75
|
+
content = content.replace(/\[\[.*?\|(.*?)\|.*?\|wiki\]\]/g, "$1");
|
|
76
|
+
|
|
77
|
+
// Remove external links, keeping only the link text
|
|
78
|
+
// Pattern explanation: [url text] --> text
|
|
79
|
+
content = content.replace(/\[http[s]?:\/\/[^\s]+ ([^\]]+)\]/g, "$1");
|
|
80
|
+
|
|
81
|
+
// Remove Markdown link references, keeping only the link text
|
|
82
|
+
// Pattern explanation:  --> link text
|
|
83
|
+
content = content.replace(/\!\[([^\]]+)\]\([^\)]+\)/g, "$1");
|
|
84
|
+
|
|
85
|
+
return content;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
sanitizeBlocks(blocks: Array<any>) {
|
|
89
|
+
let sanitizedBlocks = <any>[];
|
|
90
|
+
blocks = blocks.filter((item) => item.block_type != "table");
|
|
91
|
+
blocks.forEach((block) => {
|
|
92
|
+
let sanitizedBlock: any = {};
|
|
93
|
+
for (let key in block) {
|
|
94
|
+
let value = block[key];
|
|
95
|
+
if (typeof value === "string") {
|
|
96
|
+
sanitizedBlock[key] = this.sanitizeTextContent(value);
|
|
97
|
+
} else if (Array.isArray(value)) {
|
|
98
|
+
sanitizedBlock[key] = this.sanitizeBlocks(value);
|
|
99
|
+
} else {
|
|
100
|
+
sanitizedBlock[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
sanitizedBlocks.push(sanitizedBlock);
|
|
104
|
+
});
|
|
105
|
+
return sanitizedBlocks;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
parseVideoContent(data: Array<any>) {
|
|
109
|
+
let finalChapters: Array<any> = [];
|
|
110
|
+
// let cleanedData = this.cleanTranscript(timeCodes);
|
|
111
|
+
data.forEach((e) => {
|
|
112
|
+
let combinedContent = this.cleanTranscript(e);
|
|
113
|
+
finalChapters.push({
|
|
114
|
+
startTime: e.startTime,
|
|
115
|
+
endTime: e.endTime,
|
|
116
|
+
content: combinedContent,
|
|
117
|
+
title: e.content,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
return finalChapters;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// remove content inside [] which denotes non-speech sounds
|
|
125
|
+
isNonSpeech(content: string) {
|
|
126
|
+
// Check if the content is non-speech (enclosed in square brackets).
|
|
127
|
+
return /^\[.*\]$/.test(content.trim());
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// remove non-essential content
|
|
131
|
+
cleanTranscript(data: any) {
|
|
132
|
+
let finalContent = "";
|
|
133
|
+
let children = data.children ?? [];
|
|
134
|
+
|
|
135
|
+
children.forEach((e: any) => {
|
|
136
|
+
let content = (e.content || "").trim();
|
|
137
|
+
|
|
138
|
+
if (this.isNonSpeech(content)) return;
|
|
139
|
+
|
|
140
|
+
content = content.replace(/\s+/g, " ");
|
|
141
|
+
finalContent += content;
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
return finalContent;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// collapse the timecode to 30 seconds
|
|
148
|
+
collapseTimeCodes(data: Array<any>, maxDuration = 30.0) {
|
|
149
|
+
// Collapse time codes into buckets of approximately maxDuration seconds.
|
|
150
|
+
const collapsedData = [];
|
|
151
|
+
let bucketStartTime: number | null = null;
|
|
152
|
+
let bucketEndTime: number | null = null;
|
|
153
|
+
let bucketContent: Array<any> = [];
|
|
154
|
+
let bucketDuration = 0.0;
|
|
155
|
+
|
|
156
|
+
data.forEach((entry) => {
|
|
157
|
+
const startTime = entry.start_time;
|
|
158
|
+
const endTime = entry.end_time;
|
|
159
|
+
const content = entry.content;
|
|
160
|
+
const entryDuration = endTime - startTime;
|
|
161
|
+
|
|
162
|
+
if (bucketStartTime === null) {
|
|
163
|
+
// Start a new bucket
|
|
164
|
+
bucketStartTime = startTime;
|
|
165
|
+
bucketEndTime = endTime;
|
|
166
|
+
bucketContent.push(content);
|
|
167
|
+
bucketDuration = entryDuration;
|
|
168
|
+
} else if (bucketDuration + entryDuration <= maxDuration) {
|
|
169
|
+
// Add to current bucket
|
|
170
|
+
bucketEndTime = endTime;
|
|
171
|
+
bucketContent.push(content);
|
|
172
|
+
bucketDuration += entryDuration;
|
|
173
|
+
} else {
|
|
174
|
+
// Close current bucket and start a new one
|
|
175
|
+
const collapsedEntry = {
|
|
176
|
+
start_time: bucketStartTime,
|
|
177
|
+
end_time: bucketEndTime,
|
|
178
|
+
content: bucketContent.join(" "),
|
|
179
|
+
};
|
|
180
|
+
collapsedData.push(collapsedEntry);
|
|
181
|
+
|
|
182
|
+
// Start new bucket with current entry
|
|
183
|
+
bucketStartTime = startTime;
|
|
184
|
+
bucketEndTime = endTime;
|
|
185
|
+
bucketContent = [content];
|
|
186
|
+
bucketDuration = entryDuration;
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
// Add the last bucket if it exists
|
|
191
|
+
if (bucketContent.length > 0) {
|
|
192
|
+
const collapsedEntry = {
|
|
193
|
+
start_time: bucketStartTime,
|
|
194
|
+
end_time: bucketEndTime,
|
|
195
|
+
content: bucketContent.join(" "),
|
|
196
|
+
};
|
|
197
|
+
collapsedData.push(collapsedEntry);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
return collapsedData;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
const responseData = {
|
|
2
|
+
flash_cards: [
|
|
3
|
+
{
|
|
4
|
+
question: "What is the primary function of the 'Electrolysis'?",
|
|
5
|
+
answer:
|
|
6
|
+
"Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
7
|
+
heading: "Overview",
|
|
8
|
+
},
|
|
9
|
+
{
|
|
10
|
+
question:
|
|
11
|
+
"What did Michael Faraday discover while studying the process of electrolysis under Humphry Davy?",
|
|
12
|
+
answer: "Michael Faraday discovered two laws of electrolysis.",
|
|
13
|
+
heading: "History",
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
question:
|
|
17
|
+
"What can electrolysis be used for in the manufacturing sector?",
|
|
18
|
+
answer:
|
|
19
|
+
"Electrolysis can be used for electroplating and electrochemical machining.",
|
|
20
|
+
heading: "Manufacturing processes",
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
question:
|
|
24
|
+
"In the context of electrolysis, what does the term 'Decomposition potential' refer to?",
|
|
25
|
+
answer:
|
|
26
|
+
"Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell needed for electrolysis to occur.",
|
|
27
|
+
heading: "Decomposition potential",
|
|
28
|
+
},
|
|
29
|
+
],
|
|
30
|
+
mcqs: [
|
|
31
|
+
{
|
|
32
|
+
question: "What is the primary purpose of 'Electrometallurgy'?",
|
|
33
|
+
answers: [
|
|
34
|
+
{
|
|
35
|
+
answer: "Production of aluminium",
|
|
36
|
+
is_correct: true,
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
answer: "Chlorine production",
|
|
40
|
+
is_correct: false,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
answer: "Purifying copper",
|
|
44
|
+
is_correct: false,
|
|
45
|
+
},
|
|
46
|
+
{
|
|
47
|
+
answer: "Rust removal",
|
|
48
|
+
is_correct: false,
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
answer: "Hydrogen production",
|
|
52
|
+
is_correct: false,
|
|
53
|
+
},
|
|
54
|
+
],
|
|
55
|
+
heading: "Industrial uses",
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
question:
|
|
59
|
+
"What can electrolysis be used for in the context of batteries?",
|
|
60
|
+
answers: [
|
|
61
|
+
{
|
|
62
|
+
answer: "Spontaneous redox reactions",
|
|
63
|
+
is_correct: true,
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
answer: "Energy-releasing reactions",
|
|
67
|
+
is_correct: false,
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
answer: "Disinfectant production",
|
|
71
|
+
is_correct: false,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
answer: "Fuel production",
|
|
75
|
+
is_correct: false,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
answer: "Gas diffusion in reactors",
|
|
79
|
+
is_correct: false,
|
|
80
|
+
},
|
|
81
|
+
],
|
|
82
|
+
heading: "Related processes",
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
cloze_cards: [
|
|
86
|
+
{
|
|
87
|
+
question:
|
|
88
|
+
"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.",
|
|
89
|
+
options: [
|
|
90
|
+
{
|
|
91
|
+
option: "direct electric current",
|
|
92
|
+
cloze: "c0",
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
option: "electrolyte",
|
|
96
|
+
cloze: "c1",
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
option: "chemical reactions",
|
|
100
|
+
cloze: "c2",
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
option: "electrodes",
|
|
104
|
+
cloze: "c3",
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
option: "decomposition",
|
|
108
|
+
cloze: "c4",
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
option: "metallic objects",
|
|
112
|
+
cloze: null,
|
|
113
|
+
},
|
|
114
|
+
],
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
question:
|
|
118
|
+
"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.",
|
|
119
|
+
options: [
|
|
120
|
+
{
|
|
121
|
+
option: "anode",
|
|
122
|
+
cloze: "c0",
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
option: "cathode",
|
|
126
|
+
cloze: "c1",
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
option: "electrolyte",
|
|
130
|
+
cloze: null,
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
option: "chemical reactions",
|
|
134
|
+
cloze: null,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
option: "oxygen",
|
|
138
|
+
cloze: null,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
option: "hydrogen",
|
|
142
|
+
cloze: null,
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const sourceResp = {
|
|
150
|
+
status_code: 200,
|
|
151
|
+
usage_data: {
|
|
152
|
+
prompt_tokens: 9781,
|
|
153
|
+
completion_tokens: 1915,
|
|
154
|
+
total_tokens: 11696,
|
|
155
|
+
},
|
|
156
|
+
generated_content: {
|
|
157
|
+
missing_concepts: [
|
|
158
|
+
"Faraday's laws of electrolysis",
|
|
159
|
+
"Humphry Davy",
|
|
160
|
+
"Electrolytic cell",
|
|
161
|
+
"Decomposition potential",
|
|
162
|
+
"Oxidation",
|
|
163
|
+
"Reduction",
|
|
164
|
+
"Electrolysis of seawater",
|
|
165
|
+
"Electrometallurgy",
|
|
166
|
+
"Electroplating",
|
|
167
|
+
"Electrochemical machining",
|
|
168
|
+
"Electrochemistry",
|
|
169
|
+
"Electrocatalysis",
|
|
170
|
+
"Electrorefining",
|
|
171
|
+
"Electrolysis of carbon dioxide",
|
|
172
|
+
"Energy changes during electrolysis",
|
|
173
|
+
"Electrocrystallization",
|
|
174
|
+
"Electrolysis of Iron Ore",
|
|
175
|
+
],
|
|
176
|
+
missing_facts: [
|
|
177
|
+
"Michael Faraday introduced the term 'electrolysis' in 1834",
|
|
178
|
+
"The first demonstration of key electrolysis concepts was by William Nicholson and Anthony Carlisle in the early nineteenth century",
|
|
179
|
+
"Humphry Davy discovered several alkali and alkaline earth metals by electrolysis",
|
|
180
|
+
"Electrolysis played a key role in isolating and identifying new elements like lithium, chlorine, and fluorine",
|
|
181
|
+
"The Hall–Héroult process led to a significant drop in the price of aluminum",
|
|
182
|
+
"Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water",
|
|
183
|
+
"The electrolysis of seawater can result in the production of alkali hydroxides",
|
|
184
|
+
"Electrometallurgy is used in the production of various metals",
|
|
185
|
+
"Electroplating involves the deposition of a thin metal film onto a substrate material",
|
|
186
|
+
"Electrochemical machining is used for deburring or etching metal surfaces",
|
|
187
|
+
"Electrocatalysis involves the acceleration of electrochemical reactions",
|
|
188
|
+
"Electrorefining is used to obtain pure metals from impure ones",
|
|
189
|
+
"The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
|
|
190
|
+
"Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses",
|
|
191
|
+
"Electrocrystallization is a method for obtaining conductive crystals using electrolysis",
|
|
192
|
+
"Electrolysis of Iron Ore can eventually result in the reduction of emissions from steel production",
|
|
193
|
+
],
|
|
194
|
+
test_cards: [
|
|
195
|
+
{
|
|
196
|
+
type: "flash",
|
|
197
|
+
card_content: {
|
|
198
|
+
front: "Who introduced the term 'electrolysis' and in which year?",
|
|
199
|
+
back: "Michael Faraday introduced the term 'electrolysis' in 1834",
|
|
200
|
+
},
|
|
201
|
+
card_reference: "Electrolysis#Etymology",
|
|
202
|
+
concepts: [],
|
|
203
|
+
facts: ["Michael Faraday introduced the term 'electrolysis' in 1834"],
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
type: "flash",
|
|
207
|
+
card_content: {
|
|
208
|
+
front: "What was the significance of the Hall–Héroult process?",
|
|
209
|
+
back: "The Hall–Héroult process led to a significant drop in the price of aluminum",
|
|
210
|
+
},
|
|
211
|
+
card_reference: "Electrolysis#Industrial uses",
|
|
212
|
+
concepts: ["Hall–Héroult process"],
|
|
213
|
+
facts: [
|
|
214
|
+
"The Hall–Héroult process led to a significant drop in the price of aluminum",
|
|
215
|
+
],
|
|
216
|
+
},
|
|
217
|
+
{
|
|
218
|
+
type: "mcq",
|
|
219
|
+
card_content: {
|
|
220
|
+
prompt: "What does the electrolysis of water produce?",
|
|
221
|
+
choices: [
|
|
222
|
+
{
|
|
223
|
+
choice: "Oxygen and carbon dioxide",
|
|
224
|
+
is_correct: false,
|
|
225
|
+
},
|
|
226
|
+
{
|
|
227
|
+
choice: "Hydrogen and oxygen",
|
|
228
|
+
is_correct: true,
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
choice: "Nitrogen and helium",
|
|
232
|
+
is_correct: false,
|
|
233
|
+
},
|
|
234
|
+
],
|
|
235
|
+
},
|
|
236
|
+
card_reference: "Electrolysis#Process of electrolysis",
|
|
237
|
+
concepts: ["Electrometallurgy"],
|
|
238
|
+
facts: [
|
|
239
|
+
"Hydrogen and oxygen are produced in a 2:1 ratio by the electrolysis of water",
|
|
240
|
+
],
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
type: "cloze",
|
|
244
|
+
card_content: {
|
|
245
|
+
prompt:
|
|
246
|
+
"Electrolysis is the passing of a direct electric current through an {{c0:electrolyte}} producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
247
|
+
options: [
|
|
248
|
+
{
|
|
249
|
+
option: "electrolyte",
|
|
250
|
+
cloze: "c0",
|
|
251
|
+
},
|
|
252
|
+
{
|
|
253
|
+
option: "anode",
|
|
254
|
+
cloze: "null",
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
option: "cathode",
|
|
258
|
+
cloze: "null",
|
|
259
|
+
},
|
|
260
|
+
],
|
|
261
|
+
},
|
|
262
|
+
card_reference: "Electrolysis#Overview",
|
|
263
|
+
concepts: [],
|
|
264
|
+
facts: [],
|
|
265
|
+
},
|
|
266
|
+
{
|
|
267
|
+
type: "match",
|
|
268
|
+
card_content: {
|
|
269
|
+
"right_choice 1": "Electrometallurgy",
|
|
270
|
+
"right_choice 2": "Electroplating",
|
|
271
|
+
"right_choice 3": "Electrochemical machining",
|
|
272
|
+
"right_choice 4": "Electrochemistry",
|
|
273
|
+
"right_choice 5": "Electrocatalysis",
|
|
274
|
+
"right_choice 6": "Electrorefining",
|
|
275
|
+
"right_choice 7": "Electrolysis of carbon dioxide",
|
|
276
|
+
"right_choice 8": "Energy changes during electrolysis",
|
|
277
|
+
Electrometallurgy:
|
|
278
|
+
"The process of producing metals using electricity",
|
|
279
|
+
Electroplating:
|
|
280
|
+
"Deposition of thin metal film onto a substrate material",
|
|
281
|
+
"Electrochemical machining": "Deburring or etching metal surfaces",
|
|
282
|
+
Electrochemistry:
|
|
283
|
+
"Study of the interchange of chemical and electrical energy",
|
|
284
|
+
Electrocatalysis: "Acceleration of electrochemical reactions",
|
|
285
|
+
Electrorefining: "Obtaining pure metals from impure ones",
|
|
286
|
+
},
|
|
287
|
+
card_reference: "Electrolysis#Industrial uses",
|
|
288
|
+
concepts: [
|
|
289
|
+
"Electrometallurgy",
|
|
290
|
+
"Electroplating",
|
|
291
|
+
"Electrochemical machining",
|
|
292
|
+
"Electrochemistry",
|
|
293
|
+
"Electrocatalysis",
|
|
294
|
+
"Electrorefining",
|
|
295
|
+
"Electrolysis of carbon dioxide",
|
|
296
|
+
"Energy changes during electrolysis",
|
|
297
|
+
],
|
|
298
|
+
facts: [
|
|
299
|
+
"Electrometallurgy is used in the production of various metals",
|
|
300
|
+
"Electroplating involves the deposition of a thin metal film onto a substrate material",
|
|
301
|
+
"Electrochemical machining is used for deburring or etching metal surfaces",
|
|
302
|
+
"Electrochemistry is the study of the interchange of chemical and electrical energy",
|
|
303
|
+
"Electrocatalysis involves the acceleration of electrochemical reactions",
|
|
304
|
+
"Electrorefining is used to obtain pure metals from impure ones",
|
|
305
|
+
"The electrolysis of carbon dioxide can produce methane, ethylene, or ethanol",
|
|
306
|
+
"Energy changes during electrolysis involve the addition of electrical energy, equal to the change in Gibbs free energy plus system losses",
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
type: "mcq",
|
|
311
|
+
card_content: {
|
|
312
|
+
prompt: "What is a key application of electrolysis?",
|
|
313
|
+
choices: [
|
|
314
|
+
{
|
|
315
|
+
choice: "Production of metal from ore",
|
|
316
|
+
is_correct: false,
|
|
317
|
+
},
|
|
318
|
+
{
|
|
319
|
+
choice: "Pulsing current results",
|
|
320
|
+
is_correct: false,
|
|
321
|
+
},
|
|
322
|
+
{
|
|
323
|
+
choice: "Generating electrical potential",
|
|
324
|
+
is_correct: false,
|
|
325
|
+
},
|
|
326
|
+
{
|
|
327
|
+
choice: "Production of chlorine and sodium hydroxide",
|
|
328
|
+
is_correct: true,
|
|
329
|
+
},
|
|
330
|
+
],
|
|
331
|
+
},
|
|
332
|
+
card_reference: "Electrolysis#Industrial uses",
|
|
333
|
+
concepts: ["Electrochemistry", "Electrocatalysis", "Electrorefining"],
|
|
334
|
+
facts: [
|
|
335
|
+
"Production of chlorine and sodium hydroxide, called the Chloralkali process",
|
|
336
|
+
],
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
type: "cloze",
|
|
340
|
+
card_content: {
|
|
341
|
+
prompt:
|
|
342
|
+
"Oxidation of ions or neutral molecules occurs at the {{c0:anode}}. Reduction of ions or neutral molecules occurs at the {{c1:cathode}}.",
|
|
343
|
+
options: [
|
|
344
|
+
{
|
|
345
|
+
option: "anode",
|
|
346
|
+
cloze: "c0",
|
|
347
|
+
},
|
|
348
|
+
{
|
|
349
|
+
option: "cathode",
|
|
350
|
+
cloze: "c1",
|
|
351
|
+
},
|
|
352
|
+
{
|
|
353
|
+
option: "electrolyte",
|
|
354
|
+
cloze: "null",
|
|
355
|
+
},
|
|
356
|
+
],
|
|
357
|
+
},
|
|
358
|
+
card_reference:
|
|
359
|
+
"Electrolysis#Oxidation and reduction at the electrodes",
|
|
360
|
+
concepts: ["Oxidation", "Reduction"],
|
|
361
|
+
facts: [],
|
|
362
|
+
},
|
|
363
|
+
{
|
|
364
|
+
type: "match",
|
|
365
|
+
card_content: {
|
|
366
|
+
"right_choice 1": "Electrolysis",
|
|
367
|
+
"right_choice 2": "Electrocrystallization",
|
|
368
|
+
"right_choice 3": "Electrolysis of Iron Ore",
|
|
369
|
+
"right_choice 4": "Electrolysis of seawater",
|
|
370
|
+
"right_choice 5": "Electrometallurgy",
|
|
371
|
+
},
|
|
372
|
+
card_reference: "Electrolysis#Research trends",
|
|
373
|
+
concepts: [
|
|
374
|
+
"Electrolysis",
|
|
375
|
+
"Electrocrystallization",
|
|
376
|
+
"Electrolysis of Iron Ore",
|
|
377
|
+
"Electrolysis of seawater",
|
|
378
|
+
"Electrometallurgy",
|
|
379
|
+
],
|
|
380
|
+
facts: [],
|
|
381
|
+
},
|
|
382
|
+
],
|
|
383
|
+
},
|
|
384
|
+
generated_at: 1718625081,
|
|
385
|
+
type: "card_gen",
|
|
386
|
+
};
|