only_ever_generator 0.7.8 → 0.8.0
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 +97 -0
- package/dist/bootstrap/app.d.ts.map +1 -0
- package/dist/bootstrap/app.js +42 -48
- package/dist/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.d.ts +8 -0
- package/dist/card_gen/generate_cards.d.ts.map +1 -0
- package/dist/card_gen/generate_cards.js +32 -24
- 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 +3 -0
- 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 +5 -0
- package/dist/constants/api_constants.js.map +1 -0
- package/dist/constants/prompt_data.d.ts +4 -0
- package/dist/constants/prompt_data.js +1 -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 +1 -0
- 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 +1 -0
- package/dist/constants/prompts/typology_prompt.js.map +1 -0
- package/dist/constants/source_data.d.ts +171 -0
- package/dist/constants/source_data.js +2 -1
- 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/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/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 +3 -5
- 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 +1 -0
- package/dist/index.js +88 -49
- 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 +1 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts +17 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.js +3 -2
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts +26 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.js +4 -3
- package/dist/parse/parse_card/parse_flash_cards.js.map +1 -0
- package/dist/parse/parse_card/parse_match_card.d.ts +23 -0
- package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_match_card.js +3 -3
- package/dist/parse/parse_card/parse_match_card.js.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts +31 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.js +3 -2
- package/dist/parse/parse_card/parse_mcq_card.js.map +1 -0
- package/dist/parse/parse_card_response.d.ts +20 -0
- package/dist/parse/parse_card_response.d.ts.map +1 -0
- package/dist/parse/parse_card_response.js +62 -28
- package/dist/parse/parse_card_response.js.map +1 -0
- package/dist/parse/parse_source_content.d.ts +26 -0
- package/dist/parse/parse_source_content.d.ts.map +1 -0
- package/dist/parse/parse_source_content.js +1 -0
- package/dist/parse/parse_source_content.js.map +1 -0
- package/dist/parse/response_format_card.d.ts +176 -0
- package/dist/parse/response_format_card.js +1 -0
- package/dist/parse/response_format_card.js.map +1 -0
- package/dist/parse/response_format_typology.d.ts +1 -0
- package/dist/parse/response_format_typology.js +1 -0
- 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 +29 -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/types/base_param_type.d.ts +16 -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_typology.d.ts +29 -0
- package/dist/typology_gen/generate_typology.d.ts.map +1 -0
- package/dist/typology_gen/generate_typology.js +12 -11
- 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 +1 -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 +1 -0
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +18 -14
- package/src/bootstrap/app.ts +84 -71
- package/src/card_gen/generate_cards.ts +40 -29
- package/src/config.ts +2 -0
- package/src/constants/api_constants.ts +4 -0
- package/src/constants/prompts/card_gen_prompt.ts +1 -1
- 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/enums/card_type_enum.ts +6 -0
- package/src/gap_fill/calculate_gap_fill.ts +42 -45
- package/src/helper/qdrant_db_methods.ts +77 -0
- 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 -31
- package/src/parse/parse_source_content.ts +9 -1
- package/src/services/open_ai_service.ts +33 -1
- package/src/services/qdrant_service.ts +10 -0
- package/src/types/base_param_type.ts +16 -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_typology.ts +13 -12
- package/tsconfig.json +8 -3
- package/.env.example +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/index.ts +0 -72
- 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 { 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,33 +3,83 @@ 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 { MongoConceptFactCards } from "../types/mongo_concept_fact_type";
|
|
16
|
+
import { ParsedCardType } from "../types/parsed_card_type";
|
|
7
17
|
export class ParseCardResponse {
|
|
8
|
-
parse(
|
|
18
|
+
parse(
|
|
19
|
+
generatedData: GeneratedCardResponseType,
|
|
20
|
+
isGapFill: boolean,
|
|
21
|
+
sourceTaxonomy: SourceTaxonomy,
|
|
22
|
+
bloom_level: number
|
|
23
|
+
) {
|
|
9
24
|
let usage_data = generatedData.metadata;
|
|
10
25
|
try {
|
|
11
|
-
const cardData = [];
|
|
26
|
+
const cardData: ParsedCardType[] = [];
|
|
12
27
|
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
13
|
-
|
|
28
|
+
|
|
14
29
|
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
15
30
|
for (let elem of unparsedTestCards) {
|
|
31
|
+
elem.bloom_level = bloom_level;
|
|
32
|
+
const concepts = elem.concepts.map((e: any) => {
|
|
33
|
+
return {
|
|
34
|
+
text: e,
|
|
35
|
+
type: "concept",
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
const facts = elem.facts.map((e: any) => {
|
|
39
|
+
return {
|
|
40
|
+
text: e,
|
|
41
|
+
type: "fact",
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
const concepts_facts = [...concepts, ...facts];
|
|
45
|
+
const managedCardConcepts = this._mapIdToConcepts(
|
|
46
|
+
concepts_facts,
|
|
47
|
+
sourceTaxonomy.concepts_facts
|
|
48
|
+
);
|
|
49
|
+
|
|
16
50
|
if (elem.type == "flash") {
|
|
17
|
-
const flashCard = new ParseFlashCard().parse(
|
|
51
|
+
const flashCard = new ParseFlashCard().parse({
|
|
52
|
+
card_content: elem.card_content as RawFlashCardResponseType,
|
|
53
|
+
type: elem.type,
|
|
54
|
+
concepts_facts: managedCardConcepts,
|
|
55
|
+
bloom_level: elem.bloom_level,
|
|
56
|
+
});
|
|
18
57
|
if (flashCard != null && flashCard) {
|
|
19
58
|
flashCard.heading = this._getCardReference(
|
|
20
59
|
flashCard,
|
|
21
60
|
sourceTaxonomy
|
|
22
61
|
);
|
|
62
|
+
|
|
23
63
|
cardData.push(flashCard);
|
|
24
64
|
}
|
|
25
65
|
} else if (elem.type == "mcq") {
|
|
26
|
-
const mcqCard = new ParseMcqCard().parse(
|
|
66
|
+
const mcqCard = new ParseMcqCard().parse({
|
|
67
|
+
card_content: elem.card_content as RawMcqCardResponseType,
|
|
68
|
+
type: elem.type,
|
|
69
|
+
concepts_facts: managedCardConcepts,
|
|
70
|
+
bloom_level: elem.bloom_level,
|
|
71
|
+
});
|
|
27
72
|
if (mcqCard != null && mcqCard) {
|
|
28
73
|
mcqCard.heading = this._getCardReference(mcqCard, sourceTaxonomy);
|
|
29
74
|
cardData.push(mcqCard);
|
|
30
75
|
}
|
|
31
76
|
} else if (elem.type == "cloze") {
|
|
32
|
-
const clozeCard = new ParseClozeCard().parse(
|
|
77
|
+
const clozeCard = new ParseClozeCard().parse({
|
|
78
|
+
card_content: elem.card_content as RawClozeCardResponseType,
|
|
79
|
+
type: elem.type,
|
|
80
|
+
concepts_facts: managedCardConcepts,
|
|
81
|
+
bloom_level: elem.bloom_level,
|
|
82
|
+
});
|
|
33
83
|
if (clozeCard && clozeCard != null) {
|
|
34
84
|
clozeCard.heading = this._getCardReference(
|
|
35
85
|
clozeCard,
|
|
@@ -38,7 +88,12 @@ export class ParseCardResponse {
|
|
|
38
88
|
cardData.push(clozeCard);
|
|
39
89
|
}
|
|
40
90
|
} else if (elem.type == "match") {
|
|
41
|
-
const matchCard = new ParseMatchCard().parse(
|
|
91
|
+
const matchCard = new ParseMatchCard().parse({
|
|
92
|
+
card_content: elem.card_content as RawMatchCardResponseType,
|
|
93
|
+
type: elem.type,
|
|
94
|
+
concepts_facts: managedCardConcepts,
|
|
95
|
+
bloom_level: elem.bloom_level,
|
|
96
|
+
});
|
|
42
97
|
if (matchCard && matchCard != null) {
|
|
43
98
|
matchCard.heading = this._getCardReference(
|
|
44
99
|
matchCard,
|
|
@@ -60,41 +115,27 @@ export class ParseCardResponse {
|
|
|
60
115
|
return {
|
|
61
116
|
status_code: cardData.length == 0 ? 400 : 200,
|
|
62
117
|
metadata: usage_data,
|
|
63
|
-
type:
|
|
64
|
-
|
|
65
|
-
missing_facts: [],
|
|
118
|
+
type: "card_gen",
|
|
119
|
+
|
|
66
120
|
cards_data: cardData,
|
|
67
121
|
};
|
|
68
122
|
} catch (e: any) {
|
|
69
|
-
new ErrorLogger({
|
|
70
|
-
type: "card_parsing",
|
|
71
|
-
data: e.message,
|
|
72
|
-
response: generatedData,
|
|
73
|
-
}).log();
|
|
74
123
|
return {
|
|
75
124
|
status_code: 500,
|
|
76
125
|
metadata: usage_data,
|
|
77
|
-
type:
|
|
126
|
+
type: "card_gen",
|
|
78
127
|
};
|
|
79
128
|
}
|
|
80
129
|
}
|
|
81
130
|
|
|
82
131
|
_getCardReference(generatedCardData: any, sourceTaxonomy: any) {
|
|
83
|
-
const cardConcepts = generatedCardData.concepts ?? []
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const sourceConcepts = sourceTaxonomy.concepts ?? [];
|
|
88
|
-
|
|
89
|
-
const mappedSourceConcepts = sourceConcepts.map((elem: any) => {
|
|
90
|
-
return {
|
|
91
|
-
text: elem.concept_text,
|
|
92
|
-
reference: elem.reference,
|
|
93
|
-
};
|
|
94
|
-
});
|
|
132
|
+
const cardConcepts = (generatedCardData.concepts ?? []).map(
|
|
133
|
+
(e: any) => e.text
|
|
134
|
+
);
|
|
95
135
|
|
|
96
|
-
const
|
|
97
|
-
|
|
136
|
+
const sourceConceptsFacts = sourceTaxonomy.concepts_facts ?? [];
|
|
137
|
+
const firstMatchedConcept = sourceConceptsFacts.find((elem: any) =>
|
|
138
|
+
cardConcepts.includes(elem.text)
|
|
98
139
|
);
|
|
99
140
|
|
|
100
141
|
if (firstMatchedConcept) {
|
|
@@ -103,4 +144,26 @@ export class ParseCardResponse {
|
|
|
103
144
|
return "";
|
|
104
145
|
}
|
|
105
146
|
}
|
|
147
|
+
|
|
148
|
+
_mapIdToConcepts(
|
|
149
|
+
cardConcepts: any[],
|
|
150
|
+
sourceConceptsFacts: any[]
|
|
151
|
+
): MongoConceptFactCards[] {
|
|
152
|
+
// const cardData = cardC
|
|
153
|
+
const managedCardConcepts = [];
|
|
154
|
+
for (const cardConcept of cardConcepts) {
|
|
155
|
+
const matchedConcept = sourceConceptsFacts.find(
|
|
156
|
+
(e: any) =>
|
|
157
|
+
e.text.toLowerCase().trim() == cardConcept.text.toLowerCase().trim()
|
|
158
|
+
);
|
|
159
|
+
if (matchedConcept) {
|
|
160
|
+
managedCardConcepts.push({
|
|
161
|
+
id: matchedConcept.id,
|
|
162
|
+
text: matchedConcept.text,
|
|
163
|
+
type: matchedConcept.type,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return managedCardConcepts;
|
|
168
|
+
}
|
|
106
169
|
}
|
|
@@ -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,13 @@ export class ParseSourceContent {
|
|
|
25
27
|
this.content = sourceContent;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
parseData() {
|
|
30
|
+
parseData(): {
|
|
31
|
+
type: string;
|
|
32
|
+
title: string;
|
|
33
|
+
content: any[];
|
|
34
|
+
headings: string[];
|
|
35
|
+
taxonomy: SourceTaxonomy;
|
|
36
|
+
} {
|
|
29
37
|
let sourceType = this.content.type;
|
|
30
38
|
let afterSanitized;
|
|
31
39
|
if (sourceType == "video") {
|
|
@@ -3,7 +3,10 @@ import {
|
|
|
3
3
|
parseOpenAiFailureResponse,
|
|
4
4
|
parseOpenAiSuccessResponse,
|
|
5
5
|
} from "../utils/parse_openai_response";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
openAiEmbeddingEndPoint,
|
|
8
|
+
openAiEndPoint,
|
|
9
|
+
} from "../constants/api_constants";
|
|
7
10
|
|
|
8
11
|
export class OpenAiService {
|
|
9
12
|
public api_key: string;
|
|
@@ -53,4 +56,33 @@ export class OpenAiService {
|
|
|
53
56
|
return parseOpenAiFailureResponse(err.response);
|
|
54
57
|
}
|
|
55
58
|
}
|
|
59
|
+
|
|
60
|
+
async sendEmbeddingRequest(texts: string[]) {
|
|
61
|
+
try {
|
|
62
|
+
const url = openAiEmbeddingEndPoint();
|
|
63
|
+
let response = await axios.post(
|
|
64
|
+
url,
|
|
65
|
+
{
|
|
66
|
+
model: "text-embedding-3-large",
|
|
67
|
+
input: texts,
|
|
68
|
+
dimensions: 512,
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
headers: {
|
|
72
|
+
Authorization: "Bearer " + this.api_key,
|
|
73
|
+
"Content-Type": ["application/json"],
|
|
74
|
+
},
|
|
75
|
+
}
|
|
76
|
+
);
|
|
77
|
+
return {
|
|
78
|
+
status_code: 200,
|
|
79
|
+
data: response.data,
|
|
80
|
+
};
|
|
81
|
+
} catch (err: any) {
|
|
82
|
+
return {
|
|
83
|
+
status_code: err.response.status ?? 500,
|
|
84
|
+
message: err.message,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
56
88
|
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
title: string;
|
|
10
|
+
headings: string[];
|
|
11
|
+
content: any[];
|
|
12
|
+
fields: string[];
|
|
13
|
+
taxonomy?: SourceTaxonomy;
|
|
14
|
+
type: string;
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -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
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { OpenAiService } from "../services/open_ai_service";
|
|
2
|
-
|
|
2
|
+
|
|
3
3
|
import { ErrorLogger } from "../logger";
|
|
4
4
|
|
|
5
5
|
export class GenerateTypology {
|
|
@@ -57,26 +57,27 @@ export class GenerateTypology {
|
|
|
57
57
|
|
|
58
58
|
parseTypologyOnSuccess(responseData: any) {
|
|
59
59
|
responseData.metadata.status = "completed";
|
|
60
|
-
const
|
|
60
|
+
const generatedContent = responseData.generated_content;
|
|
61
|
+
const concepts = generatedContent.concepts.map((e: any) => {
|
|
61
62
|
return {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
text: e.concept_text,
|
|
64
|
+
type: "concept",
|
|
65
|
+
reference: e.reference,
|
|
65
66
|
};
|
|
66
67
|
});
|
|
67
|
-
const
|
|
68
|
+
const facts = generatedContent.facts.map((e: any) => {
|
|
68
69
|
return {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
70
|
+
text: e.fact_text,
|
|
71
|
+
type: "fact",
|
|
72
|
+
reference: e.reference,
|
|
72
73
|
};
|
|
73
74
|
});
|
|
74
|
-
|
|
75
|
+
|
|
75
76
|
return {
|
|
76
77
|
status_code: 200,
|
|
77
|
-
metadata: responseData.metadata,
|
|
78
|
+
metadata: [responseData.metadata],
|
|
78
79
|
field: this.parseFields(generatedContent.field),
|
|
79
|
-
|
|
80
|
+
concepts_facts: [...concepts, ...facts],
|
|
80
81
|
generate_cards: generatedContent.generate_cards,
|
|
81
82
|
summary_cards: generatedContent.summary_cards,
|
|
82
83
|
// type: responseData.type,
|
package/tsconfig.json
CHANGED
|
@@ -5,8 +5,13 @@
|
|
|
5
5
|
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
|
6
6
|
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
|
7
7
|
"strict": true,
|
|
8
|
+
"declaration": true,
|
|
9
|
+
"declarationMap": true,
|
|
10
|
+
"emitDeclarationOnly": false,
|
|
8
11
|
"rootDir": "./src",
|
|
9
|
-
"outDir": "./dist" /* Enable all strict type-checking options. */
|
|
12
|
+
"outDir": "./dist", /* Enable all strict type-checking options. */
|
|
13
|
+
"sourceMap": true
|
|
10
14
|
},
|
|
11
|
-
"
|
|
12
|
-
|
|
15
|
+
"include": ["src/**/*"],
|
|
16
|
+
"exclude": ["node_modules", "**/*.test.ts"]
|
|
17
|
+
}
|
package/.env.example
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
OPEN_AI_KEY= 'open ai key'
|
package/prompts.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
[
|
|
2
|
-
{
|
|
3
|
-
"generation_for":"card",
|
|
4
|
-
"type": "role",
|
|
5
|
-
"prompt": "As a dedicated assistant at a learning company, your role is to create test cards based on the provided content. The purpose of these cards is to help learners master and understand the concepts and facts presented to you."
|
|
6
|
-
},
|
|
7
|
-
{
|
|
8
|
-
"generation_for":"card",
|
|
9
|
-
"type": "inputs",
|
|
10
|
-
"prompt": "You will be provided with the following: \n 1. Title of the source \n 2. The content \n 3. The field of knowledge it belongs to \n 4. Key concepts in the source \n 5. Important facts in the source"
|
|
11
|
-
},
|
|
12
|
-
{
|
|
13
|
-
"generation_for":"card",
|
|
14
|
-
"type" :"steps",
|
|
15
|
-
"prompt": "**Follow these steps:** \n 1. Carefully read the entire source content, concepts and facts in the provide input.\n 2. Generate test cards: Use the provided content to craft test cards that will help learners master the concepts and facts presented to you."
|
|
16
|
-
},
|
|
17
|
-
{
|
|
18
|
-
"generation_for": "card",
|
|
19
|
-
"type": "schema",
|
|
20
|
-
"prompt": "**Format your response in the following JSON format:** json { \"test_cards\": [ { \"type\": \"{card_type}\", \"card_content\": \"{content}\", \"concepts\": [\"concept1\", \"concept2\", \"...\"], \"facts\": [\"fact1\", \"fact2\", \"...\"] }, {... as many cards as possible} ] }"
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
]
|
package/readme.md
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
This is a NPM package that handles the all the ai generation for _source on OnlyEver.
|
|
2
|
-
The Generation includes, Knowledge Taxonomy , Summary and Test Cards data for the _source.
|
|
3
|
-
|
|
4
|
-
The class [OnlyEverGenerator] is the Entry point for the generation module it has two required fields,
|
|
5
|
-
[api_key] which is open ai token
|
|
6
|
-
[model] open ai model : 'gpt-3.5-turbo-1106'
|
|
7
|
-
[content] source content : Array<BaseBlocks>
|
|
8
|
-
|
|
9
|
-
The [OnlyEverGenerator] currently exposes a main method, [generate] which handles all types of generation and takes a Param
|
|
10
|
-
```
|
|
11
|
-
generate(generate_typology = false,generate_card = false) method takes two args, generate_typology and generate_cards, which are both boolean.
|
|
12
|
-
For Eg:
|
|
13
|
-
let oeGenerator = new OnlyEverGenerator(
|
|
14
|
-
api_key,
|
|
15
|
-
model,
|
|
16
|
-
[Block1,Block2,Block3], // oe content model
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let responsesArray = await oeGenerator.generate(true,true);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
Exposed a new method ```gapFill``` from OnlyEverGenerator
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
async gapFill(factsMaps: any, aiCards: Array<any>) {}
|
|
27
|
-
/// factsmap
|
|
28
|
-
/// {
|
|
29
|
-
/// remaining_facts: [],
|
|
30
|
-
/// remaining_concepts: [],
|
|
31
|
-
//}
|
|
32
|
-
|
|
33
|
-
/// aicards is array of ai cards
|
|
34
|
-
|
|
35
|
-
```
|