only_ever_generator 0.5.2 → 0.5.4
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/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.js +2 -2
- package/dist/card_gen/generate_cards.js.map +1 -0
- package/dist/constants/api_constants.js.map +1 -0
- package/dist/constants/prompt_data.js.map +1 -0
- package/dist/constants/prompts/card_gen_prompt.js +93 -164
- package/dist/constants/prompts/card_gen_prompt.js.map +1 -0
- package/dist/constants/prompts/typology_prompt.js +21 -20
- package/dist/constants/prompts/typology_prompt.js.map +1 -0
- package/dist/constants/source_data.js.map +1 -0
- package/dist/gap_fill/calculate_gap_fill.js.map +1 -0
- package/dist/index.js +17 -22
- package/dist/parse/parse_card/parse_cloze_card.js +55 -18
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -0
- package/dist/parse/parse_card/parse_match_card.js +30 -8
- package/dist/parse/parse_card/parse_match_card.js.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.js +1 -1
- package/dist/parse/parse_card/parse_mcq_card.js.map +1 -0
- package/dist/parse/parse_card_response.js +35 -3
- package/dist/parse/parse_card_response.js.map +1 -0
- package/dist/parse/parse_source_content.js.map +1 -0
- package/dist/parse/response_format_card.js.map +1 -0
- package/dist/parse/response_format_typology.js.map +1 -0
- package/dist/services/open_ai_service.js.map +1 -0
- package/dist/typology_gen/generate_typology.js.map +1 -0
- package/dist/utils/generate_args.js.map +1 -0
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +1 -1
- package/prompts.json +23 -0
- package/src/bootstrap/app.ts +7 -1
- package/src/card_gen/generate_cards.ts +2 -2
- package/src/constants/prompts/card_gen_prompt.ts +93 -164
- package/src/constants/prompts/typology_prompt.ts +21 -20
- package/src/index.ts +13 -24
- package/src/parse/parse_card/parse_cloze_card.ts +51 -17
- package/src/parse/parse_card/parse_match_card.ts +42 -7
- package/src/parse/parse_card/parse_mcq_card.ts +1 -1
- package/src/parse/parse_card_response.ts +39 -3
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { match } from "assert";
|
|
2
2
|
|
|
3
|
+
type InputItem = {
|
|
4
|
+
left_item: string;
|
|
5
|
+
right_item: string;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
type OutputItem = {
|
|
9
|
+
left_item: string;
|
|
10
|
+
right_item: string[];
|
|
11
|
+
};
|
|
12
|
+
|
|
3
13
|
export class ParseMatchCard {
|
|
4
14
|
parse(cardData: any) {
|
|
5
15
|
try {
|
|
6
16
|
let content = cardData.card_content;
|
|
17
|
+
const finalContent =this._parseMatchContent(content);
|
|
7
18
|
|
|
8
19
|
let displayTitle = this._generateMatchCardDisplayTitle(content);
|
|
9
20
|
let matchCard = {
|
|
@@ -11,8 +22,8 @@ export class ParseMatchCard {
|
|
|
11
22
|
category: "learning",
|
|
12
23
|
sub_type: cardData.type,
|
|
13
24
|
},
|
|
14
|
-
heading:
|
|
15
|
-
content:
|
|
25
|
+
heading:"",
|
|
26
|
+
content: finalContent,
|
|
16
27
|
// content: cardData.card_content,
|
|
17
28
|
displayTitle: displayTitle,
|
|
18
29
|
concepts: cardData.concepts,
|
|
@@ -26,11 +37,13 @@ export class ParseMatchCard {
|
|
|
26
37
|
}
|
|
27
38
|
}
|
|
28
39
|
|
|
40
|
+
|
|
41
|
+
|
|
29
42
|
_generateMatchCardDisplayTitle(answers: any) {
|
|
30
43
|
let titles: string[] = [];
|
|
31
44
|
let counter = 65;
|
|
32
45
|
for (let data of answers) {
|
|
33
|
-
let value = data.right_item
|
|
46
|
+
let value = data.right_item;
|
|
34
47
|
let leftData = data.left_item;
|
|
35
48
|
let letter = String.fromCharCode(counter);
|
|
36
49
|
titles.push(`${letter}. ${leftData} -- ${value}`);
|
|
@@ -40,16 +53,38 @@ export class ParseMatchCard {
|
|
|
40
53
|
return displayTitle;
|
|
41
54
|
}
|
|
42
55
|
|
|
56
|
+
_parseMatchContent = (input: InputItem[]): OutputItem[] => {
|
|
57
|
+
const grouped = input.reduce<Record<string, OutputItem>>((acc, { left_item, right_item }) => {
|
|
58
|
+
if (!acc[left_item]) {
|
|
59
|
+
acc[left_item] = { left_item, right_item: [] };
|
|
60
|
+
}
|
|
61
|
+
acc[left_item].right_item.push(right_item);
|
|
62
|
+
return acc;
|
|
63
|
+
}, {});
|
|
64
|
+
|
|
65
|
+
return Object.values(grouped);
|
|
66
|
+
};
|
|
67
|
+
|
|
43
68
|
_validateMatch(matchCard: any){
|
|
44
69
|
let matches = matchCard.content;
|
|
70
|
+
let content = [];
|
|
45
71
|
try{
|
|
72
|
+
if(matches.length < 1 || matches.length > 8){
|
|
73
|
+
throw Error("Invalid number of matches");
|
|
74
|
+
}
|
|
75
|
+
|
|
46
76
|
for(let elem of matches){
|
|
47
|
-
if(elem.left_item.length
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
throw Error(" Invalid Length of right item")
|
|
77
|
+
if(elem.left_item.length <= 30 && elem.left_item.length != 0){
|
|
78
|
+
if(elem.right_item.length <= 40 && elem.right_item.length != 0){
|
|
79
|
+
content.push(elem);
|
|
51
80
|
}
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if(content.length >= 2){
|
|
84
|
+
matchCard.content = content;
|
|
52
85
|
|
|
86
|
+
}else{
|
|
87
|
+
throw Error("Invalid content");
|
|
53
88
|
}
|
|
54
89
|
return matchCard;
|
|
55
90
|
}catch(e){
|
|
@@ -4,7 +4,7 @@ import { ParseMatchCard } from "./parse_card/parse_match_card";
|
|
|
4
4
|
import { ParseMcqCard } from "./parse_card/parse_mcq_card";
|
|
5
5
|
|
|
6
6
|
export class ParseCardResponse {
|
|
7
|
-
parse(generatedData: any, isGapFill: boolean) {
|
|
7
|
+
parse(generatedData: any, isGapFill: boolean, sourceTaxonomy: any) {
|
|
8
8
|
let usage_data = generatedData.metadata;
|
|
9
9
|
try {
|
|
10
10
|
const cardData = [];
|
|
@@ -15,21 +15,25 @@ export class ParseCardResponse {
|
|
|
15
15
|
if (elem.type == "flash") {
|
|
16
16
|
const flashCard = this.parseFlashCard(elem);
|
|
17
17
|
if (flashCard != null && flashCard) {
|
|
18
|
-
this.
|
|
18
|
+
flashCard.heading = this._getCardReference(flashCard, sourceTaxonomy);
|
|
19
|
+
cardData.push(flashCard);
|
|
19
20
|
}
|
|
20
21
|
} else if (elem.type == "mcq") {
|
|
21
22
|
const mcqCard = new ParseMcqCard().parse(elem);
|
|
22
23
|
if (mcqCard != null && mcqCard) {
|
|
24
|
+
mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
|
|
23
25
|
cardData.push(mcqCard);
|
|
24
26
|
}
|
|
25
27
|
} else if (elem.type == "cloze") {
|
|
26
28
|
const clozeCard = new ParseClozeCard().parse(elem);
|
|
27
29
|
if (clozeCard && clozeCard != null) {
|
|
30
|
+
clozeCard.heading = this._getCardReference(clozeCard, sourceTaxonomy);
|
|
28
31
|
cardData.push(clozeCard);
|
|
29
32
|
}
|
|
30
33
|
} else if (elem.type == "match") {
|
|
31
34
|
const matchCard = new ParseMatchCard().parse(elem);
|
|
32
35
|
if (matchCard && matchCard != null) {
|
|
36
|
+
matchCard.heading = this._getCardReference(matchCard, sourceTaxonomy);
|
|
33
37
|
cardData.push(matchCard);
|
|
34
38
|
}
|
|
35
39
|
}
|
|
@@ -77,7 +81,7 @@ export class ParseCardResponse {
|
|
|
77
81
|
category: "learning",
|
|
78
82
|
sub_type: data.type,
|
|
79
83
|
},
|
|
80
|
-
heading:
|
|
84
|
+
heading : "",
|
|
81
85
|
displayTitle: displayTitle,
|
|
82
86
|
content: {
|
|
83
87
|
front_content: data.card_content.front,
|
|
@@ -97,4 +101,36 @@ export class ParseCardResponse {
|
|
|
97
101
|
generateFlashCardDisplayTitle(front: string, back: string) {
|
|
98
102
|
return `${front} ---- ${back}`;
|
|
99
103
|
}
|
|
104
|
+
|
|
105
|
+
_getCardReference(generatedCardData: any, sourceTaxonomy: any) {
|
|
106
|
+
const cardConcepts = generatedCardData.concepts ?? [];
|
|
107
|
+
const cardFacts = generatedCardData.facts ?? [];
|
|
108
|
+
const combinedCardFactsAndConcepts = [...cardConcepts, ...cardFacts];
|
|
109
|
+
|
|
110
|
+
const sourceConcepts = sourceTaxonomy.concepts ?? [];
|
|
111
|
+
const sourceFacts = sourceTaxonomy.facts ?? [];
|
|
112
|
+
|
|
113
|
+
const mappedSourceConcepts = sourceConcepts.map((elem: any) => {
|
|
114
|
+
return {
|
|
115
|
+
"text": elem.concept_text,
|
|
116
|
+
reference: elem.reference,
|
|
117
|
+
};
|
|
118
|
+
});
|
|
119
|
+
const mappedSourceFacts = sourceFacts.map((elem: any) => {
|
|
120
|
+
return {
|
|
121
|
+
"text": elem.fact_text,
|
|
122
|
+
reference: elem.reference,
|
|
123
|
+
};
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
const compinedConceptsAndFacts = [...mappedSourceConcepts, ...mappedSourceFacts];
|
|
127
|
+
const firstMatchedConcept = compinedConceptsAndFacts.find((elem: any) => combinedCardFactsAndConcepts.includes(elem.text));
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if(firstMatchedConcept){
|
|
131
|
+
return firstMatchedConcept.reference;
|
|
132
|
+
}else{
|
|
133
|
+
return "";
|
|
134
|
+
}
|
|
135
|
+
}
|
|
100
136
|
}
|