only_ever_generator 1.0.7 → 1.0.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.
- package/dist/bootstrap/app.d.ts +29 -6
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +82 -19
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +2 -1
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +21 -4
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/prompt_data.d.ts +0 -1
- package/dist/constants/prompts/card_gen_prompt.js.map +1 -1
- package/dist/constants/source_data.d.ts +0 -2
- package/dist/constants/source_data.js +1 -1
- package/dist/constants/source_data.js.map +1 -1
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts +1 -1
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts.map +1 -1
- package/dist/embedding_generation/consolidation/global_consolidation.js +1 -1
- package/dist/embedding_generation/consolidation/global_consolidation.js.map +1 -1
- package/dist/embedding_generation/consolidation/local_consolidation.d.ts.map +1 -1
- package/dist/embedding_generation/local_consolidation.js +104 -0
- package/dist/enums/card_type_enum.d.ts +7 -0
- package/dist/enums/card_type_enum.d.ts.map +1 -0
- package/dist/enums/card_type_enum.js +11 -0
- package/dist/enums/card_type_enum.js.map +1 -0
- package/dist/helper/openai_helper.d.ts +12 -0
- package/dist/helper/openai_helper.d.ts.map +1 -0
- package/dist/helper/openai_helper.js +26 -0
- package/dist/helper/openai_helper.js.map +1 -0
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +923 -87
- package/dist/index.js.map +1 -1
- package/dist/parse/parse_card/parse_cloze_card.d.ts +8 -1
- package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -1
- package/dist/parse/parse_card/parse_cloze_card.js +2 -2
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -1
- package/dist/parse/parse_card/parse_flash_cards.d.ts +14 -7
- package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -1
- package/dist/parse/parse_card/parse_flash_cards.js +3 -3
- package/dist/parse/parse_card/parse_flash_cards.js.map +1 -1
- package/dist/parse/parse_card/parse_match_card.d.ts +8 -1
- package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -1
- package/dist/parse/parse_card/parse_match_card.js +2 -3
- package/dist/parse/parse_card/parse_match_card.js.map +1 -1
- package/dist/parse/parse_card/parse_mcq_card.d.ts +15 -8
- package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -1
- package/dist/parse/parse_card/parse_mcq_card.js +2 -2
- package/dist/parse/parse_card/parse_mcq_card.js.map +1 -1
- package/dist/parse/parse_card_response.d.ts +12 -10
- package/dist/parse/parse_card_response.d.ts.map +1 -1
- package/dist/parse/parse_card_response.js +121 -54
- package/dist/parse/parse_card_response.js.map +1 -1
- package/dist/parse/parse_source_content.d.ts +7 -5
- package/dist/parse/parse_source_content.d.ts.map +1 -1
- package/dist/parse/parse_source_content.js +1 -0
- package/dist/parse/parse_source_content.js.map +1 -1
- package/dist/parse/response_format_card.d.ts +0 -1
- package/dist/parse/response_format_typology.d.ts +0 -1
- package/dist/types/base_param_type.d.ts +17 -0
- package/dist/types/base_param_type.d.ts.map +1 -0
- package/dist/types/base_param_type.js +3 -0
- package/dist/types/base_param_type.js.map +1 -0
- package/dist/types/mongo_concept_fact_type.d.ts +12 -0
- package/dist/types/mongo_concept_fact_type.d.ts.map +1 -0
- package/dist/types/mongo_concept_fact_type.js +3 -0
- package/dist/types/mongo_concept_fact_type.js.map +1 -0
- package/dist/types/parsed_card_type.d.ts +12 -0
- package/dist/types/parsed_card_type.d.ts.map +1 -0
- package/dist/types/parsed_card_type.js +30 -0
- package/dist/types/parsed_card_type.js.map +1 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.d.ts +40 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.d.ts.map +1 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.js +8 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.js.map +1 -0
- package/dist/types/source_taxonomy_type.d.ts +15 -0
- package/dist/types/source_taxonomy_type.d.ts.map +1 -0
- package/dist/types/source_taxonomy_type.js +3 -0
- package/dist/types/source_taxonomy_type.js.map +1 -0
- package/dist/typology_gen/generate_concept_facts.d.ts +18 -0
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -0
- package/dist/typology_gen/generate_concept_facts.js +48 -0
- package/dist/typology_gen/generate_concept_facts.js.map +1 -0
- package/dist/typology_gen/generate_typology.d.ts +9 -3
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +43 -31
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/package.json +9 -9
- package/src/bootstrap/app.ts +129 -29
- package/src/card_gen/generate_cards.ts +27 -5
- package/src/constants/prompts/card_gen_prompt.ts +1 -1
- package/src/embedding_generation/consolidation/global_consolidation.ts +2 -2
- package/src/enums/card_type_enum.ts +6 -0
- package/src/helper/openai_helper.ts +31 -0
- package/src/index.ts +947 -101
- package/src/parse/parse_card/parse_cloze_card.ts +11 -3
- package/src/parse/parse_card/parse_flash_cards.ts +12 -4
- package/src/parse/parse_card/parse_match_card.ts +10 -4
- package/src/parse/parse_card/parse_mcq_card.ts +11 -3
- package/src/parse/parse_card_response.ts +94 -20
- package/src/parse/parse_source_content.ts +11 -1
- package/src/types/base_param_type.ts +17 -0
- package/src/types/mongo_concept_fact_type.ts +12 -0
- package/src/types/parsed_card_type.ts +39 -0
- package/src/types/raw_card_response_types/generated_card_response_type.ts +61 -0
- package/src/types/source_taxonomy_type.ts +17 -0
- package/src/typology_gen/generate_concept_facts.ts +54 -0
- package/src/typology_gen/generate_typology.ts +59 -36
- package/.env.example +0 -1
- package/dist/constants/prompt_data.d.ts.map +0 -1
- package/dist/constants/source_data.d.ts.map +0 -1
- package/dist/parse/response_format_card.d.ts.map +0 -1
- package/dist/parse/response_format_typology.d.ts.map +0 -1
- package/prompts.json +0 -23
- package/readme.md +0 -35
- package/src/constants/prompt_data.ts +0 -301
- package/src/constants/source_data.ts +0 -1036
- package/src/parse/response_format_card.ts +0 -386
- package/src/parse/response_format_typology.ts +0 -44
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { MongoConceptFactCards } from "../../types/mongo_concept_fact_type";
|
|
2
|
+
import { RawClozeCardResponseType } from "../../types/raw_card_response_types/generated_card_response_type";
|
|
3
|
+
|
|
1
4
|
export class ParseClozeCard {
|
|
2
|
-
parse(data:
|
|
5
|
+
parse(data: {
|
|
6
|
+
card_content: RawClozeCardResponseType;
|
|
7
|
+
type: string;
|
|
8
|
+
concepts_facts: MongoConceptFactCards[];
|
|
9
|
+
bloom_level: number;
|
|
10
|
+
}) {
|
|
3
11
|
try {
|
|
4
12
|
const content = data.card_content;
|
|
5
13
|
let correctOptions = content.correct_options;
|
|
@@ -36,9 +44,9 @@ export class ParseClozeCard {
|
|
|
36
44
|
question: finalQuestion,
|
|
37
45
|
options: finalParsedOptions,
|
|
38
46
|
},
|
|
39
|
-
|
|
40
|
-
facts: data.facts,
|
|
47
|
+
concepts_facts: data.concepts_facts,
|
|
41
48
|
explanation: data.card_content.explanation,
|
|
49
|
+
bloom_level: data.bloom_level,
|
|
42
50
|
};
|
|
43
51
|
|
|
44
52
|
return this._validateCloze(clozeCardData);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { MongoConceptFactCards } from "../../types/mongo_concept_fact_type";
|
|
2
|
+
import { RawFlashCardResponseType } from "../../types/raw_card_response_types/generated_card_response_type";
|
|
3
|
+
|
|
1
4
|
export class ParseFlashCard {
|
|
2
|
-
parse(data:
|
|
5
|
+
parse(data: {
|
|
6
|
+
card_content: RawFlashCardResponseType;
|
|
7
|
+
type: string;
|
|
8
|
+
concepts_facts: MongoConceptFactCards[];
|
|
9
|
+
bloom_level: number;
|
|
10
|
+
}) {
|
|
3
11
|
try {
|
|
4
12
|
let displayTitle = this.generateFlashCardDisplayTitle(
|
|
5
13
|
data.card_content.front,
|
|
@@ -8,7 +16,7 @@ export class ParseFlashCard {
|
|
|
8
16
|
let flashCardData = {
|
|
9
17
|
type: {
|
|
10
18
|
category: "learning",
|
|
11
|
-
sub_type:
|
|
19
|
+
sub_type: "flash",
|
|
12
20
|
},
|
|
13
21
|
heading: "",
|
|
14
22
|
displayTitle: displayTitle,
|
|
@@ -16,9 +24,9 @@ export class ParseFlashCard {
|
|
|
16
24
|
front_content: data.card_content.front,
|
|
17
25
|
back_content: data.card_content.back,
|
|
18
26
|
},
|
|
19
|
-
|
|
27
|
+
concepts_facts: data.concepts_facts,
|
|
20
28
|
explanation: data.card_content.explanation,
|
|
21
|
-
|
|
29
|
+
bloom_level: data.bloom_level,
|
|
22
30
|
};
|
|
23
31
|
|
|
24
32
|
return flashCardData;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { match } from "assert";
|
|
2
|
+
import { RawMatchCardResponseType } from "../../types/raw_card_response_types/generated_card_response_type";
|
|
3
|
+
import { MongoConceptFactCards } from "../../types/mongo_concept_fact_type";
|
|
2
4
|
|
|
3
5
|
type InputItem = {
|
|
4
6
|
left_item: string;
|
|
@@ -11,7 +13,12 @@ type OutputItem = {
|
|
|
11
13
|
};
|
|
12
14
|
|
|
13
15
|
export class ParseMatchCard {
|
|
14
|
-
parse(cardData:
|
|
16
|
+
parse(cardData: {
|
|
17
|
+
card_content: RawMatchCardResponseType;
|
|
18
|
+
type: string;
|
|
19
|
+
concepts_facts: MongoConceptFactCards[];
|
|
20
|
+
bloom_level: number;
|
|
21
|
+
}) {
|
|
15
22
|
try {
|
|
16
23
|
let content = cardData.card_content;
|
|
17
24
|
const finalContent = this._parseMatchContent(content);
|
|
@@ -26,9 +33,8 @@ export class ParseMatchCard {
|
|
|
26
33
|
content: finalContent,
|
|
27
34
|
// content: cardData.card_content,
|
|
28
35
|
displayTitle: displayTitle,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
explanation: cardData.card_content.explanation,
|
|
36
|
+
concepts_facts: cardData.concepts_facts,
|
|
37
|
+
bloom_level: cardData.bloom_level,
|
|
32
38
|
};
|
|
33
39
|
|
|
34
40
|
return this._validateMatch(matchCard);
|
|
@@ -1,5 +1,13 @@
|
|
|
1
|
+
import { MongoConceptFactCards } from "../../types/mongo_concept_fact_type";
|
|
2
|
+
import { RawMcqCardResponseType } from "../../types/raw_card_response_types/generated_card_response_type";
|
|
3
|
+
|
|
1
4
|
export class ParseMcqCard {
|
|
2
|
-
parse(data:
|
|
5
|
+
parse(data: {
|
|
6
|
+
card_content: RawMcqCardResponseType;
|
|
7
|
+
type: string;
|
|
8
|
+
concepts_facts: MongoConceptFactCards[];
|
|
9
|
+
bloom_level: number;
|
|
10
|
+
}) {
|
|
3
11
|
try {
|
|
4
12
|
let mcqAnswers = [];
|
|
5
13
|
if (
|
|
@@ -30,9 +38,9 @@ export class ParseMcqCard {
|
|
|
30
38
|
question: data.card_content.prompt,
|
|
31
39
|
answers: mcqAnswers,
|
|
32
40
|
},
|
|
33
|
-
|
|
34
|
-
facts: data.facts,
|
|
41
|
+
concepts_facts: data.concepts_facts,
|
|
35
42
|
explanation: data.card_content.explanation,
|
|
43
|
+
bloom_level: data.bloom_level,
|
|
36
44
|
};
|
|
37
45
|
// return mcqCard;
|
|
38
46
|
const isValid = this._validate(mcqCard);
|
|
@@ -3,24 +3,60 @@ import { ParseClozeCard } from "./parse_card/parse_cloze_card";
|
|
|
3
3
|
import { ParseFlashCard } from "./parse_card/parse_flash_cards";
|
|
4
4
|
import { ParseMatchCard } from "./parse_card/parse_match_card";
|
|
5
5
|
import { ParseMcqCard } from "./parse_card/parse_mcq_card";
|
|
6
|
-
|
|
6
|
+
import {
|
|
7
|
+
GeneratedCardResponseType,
|
|
8
|
+
RawClozeCardResponseType,
|
|
9
|
+
RawFlashCardResponseType,
|
|
10
|
+
RawMatchCardResponseType,
|
|
11
|
+
RawMcqCardResponseType,
|
|
12
|
+
RawTestCardResponseType,
|
|
13
|
+
} from "../types/raw_card_response_types/generated_card_response_type";
|
|
14
|
+
import { SourceTaxonomy } from "../types/source_taxonomy_type";
|
|
15
|
+
import {
|
|
16
|
+
MongoConceptFactCards,
|
|
17
|
+
MongoConceptFactSource,
|
|
18
|
+
} from "../types/mongo_concept_fact_type";
|
|
19
|
+
import { ParsedCardType } from "../types/parsed_card_type";
|
|
7
20
|
export class ParseCardResponse {
|
|
8
|
-
parse(
|
|
21
|
+
async parse(
|
|
22
|
+
generatedData: GeneratedCardResponseType,
|
|
23
|
+
isGapFill: boolean,
|
|
24
|
+
sourceTaxonomy: SourceTaxonomy,
|
|
25
|
+
bloom_level: number
|
|
26
|
+
) {
|
|
9
27
|
let usage_data = generatedData.metadata;
|
|
10
28
|
try {
|
|
11
|
-
const cardData = [];
|
|
29
|
+
const cardData: ParsedCardType[] = [];
|
|
12
30
|
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
13
|
-
const type = generatedData.type;
|
|
14
31
|
|
|
15
32
|
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
16
33
|
for (let elem of unparsedTestCards) {
|
|
34
|
+
elem.bloom_level = bloom_level;
|
|
35
|
+
const concepts = (elem.concepts ?? []).map((e: any) => {
|
|
36
|
+
return {
|
|
37
|
+
text: e,
|
|
38
|
+
type: "concept",
|
|
39
|
+
};
|
|
40
|
+
});
|
|
41
|
+
const facts = (elem.facts ?? []).map((e: any) => {
|
|
42
|
+
return {
|
|
43
|
+
text: e,
|
|
44
|
+
type: "fact",
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
const concepts_facts = [...concepts, ...facts];
|
|
17
48
|
const managedCardConcepts = this._mapIdToConcepts(
|
|
18
|
-
|
|
49
|
+
concepts_facts,
|
|
19
50
|
sourceTaxonomy.concepts_facts
|
|
20
51
|
);
|
|
21
|
-
|
|
52
|
+
|
|
22
53
|
if (elem.type == "flash") {
|
|
23
|
-
const flashCard = new ParseFlashCard().parse(
|
|
54
|
+
const flashCard = new ParseFlashCard().parse({
|
|
55
|
+
card_content: elem.card_content as RawFlashCardResponseType,
|
|
56
|
+
type: elem.type,
|
|
57
|
+
concepts_facts: managedCardConcepts,
|
|
58
|
+
bloom_level: elem.bloom_level,
|
|
59
|
+
});
|
|
24
60
|
if (flashCard != null && flashCard) {
|
|
25
61
|
flashCard.heading = this._getCardReference(
|
|
26
62
|
flashCard,
|
|
@@ -30,13 +66,23 @@ export class ParseCardResponse {
|
|
|
30
66
|
cardData.push(flashCard);
|
|
31
67
|
}
|
|
32
68
|
} else if (elem.type == "mcq") {
|
|
33
|
-
const mcqCard = new ParseMcqCard().parse(
|
|
69
|
+
const mcqCard = new ParseMcqCard().parse({
|
|
70
|
+
card_content: elem.card_content as RawMcqCardResponseType,
|
|
71
|
+
type: elem.type,
|
|
72
|
+
concepts_facts: managedCardConcepts,
|
|
73
|
+
bloom_level: elem.bloom_level,
|
|
74
|
+
});
|
|
34
75
|
if (mcqCard != null && mcqCard) {
|
|
35
76
|
mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
|
|
36
77
|
cardData.push(mcqCard);
|
|
37
78
|
}
|
|
38
79
|
} else if (elem.type == "cloze") {
|
|
39
|
-
const clozeCard = new ParseClozeCard().parse(
|
|
80
|
+
const clozeCard = new ParseClozeCard().parse({
|
|
81
|
+
card_content: elem.card_content as RawClozeCardResponseType,
|
|
82
|
+
type: elem.type,
|
|
83
|
+
concepts_facts: managedCardConcepts,
|
|
84
|
+
bloom_level: elem.bloom_level,
|
|
85
|
+
});
|
|
40
86
|
if (clozeCard && clozeCard != null) {
|
|
41
87
|
clozeCard.heading = this._getCardReference(
|
|
42
88
|
clozeCard,
|
|
@@ -45,7 +91,12 @@ export class ParseCardResponse {
|
|
|
45
91
|
cardData.push(clozeCard);
|
|
46
92
|
}
|
|
47
93
|
} else if (elem.type == "match") {
|
|
48
|
-
const matchCard = new ParseMatchCard().parse(
|
|
94
|
+
const matchCard = new ParseMatchCard().parse({
|
|
95
|
+
card_content: elem.card_content as RawMatchCardResponseType,
|
|
96
|
+
type: elem.type,
|
|
97
|
+
concepts_facts: managedCardConcepts,
|
|
98
|
+
bloom_level: elem.bloom_level,
|
|
99
|
+
});
|
|
49
100
|
if (matchCard && matchCard != null) {
|
|
50
101
|
matchCard.heading = this._getCardReference(
|
|
51
102
|
matchCard,
|
|
@@ -67,27 +118,46 @@ export class ParseCardResponse {
|
|
|
67
118
|
return {
|
|
68
119
|
status_code: cardData.length == 0 ? 400 : 200,
|
|
69
120
|
metadata: usage_data,
|
|
70
|
-
type:
|
|
121
|
+
type: "card_gen",
|
|
71
122
|
|
|
72
123
|
cards_data: cardData,
|
|
73
124
|
};
|
|
74
125
|
} catch (e: any) {
|
|
126
|
+
await new ErrorLogger({
|
|
127
|
+
type: "card_parsing",
|
|
128
|
+
data: {
|
|
129
|
+
error: e.message,
|
|
130
|
+
generatedData: generatedData,
|
|
131
|
+
sourceTaxonomy: sourceTaxonomy,
|
|
132
|
+
},
|
|
133
|
+
}).log();
|
|
75
134
|
return {
|
|
76
135
|
status_code: 500,
|
|
77
136
|
metadata: usage_data,
|
|
78
|
-
type:
|
|
137
|
+
type: "card_gen",
|
|
79
138
|
};
|
|
80
139
|
}
|
|
81
140
|
}
|
|
82
141
|
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
142
|
+
_parseCard(generatedCardData: any, sourceTaxonomy: any) {
|
|
143
|
+
const cardData: ParsedCardType[] = [];
|
|
144
|
+
const concepts = (generatedCardData.concepts ?? []).map((e: any) => {
|
|
145
|
+
return {
|
|
146
|
+
text: e,
|
|
147
|
+
type: "concept",
|
|
148
|
+
};
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
_getCardReference(card: any, sourceTaxonomy: any) {
|
|
152
|
+
const cardConcepts = (card.concepts_facts ?? []) as MongoConceptFactCards[];
|
|
153
|
+
const sourceConceptsFacts = (sourceTaxonomy.concepts_facts ??
|
|
154
|
+
[]) as MongoConceptFactSource[];
|
|
155
|
+
if (cardConcepts.length == 0 || sourceConceptsFacts.length == 0) {
|
|
156
|
+
return "";
|
|
157
|
+
}
|
|
87
158
|
|
|
88
|
-
const
|
|
89
|
-
|
|
90
|
-
cardConcepts.includes(elem.text)
|
|
159
|
+
const firstMatchedConcept = sourceConceptsFacts.find(
|
|
160
|
+
(e: any) => cardConcepts[0].id == e.id
|
|
91
161
|
);
|
|
92
162
|
|
|
93
163
|
if (firstMatchedConcept) {
|
|
@@ -97,7 +167,10 @@ export class ParseCardResponse {
|
|
|
97
167
|
}
|
|
98
168
|
}
|
|
99
169
|
|
|
100
|
-
_mapIdToConcepts(
|
|
170
|
+
_mapIdToConcepts(
|
|
171
|
+
cardConcepts: any[],
|
|
172
|
+
sourceConceptsFacts: any[]
|
|
173
|
+
): MongoConceptFactCards[] {
|
|
101
174
|
// const cardData = cardC
|
|
102
175
|
const managedCardConcepts = [];
|
|
103
176
|
for (const cardConcept of cardConcepts) {
|
|
@@ -109,6 +182,7 @@ export class ParseCardResponse {
|
|
|
109
182
|
managedCardConcepts.push({
|
|
110
183
|
id: matchedConcept.id,
|
|
111
184
|
text: matchedConcept.text,
|
|
185
|
+
type: matchedConcept.type,
|
|
112
186
|
});
|
|
113
187
|
}
|
|
114
188
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { SourceTaxonomy } from "../types/source_taxonomy_type";
|
|
2
|
+
|
|
1
3
|
export class ParseSourceContent {
|
|
2
4
|
public content: any;
|
|
3
5
|
/// Format of Content
|
|
@@ -25,7 +27,14 @@ export class ParseSourceContent {
|
|
|
25
27
|
this.content = sourceContent;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
parseData() {
|
|
30
|
+
parseData(): {
|
|
31
|
+
source_id: string;
|
|
32
|
+
type: string;
|
|
33
|
+
title: string;
|
|
34
|
+
content: any[];
|
|
35
|
+
headings: string[];
|
|
36
|
+
taxonomy: SourceTaxonomy;
|
|
37
|
+
} {
|
|
29
38
|
let sourceType = this.content.type;
|
|
30
39
|
let afterSanitized;
|
|
31
40
|
if (sourceType == "video") {
|
|
@@ -37,6 +46,7 @@ export class ParseSourceContent {
|
|
|
37
46
|
afterSanitized = this.sanitizeBlocks(dataAfterRemovingUnWantedBlocks);
|
|
38
47
|
}
|
|
39
48
|
return {
|
|
49
|
+
source_id: this.content.source_id,
|
|
40
50
|
type: this.content.type,
|
|
41
51
|
title: this.content.title,
|
|
42
52
|
content: afterSanitized,
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { SourceTaxonomy } from "./source_taxonomy_type";
|
|
2
|
+
|
|
3
|
+
export type BaseParamType = {
|
|
4
|
+
prompt: {
|
|
5
|
+
typology: string;
|
|
6
|
+
card_generation: string;
|
|
7
|
+
};
|
|
8
|
+
content: {
|
|
9
|
+
source_id: string;
|
|
10
|
+
title: string;
|
|
11
|
+
headings: string[];
|
|
12
|
+
content: any[];
|
|
13
|
+
fields: string[];
|
|
14
|
+
taxonomy?: SourceTaxonomy;
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type ParsedCardType = {
|
|
2
|
+
type: {
|
|
3
|
+
category: string;
|
|
4
|
+
sub_type: string;
|
|
5
|
+
};
|
|
6
|
+
heading: string;
|
|
7
|
+
displayTitle: string;
|
|
8
|
+
content: any;
|
|
9
|
+
explanation?: string;
|
|
10
|
+
bloom_level?: number;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// {
|
|
14
|
+
// "type": {
|
|
15
|
+
// "category": "learning",
|
|
16
|
+
// "sub_type": "cloze"
|
|
17
|
+
// },
|
|
18
|
+
// "heading": "",
|
|
19
|
+
// "displayTitle": "Ink is a medium that consists of colorants and other {{components}}. ---- components, elements, substances",
|
|
20
|
+
// "content": {
|
|
21
|
+
// "question": "Ink is a medium that consists of colorants and other {{c0:components}}.",
|
|
22
|
+
// "options": [
|
|
23
|
+
// {
|
|
24
|
+
// "option": "components",
|
|
25
|
+
// "cloze": "c0"
|
|
26
|
+
// },
|
|
27
|
+
// {
|
|
28
|
+
// "option": "elements",
|
|
29
|
+
// "cloze": "null"
|
|
30
|
+
// },
|
|
31
|
+
// {
|
|
32
|
+
// "option": "substances",
|
|
33
|
+
// "cloze": "null"
|
|
34
|
+
// }
|
|
35
|
+
// ]
|
|
36
|
+
// },
|
|
37
|
+
// "explanation": "Ink contains various components that include colorants, solvents, and additives which determine its properties.",
|
|
38
|
+
// "bloom_level": 1
|
|
39
|
+
// },
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { CardTypeEnum } from "../../enums/card_type_enum";
|
|
2
|
+
|
|
3
|
+
export type GeneratedCardResponseType = {
|
|
4
|
+
metadata: any;
|
|
5
|
+
generated_content: {
|
|
6
|
+
test_cards: RawTestCardResponseType[];
|
|
7
|
+
};
|
|
8
|
+
status_code: number;
|
|
9
|
+
usage_data: any;
|
|
10
|
+
generated_at: Date;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type RawTestCardResponseType = {
|
|
14
|
+
type: string;
|
|
15
|
+
// type:
|
|
16
|
+
// | CardTypeEnum.FLASH
|
|
17
|
+
// | CardTypeEnum.MATCH
|
|
18
|
+
// | CardTypeEnum.MCQ
|
|
19
|
+
// | CardTypeEnum.CLOZE;
|
|
20
|
+
card_content:
|
|
21
|
+
| RawFlashCardResponseType
|
|
22
|
+
| RawMatchCardResponseType
|
|
23
|
+
| RawClozeCardResponseType
|
|
24
|
+
| RawMcqCardResponseType;
|
|
25
|
+
concepts: string[];
|
|
26
|
+
facts: string[];
|
|
27
|
+
bloom_level: number;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export type RawFlashCardResponseType = {
|
|
31
|
+
front: string;
|
|
32
|
+
back: string;
|
|
33
|
+
explanation?: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type RawMatchCardResponseType = {
|
|
37
|
+
left_item: string;
|
|
38
|
+
right_item: string;
|
|
39
|
+
}[];
|
|
40
|
+
|
|
41
|
+
export type RawClozeCardResponseType = {
|
|
42
|
+
correct_options: string[];
|
|
43
|
+
incorrect_options: string[];
|
|
44
|
+
prompt: string;
|
|
45
|
+
explanation?: string;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export type RawMcqCardResponseType = {
|
|
49
|
+
prompt: string;
|
|
50
|
+
explanation?: string;
|
|
51
|
+
choices: {
|
|
52
|
+
choice: string;
|
|
53
|
+
is_correct: boolean;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
//
|
|
58
|
+
// flash : 1
|
|
59
|
+
// cloze 0,
|
|
60
|
+
// match 2
|
|
61
|
+
// mcq 3
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export type SourceTaxonomy = {
|
|
2
|
+
concepts_facts: {
|
|
3
|
+
text: string;
|
|
4
|
+
type: string;
|
|
5
|
+
/// will only be present temporarily and wont be stored in database
|
|
6
|
+
embedding?: number[];
|
|
7
|
+
reference: string;
|
|
8
|
+
}[];
|
|
9
|
+
fields: string[];
|
|
10
|
+
|
|
11
|
+
/// will only be present temporarily and wont be stored in database
|
|
12
|
+
metadata?: any[];
|
|
13
|
+
generate_cards: {
|
|
14
|
+
state: boolean;
|
|
15
|
+
reason: string;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
3
|
+
|
|
4
|
+
export class GenerateConceptFacts {
|
|
5
|
+
public openAiService: OpenAiService;
|
|
6
|
+
public openAIHelper: OpenAIHelper;
|
|
7
|
+
public content: string;
|
|
8
|
+
public type: string = "";
|
|
9
|
+
public promptForConceptFacts: {
|
|
10
|
+
promptId: string;
|
|
11
|
+
version: string;
|
|
12
|
+
} = {
|
|
13
|
+
promptId: "",
|
|
14
|
+
version: "",
|
|
15
|
+
};
|
|
16
|
+
constructor(
|
|
17
|
+
openAiService: OpenAiService,
|
|
18
|
+
content: string,
|
|
19
|
+
type: string,
|
|
20
|
+
promptForConceptFacts: {
|
|
21
|
+
promptId: string;
|
|
22
|
+
version: string;
|
|
23
|
+
}
|
|
24
|
+
) {
|
|
25
|
+
this.openAiService = openAiService;
|
|
26
|
+
this.openAIHelper = new OpenAIHelper(
|
|
27
|
+
this.openAiService.api_key,
|
|
28
|
+
this.openAiService.model,
|
|
29
|
+
this.promptForConceptFacts.promptId,
|
|
30
|
+
this.promptForConceptFacts.version
|
|
31
|
+
);
|
|
32
|
+
this.content = content;
|
|
33
|
+
this.promptForConceptFacts = promptForConceptFacts;
|
|
34
|
+
this.type = type;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
async generate() {
|
|
38
|
+
console.log(this.promptForConceptFacts);
|
|
39
|
+
const openAiResponse = await this.openAIHelper.openAI.responses.create({
|
|
40
|
+
model: this.openAIHelper.model,
|
|
41
|
+
prompt: {
|
|
42
|
+
id: this.promptForConceptFacts.promptId,
|
|
43
|
+
version: this.promptForConceptFacts.version,
|
|
44
|
+
variables: {
|
|
45
|
+
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
input: this.content,
|
|
49
|
+
store: false,
|
|
50
|
+
});
|
|
51
|
+
console.log(openAiResponse.output_text);
|
|
52
|
+
return JSON.parse(openAiResponse.output_text);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
@@ -1,51 +1,88 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { returnTypologyData } from "../parse/response_format_typology";
|
|
1
|
+
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
2
|
import { ErrorLogger } from "../logger";
|
|
3
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
4
4
|
|
|
5
5
|
export class GenerateTypology {
|
|
6
6
|
public openAiService: OpenAiService;
|
|
7
|
-
public
|
|
7
|
+
public type: string = "";
|
|
8
8
|
public content: string = "";
|
|
9
|
+
public promptForTypology: {
|
|
10
|
+
promptId: string;
|
|
11
|
+
version: string;
|
|
12
|
+
} = {
|
|
13
|
+
promptId: "",
|
|
14
|
+
version: "",
|
|
15
|
+
};
|
|
9
16
|
expectedFields: Array<string>;
|
|
10
17
|
constructor(
|
|
11
18
|
openAiService: OpenAiService,
|
|
12
|
-
|
|
19
|
+
type: string,
|
|
13
20
|
content: string,
|
|
14
|
-
expected_fields: Array<string
|
|
21
|
+
expected_fields: Array<string>,
|
|
22
|
+
promptForTypology: {
|
|
23
|
+
promptId: string;
|
|
24
|
+
version: string;
|
|
25
|
+
}
|
|
15
26
|
) {
|
|
16
27
|
this.openAiService = openAiService;
|
|
17
|
-
this.
|
|
28
|
+
this.type = type;
|
|
18
29
|
this.content = content;
|
|
19
30
|
this.expectedFields = expected_fields.map((elem: string) =>
|
|
20
31
|
elem.toLowerCase()
|
|
21
32
|
);
|
|
33
|
+
this.promptForTypology = promptForTypology;
|
|
22
34
|
}
|
|
23
35
|
async generate() {
|
|
24
36
|
try {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.
|
|
37
|
+
// Use OpenAI Responses API
|
|
38
|
+
const openAIHelper = new OpenAIHelper(
|
|
39
|
+
this.openAiService.api_key,
|
|
40
|
+
this.openAiService.model,
|
|
41
|
+
this.promptForTypology.promptId,
|
|
42
|
+
this.promptForTypology.version
|
|
28
43
|
);
|
|
29
|
-
|
|
44
|
+
const openAiResponse: any = await openAIHelper.openAI.responses.create({
|
|
45
|
+
model: openAIHelper.model,
|
|
46
|
+
prompt: {
|
|
47
|
+
id: openAIHelper.promptId,
|
|
48
|
+
version: openAIHelper.version,
|
|
49
|
+
variables: {
|
|
50
|
+
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
input: this.content,
|
|
54
|
+
store: false,
|
|
55
|
+
});
|
|
56
|
+
console.log(openAiResponse);
|
|
57
|
+
|
|
58
|
+
// const response = await this.openAiService?.sendRequest(
|
|
59
|
+
// this.prompt,
|
|
60
|
+
// this.content
|
|
61
|
+
// );
|
|
62
|
+
openAiResponse["request_type"] = {
|
|
30
63
|
type: "breadth",
|
|
31
64
|
n: 1,
|
|
32
65
|
};
|
|
33
|
-
|
|
34
|
-
req_time:
|
|
66
|
+
openAiResponse.metadata = {
|
|
67
|
+
req_time: openAiResponse.created ?? new Date(),
|
|
35
68
|
req_type: {
|
|
36
69
|
type: "breadth",
|
|
37
70
|
n: 1,
|
|
38
71
|
},
|
|
39
|
-
req_tokens:
|
|
40
|
-
res_tokens:
|
|
41
|
-
|
|
72
|
+
req_tokens: openAiResponse.usage?.input_tokens ?? 0,
|
|
73
|
+
res_tokens: openAiResponse.usage?.output_tokens ?? 0,
|
|
74
|
+
prompt: openAiResponse.prompt,
|
|
75
|
+
// prompt_tokens_details: openAiResponse.usage?.,
|
|
42
76
|
model: this.openAiService.model,
|
|
77
|
+
usage: openAiResponse.usage,
|
|
43
78
|
};
|
|
44
|
-
|
|
45
|
-
|
|
79
|
+
|
|
80
|
+
if (openAiResponse.status == "completed") {
|
|
81
|
+
console.log("Completed");
|
|
82
|
+
return this.parseTypologyOnSuccess(openAiResponse);
|
|
46
83
|
} else {
|
|
47
|
-
|
|
48
|
-
return
|
|
84
|
+
openAiResponse.metadata.err_message = openAiResponse.message;
|
|
85
|
+
return openAiResponse;
|
|
49
86
|
}
|
|
50
87
|
} catch (e: any) {
|
|
51
88
|
await new ErrorLogger({
|
|
@@ -57,28 +94,14 @@ export class GenerateTypology {
|
|
|
57
94
|
|
|
58
95
|
parseTypologyOnSuccess(responseData: any) {
|
|
59
96
|
responseData.metadata.status = "completed";
|
|
60
|
-
const generatedContent = responseData.
|
|
61
|
-
const concepts = generatedContent.concepts.map((e: any) => {
|
|
62
|
-
return {
|
|
63
|
-
text: e.concept_text,
|
|
64
|
-
type: "concept",
|
|
65
|
-
reference: e.reference,
|
|
66
|
-
};
|
|
67
|
-
});
|
|
68
|
-
const facts = generatedContent.facts.map((e: any) => {
|
|
69
|
-
return {
|
|
70
|
-
text: e.fact_text,
|
|
71
|
-
type: "fact",
|
|
72
|
-
reference: e.reference,
|
|
73
|
-
};
|
|
74
|
-
});
|
|
97
|
+
const generatedContent = JSON.parse(responseData.output_text);
|
|
75
98
|
|
|
76
99
|
return {
|
|
77
100
|
status_code: 200,
|
|
78
101
|
metadata: [responseData.metadata],
|
|
79
102
|
field: this.parseFields(generatedContent.field),
|
|
80
|
-
|
|
81
|
-
generate_cards: generatedContent.
|
|
103
|
+
|
|
104
|
+
generate_cards: generatedContent.learn_value,
|
|
82
105
|
summary_cards: generatedContent.summary_cards,
|
|
83
106
|
// type: responseData.type,
|
|
84
107
|
};
|
package/.env.example
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
OPEN_AI_KEY= 'open ai key'
|