only_ever_generator 0.5.3 → 0.5.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.js +7 -2
- package/dist/card_gen/generate_cards.js +2 -2
- package/dist/constants/source_data.js +401 -1149
- package/dist/index.js +1 -1
- package/dist/parse/parse_card/parse_cloze_card.js +2 -2
- package/dist/parse/parse_card/parse_match_card.js +2 -2
- package/dist/parse/parse_card/parse_mcq_card.js +2 -2
- package/dist/parse/parse_card_response.js +35 -3
- package/package.json +1 -1
- package/src/bootstrap/app.ts +7 -1
- package/src/card_gen/generate_cards.ts +2 -2
- package/src/constants/source_data.ts +408 -1322
- package/src/index.ts +2 -2
- package/src/parse/parse_card/parse_cloze_card.ts +2 -2
- package/src/parse/parse_card/parse_match_card.ts +2 -2
- package/src/parse/parse_card/parse_mcq_card.ts +2 -2
- package/src/parse/parse_card_response.ts +39 -3
package/dist/index.js
CHANGED
|
@@ -50,7 +50,7 @@ Object.defineProperty(exports, "OnlyEverGenerator", { enumerable: true, get: fun
|
|
|
50
50
|
// "res_tokens": cardResp.usage_data?.completion_tokens,
|
|
51
51
|
// "model": '40-mini'
|
|
52
52
|
// };
|
|
53
|
-
// let parsedData = new ParseCardResponse().parse(cardResp,false);
|
|
53
|
+
// let parsedData = new ParseCardResponse().parse(cardResp,false, {});
|
|
54
54
|
// res.send(parsedData)
|
|
55
55
|
// });
|
|
56
56
|
// app.get("/typology", async (req, res) => {
|
|
@@ -24,7 +24,7 @@ class ParseClozeCard {
|
|
|
24
24
|
category: "learning",
|
|
25
25
|
sub_type: data.type,
|
|
26
26
|
},
|
|
27
|
-
heading:
|
|
27
|
+
heading: "",
|
|
28
28
|
displayTitle: displayTitle,
|
|
29
29
|
content: {
|
|
30
30
|
question: finalQuestion,
|
|
@@ -32,7 +32,7 @@ class ParseClozeCard {
|
|
|
32
32
|
},
|
|
33
33
|
concepts: data.concepts,
|
|
34
34
|
facts: data.facts,
|
|
35
|
-
|
|
35
|
+
explanation: data.card_content.explanation,
|
|
36
36
|
};
|
|
37
37
|
return this._validateCloze(clozeCardData);
|
|
38
38
|
}
|
|
@@ -24,13 +24,13 @@ class ParseMatchCard {
|
|
|
24
24
|
category: "learning",
|
|
25
25
|
sub_type: cardData.type,
|
|
26
26
|
},
|
|
27
|
-
heading:
|
|
27
|
+
heading: "",
|
|
28
28
|
content: finalContent,
|
|
29
29
|
// content: cardData.card_content,
|
|
30
30
|
displayTitle: displayTitle,
|
|
31
31
|
concepts: cardData.concepts,
|
|
32
32
|
facts: cardData.facts,
|
|
33
|
-
|
|
33
|
+
explanation: cardData.card_content.explanation,
|
|
34
34
|
};
|
|
35
35
|
return this._validateMatch(matchCard);
|
|
36
36
|
}
|
|
@@ -21,7 +21,7 @@ class ParseMcqCard {
|
|
|
21
21
|
category: "learning",
|
|
22
22
|
sub_type: data.type,
|
|
23
23
|
},
|
|
24
|
-
heading:
|
|
24
|
+
heading: "",
|
|
25
25
|
displayTitle: displayTitle,
|
|
26
26
|
content: {
|
|
27
27
|
question: data.card_content.prompt,
|
|
@@ -29,7 +29,7 @@ class ParseMcqCard {
|
|
|
29
29
|
},
|
|
30
30
|
concepts: data.concepts,
|
|
31
31
|
facts: data.facts,
|
|
32
|
-
|
|
32
|
+
explanation: data.card_content.explanation,
|
|
33
33
|
};
|
|
34
34
|
// return mcqCard;
|
|
35
35
|
const isValid = this._validate(mcqCard);
|
|
@@ -6,7 +6,7 @@ const parse_cloze_card_1 = require("./parse_card/parse_cloze_card");
|
|
|
6
6
|
const parse_match_card_1 = require("./parse_card/parse_match_card");
|
|
7
7
|
const parse_mcq_card_1 = require("./parse_card/parse_mcq_card");
|
|
8
8
|
class ParseCardResponse {
|
|
9
|
-
parse(generatedData, isGapFill) {
|
|
9
|
+
parse(generatedData, isGapFill, sourceTaxonomy) {
|
|
10
10
|
let usage_data = generatedData.metadata;
|
|
11
11
|
try {
|
|
12
12
|
const cardData = [];
|
|
@@ -17,24 +17,28 @@ class ParseCardResponse {
|
|
|
17
17
|
if (elem.type == "flash") {
|
|
18
18
|
const flashCard = this.parseFlashCard(elem);
|
|
19
19
|
if (flashCard != null && flashCard) {
|
|
20
|
+
flashCard.heading = this._getCardReference(flashCard, sourceTaxonomy);
|
|
20
21
|
cardData.push(flashCard);
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
else if (elem.type == "mcq") {
|
|
24
25
|
const mcqCard = new parse_mcq_card_1.ParseMcqCard().parse(elem);
|
|
25
26
|
if (mcqCard != null && mcqCard) {
|
|
27
|
+
mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
|
|
26
28
|
cardData.push(mcqCard);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
else if (elem.type == "cloze") {
|
|
30
32
|
const clozeCard = new parse_cloze_card_1.ParseClozeCard().parse(elem);
|
|
31
33
|
if (clozeCard && clozeCard != null) {
|
|
34
|
+
clozeCard.heading = this._getCardReference(clozeCard, sourceTaxonomy);
|
|
32
35
|
cardData.push(clozeCard);
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
38
|
else if (elem.type == "match") {
|
|
36
39
|
const matchCard = new parse_match_card_1.ParseMatchCard().parse(elem);
|
|
37
40
|
if (matchCard && matchCard != null) {
|
|
41
|
+
matchCard.heading = this._getCardReference(matchCard, sourceTaxonomy);
|
|
38
42
|
cardData.push(matchCard);
|
|
39
43
|
}
|
|
40
44
|
}
|
|
@@ -78,15 +82,15 @@ class ParseCardResponse {
|
|
|
78
82
|
category: "learning",
|
|
79
83
|
sub_type: data.type,
|
|
80
84
|
},
|
|
81
|
-
heading:
|
|
85
|
+
heading: "",
|
|
82
86
|
displayTitle: displayTitle,
|
|
83
87
|
content: {
|
|
84
88
|
front_content: data.card_content.front,
|
|
85
89
|
back_content: data.card_content.back,
|
|
86
90
|
},
|
|
87
91
|
concepts: data.concepts,
|
|
92
|
+
explanation: data.card_content.explanation,
|
|
88
93
|
facts: data.facts,
|
|
89
|
-
bloomLevel: data.bloom_level,
|
|
90
94
|
};
|
|
91
95
|
return flashCardData;
|
|
92
96
|
}
|
|
@@ -97,5 +101,33 @@ class ParseCardResponse {
|
|
|
97
101
|
generateFlashCardDisplayTitle(front, back) {
|
|
98
102
|
return `${front} ---- ${back}`;
|
|
99
103
|
}
|
|
104
|
+
_getCardReference(generatedCardData, sourceTaxonomy) {
|
|
105
|
+
var _a, _b, _c, _d;
|
|
106
|
+
const cardConcepts = (_a = generatedCardData.concepts) !== null && _a !== void 0 ? _a : [];
|
|
107
|
+
const cardFacts = (_b = generatedCardData.facts) !== null && _b !== void 0 ? _b : [];
|
|
108
|
+
const combinedCardFactsAndConcepts = [...cardConcepts, ...cardFacts];
|
|
109
|
+
const sourceConcepts = (_c = sourceTaxonomy.concepts) !== null && _c !== void 0 ? _c : [];
|
|
110
|
+
const sourceFacts = (_d = sourceTaxonomy.facts) !== null && _d !== void 0 ? _d : [];
|
|
111
|
+
const mappedSourceConcepts = sourceConcepts.map((elem) => {
|
|
112
|
+
return {
|
|
113
|
+
"text": elem.concept_text,
|
|
114
|
+
reference: elem.reference,
|
|
115
|
+
};
|
|
116
|
+
});
|
|
117
|
+
const mappedSourceFacts = sourceFacts.map((elem) => {
|
|
118
|
+
return {
|
|
119
|
+
"text": elem.fact_text,
|
|
120
|
+
reference: elem.reference,
|
|
121
|
+
};
|
|
122
|
+
});
|
|
123
|
+
const compinedConceptsAndFacts = [...mappedSourceConcepts, ...mappedSourceFacts];
|
|
124
|
+
const firstMatchedConcept = compinedConceptsAndFacts.find((elem) => combinedCardFactsAndConcepts.includes(elem.text));
|
|
125
|
+
if (firstMatchedConcept) {
|
|
126
|
+
return firstMatchedConcept.reference;
|
|
127
|
+
}
|
|
128
|
+
else {
|
|
129
|
+
return "";
|
|
130
|
+
}
|
|
131
|
+
}
|
|
100
132
|
}
|
|
101
133
|
exports.ParseCardResponse = ParseCardResponse;
|
package/package.json
CHANGED
package/src/bootstrap/app.ts
CHANGED
|
@@ -42,6 +42,7 @@ export class OnlyEverGenerator {
|
|
|
42
42
|
title: parsedData.title,
|
|
43
43
|
headings: parsedData.headings,
|
|
44
44
|
content: parsedData.content,
|
|
45
|
+
taxonomy: parsedData.taxonomy,
|
|
45
46
|
|
|
46
47
|
},
|
|
47
48
|
// parsedData.type == 'cards' ? this.typologyResponse = parsedData.taxonomy : this.typologyResponse = null;
|
|
@@ -70,6 +71,11 @@ export class OnlyEverGenerator {
|
|
|
70
71
|
} else if (elem == "generate_card") {
|
|
71
72
|
/// for cards gen to occur, there must be presence of source taxonomy
|
|
72
73
|
if(this.shouldTheCardBeGeneratedAfterTypologyResponse()){
|
|
74
|
+
this.parsedContent.taxonomy = {
|
|
75
|
+
concepts: this.typologyResponse.concepts,
|
|
76
|
+
facts: this.typologyResponse.facts,
|
|
77
|
+
generate_cards: this.typologyResponse.generate_cards,
|
|
78
|
+
};
|
|
73
79
|
this.cardgenResponse = await this.generateCard(
|
|
74
80
|
this.promptForCardGen,
|
|
75
81
|
JSON.stringify(this.typologyResponse),
|
|
@@ -128,7 +134,7 @@ export class OnlyEverGenerator {
|
|
|
128
134
|
prompt ?? "",
|
|
129
135
|
JSON.stringify(this.parsedContent) + additionalContent,
|
|
130
136
|
isGapFill,
|
|
131
|
-
this.parsedContent.
|
|
137
|
+
this.parsedContent.taxonomy,
|
|
132
138
|
);
|
|
133
139
|
|
|
134
140
|
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
@@ -12,7 +12,7 @@ export class GenerateCards {
|
|
|
12
12
|
prompt: string,
|
|
13
13
|
parsedContent: string,
|
|
14
14
|
isGapFill: boolean,
|
|
15
|
-
|
|
15
|
+
taxonomy: any
|
|
16
16
|
) {
|
|
17
17
|
let response = await this.openAiService?.sendRequest(prompt, parsedContent);
|
|
18
18
|
// console.log("response to card generation ", response);
|
|
@@ -26,7 +26,7 @@ export class GenerateCards {
|
|
|
26
26
|
};
|
|
27
27
|
if (response.status_code == 200) {
|
|
28
28
|
response.metadata.status = "completed";
|
|
29
|
-
let parseCard = new ParseCardResponse().parse(response,isGapFill);
|
|
29
|
+
let parseCard = new ParseCardResponse().parse(response,isGapFill, taxonomy);
|
|
30
30
|
return parseCard;
|
|
31
31
|
} else {
|
|
32
32
|
response.metadata.status = "failed";
|