only_ever_generator 1.0.7 → 1.0.8

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.
Files changed (103) hide show
  1. package/dist/bootstrap/app.d.ts +12 -5
  2. package/dist/bootstrap/app.d.ts.map +1 -1
  3. package/dist/bootstrap/app.js +41 -15
  4. package/dist/bootstrap/app.js.map +1 -1
  5. package/dist/card_gen/generate_cards.d.ts +2 -1
  6. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  7. package/dist/card_gen/generate_cards.js +21 -4
  8. package/dist/card_gen/generate_cards.js.map +1 -1
  9. package/dist/constants/prompt_data.d.ts +0 -1
  10. package/dist/constants/prompts/card_gen_prompt.js.map +1 -1
  11. package/dist/constants/source_data.d.ts +0 -2
  12. package/dist/constants/source_data.js +1 -1
  13. package/dist/constants/source_data.js.map +1 -1
  14. package/dist/embedding_generation/consolidation/global_consolidation.d.ts +1 -1
  15. package/dist/embedding_generation/consolidation/global_consolidation.d.ts.map +1 -1
  16. package/dist/embedding_generation/consolidation/global_consolidation.js +1 -1
  17. package/dist/embedding_generation/consolidation/global_consolidation.js.map +1 -1
  18. package/dist/embedding_generation/local_consolidation.js +104 -0
  19. package/dist/enums/card_type_enum.d.ts +7 -0
  20. package/dist/enums/card_type_enum.d.ts.map +1 -0
  21. package/dist/enums/card_type_enum.js +11 -0
  22. package/dist/enums/card_type_enum.js.map +1 -0
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +0 -91
  25. package/dist/index.js.map +1 -1
  26. package/dist/parse/parse_card/parse_cloze_card.d.ts +8 -1
  27. package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -1
  28. package/dist/parse/parse_card/parse_cloze_card.js +2 -2
  29. package/dist/parse/parse_card/parse_cloze_card.js.map +1 -1
  30. package/dist/parse/parse_card/parse_flash_cards.d.ts +14 -7
  31. package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -1
  32. package/dist/parse/parse_card/parse_flash_cards.js +3 -3
  33. package/dist/parse/parse_card/parse_flash_cards.js.map +1 -1
  34. package/dist/parse/parse_card/parse_match_card.d.ts +8 -1
  35. package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -1
  36. package/dist/parse/parse_card/parse_match_card.js +2 -3
  37. package/dist/parse/parse_card/parse_match_card.js.map +1 -1
  38. package/dist/parse/parse_card/parse_mcq_card.d.ts +15 -8
  39. package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -1
  40. package/dist/parse/parse_card/parse_mcq_card.js +2 -2
  41. package/dist/parse/parse_card/parse_mcq_card.js.map +1 -1
  42. package/dist/parse/parse_card_response.d.ts +12 -10
  43. package/dist/parse/parse_card_response.d.ts.map +1 -1
  44. package/dist/parse/parse_card_response.js +121 -54
  45. package/dist/parse/parse_card_response.js.map +1 -1
  46. package/dist/parse/parse_source_content.d.ts +7 -5
  47. package/dist/parse/parse_source_content.d.ts.map +1 -1
  48. package/dist/parse/parse_source_content.js +1 -0
  49. package/dist/parse/parse_source_content.js.map +1 -1
  50. package/dist/parse/response_format_card.d.ts +0 -1
  51. package/dist/parse/response_format_typology.d.ts +0 -1
  52. package/dist/types/base_param_type.d.ts +17 -0
  53. package/dist/types/base_param_type.d.ts.map +1 -0
  54. package/dist/types/base_param_type.js +3 -0
  55. package/dist/types/base_param_type.js.map +1 -0
  56. package/dist/types/mongo_concept_fact_type.d.ts +12 -0
  57. package/dist/types/mongo_concept_fact_type.d.ts.map +1 -0
  58. package/dist/types/mongo_concept_fact_type.js +3 -0
  59. package/dist/types/mongo_concept_fact_type.js.map +1 -0
  60. package/dist/types/parsed_card_type.d.ts +12 -0
  61. package/dist/types/parsed_card_type.d.ts.map +1 -0
  62. package/dist/types/parsed_card_type.js +30 -0
  63. package/dist/types/parsed_card_type.js.map +1 -0
  64. package/dist/types/raw_card_response_types/generated_card_response_type.d.ts +40 -0
  65. package/dist/types/raw_card_response_types/generated_card_response_type.d.ts.map +1 -0
  66. package/dist/types/raw_card_response_types/generated_card_response_type.js +8 -0
  67. package/dist/types/raw_card_response_types/generated_card_response_type.js.map +1 -0
  68. package/dist/types/source_taxonomy_type.d.ts +15 -0
  69. package/dist/types/source_taxonomy_type.d.ts.map +1 -0
  70. package/dist/types/source_taxonomy_type.js +3 -0
  71. package/dist/types/source_taxonomy_type.js.map +1 -0
  72. package/dist/typology_gen/generate_typology.d.ts.map +1 -1
  73. package/dist/typology_gen/generate_typology.js.map +1 -1
  74. package/package.json +10 -9
  75. package/src/bootstrap/app.ts +63 -22
  76. package/src/card_gen/generate_cards.ts +27 -5
  77. package/src/constants/prompts/card_gen_prompt.ts +1 -1
  78. package/src/embedding_generation/consolidation/global_consolidation.ts +2 -2
  79. package/src/enums/card_type_enum.ts +6 -0
  80. package/src/index.ts +4 -110
  81. package/src/parse/parse_card/parse_cloze_card.ts +11 -3
  82. package/src/parse/parse_card/parse_flash_cards.ts +12 -4
  83. package/src/parse/parse_card/parse_match_card.ts +10 -4
  84. package/src/parse/parse_card/parse_mcq_card.ts +11 -3
  85. package/src/parse/parse_card_response.ts +94 -20
  86. package/src/parse/parse_source_content.ts +11 -1
  87. package/src/types/base_param_type.ts +17 -0
  88. package/src/types/mongo_concept_fact_type.ts +12 -0
  89. package/src/types/parsed_card_type.ts +39 -0
  90. package/src/types/raw_card_response_types/generated_card_response_type.ts +61 -0
  91. package/src/types/source_taxonomy_type.ts +17 -0
  92. package/src/typology_gen/generate_typology.ts +1 -2
  93. package/.env.example +0 -1
  94. package/dist/constants/prompt_data.d.ts.map +0 -1
  95. package/dist/constants/source_data.d.ts.map +0 -1
  96. package/dist/parse/response_format_card.d.ts.map +0 -1
  97. package/dist/parse/response_format_typology.d.ts.map +0 -1
  98. package/prompts.json +0 -23
  99. package/readme.md +0 -35
  100. package/src/constants/prompt_data.ts +0 -301
  101. package/src/constants/source_data.ts +0 -1036
  102. package/src/parse/response_format_card.ts +0 -386
  103. package/src/parse/response_format_typology.ts +0 -44
package/src/index.ts CHANGED
@@ -1,113 +1,7 @@
1
- // import express from "express";
2
- // import {
3
- // returnCardResponse,
4
- // returnHeadings,
5
- // returnSourceData,
6
- // } from "./constants/source_data";
7
- // import config from "./config";
8
- // const app = express();
9
- // const port = 3000;
10
- // import { returnPromptData } from "./constants/prompt_data";
11
- // import { GenerateCards } from "./card_gen/generate_cards";
12
- // import { OpenAiService } from "./services/open_ai_service";
13
- // import { ParseCardResponse } from "./parse/parse_card_response";
14
- // import { returnTypologyPrompt } from "./constants/prompts/typology_prompt";
15
- // import { returnCardGenPrompt } from "./constants/prompts/card_gen_prompt";
16
- // import { GenerateArgs } from "./utils/generate_args";
17
-
18
1
  import { OnlyEverGenerator } from "./bootstrap/app";
19
- // import { LocalConsolidation } from "./embedding_generation/consolidation/local_consolidation";
20
- // import { embeddingsResp } from "./typology-parsed-response";
21
- // import { GlobalConsolidation } from "./embedding_generation/consolidation/global_consolidation";
22
- // import { ParseEmbeddingResponse } from "./embedding_generation/parse_embedding_response";
2
+ import { LocalConsolidation } from "./embedding_generation/consolidation/local_consolidation";
3
+ import { embeddingsResp } from "./typology-parsed-response";
4
+ import { GlobalConsolidation } from "./embedding_generation/consolidation/global_consolidation";
5
+ import { ParseEmbeddingResponse } from "./embedding_generation/parse_embedding_response";
23
6
 
24
- /// While Publishing the package , and using this code as a separate npm module
25
- /// uncomment the below line and comment all the others, expect the import of OnlyEverGenerator
26
7
  export { OnlyEverGenerator };
27
-
28
- // . All the Codes Below uses express and are strictly for development purpose, while publishing the package, comment everything
29
- // below this line
30
- // let oeGen = new OnlyEverGenerator(config.openAIKey, "gpt-4o-mini", {
31
- // prompt: returnPromptData(),
32
- // content: returnSourceData(),
33
- // });
34
- // app.get("/", async (req, res) => {
35
- // // let data = oeGen.returnParsedContent();
36
- // // let parsedData = parseResponse()
37
- // let cardPrompt = "";
38
-
39
- // res.send(cardPrompt);
40
- // });
41
-
42
- // app.get("/openAI", async (req, res) => {
43
- // // let prompt = returnPromt();
44
- // // let prompt = returnCardGenPrompt();
45
- // // let content = returnSourceData().toString()
46
- // // let headings = returnHeadings();
47
- // // // let aiRequest = await openAIRequest(prompt,content);
48
- // let aiRequest = await oeGen.generate(true, true);
49
- // res.send(aiRequest);
50
- // });
51
-
52
- // app.get("/parseCardData", async (req, res) => {
53
- // let cardResp = returnCardResponse();
54
- // let headings = returnHeadings();
55
-
56
- // cardResp.metadata = {
57
- // req_time: cardResp.generated_at ?? new Date(),
58
- // req_type: "card",
59
- // req_tokens: cardResp.usage_data?.prompt_tokens,
60
- // res_tokens: cardResp.usage_data?.completion_tokens,
61
- // model: "40-mini",
62
- // };
63
- // let parsedData = new ParseCardResponse().parse(cardResp, false, {});
64
- // res.send(parsedData);
65
- // });
66
-
67
- // app.get("/generate-cards", async (req, res) => {
68
- // let cardResp = embeddingsResp;
69
- // oeGen.parsedContent.taxonomy = cardResp;
70
- // let parsedData = await oeGen.generateCard(
71
- // returnCardGenPrompt(),
72
- // JSON.stringify(cardResp),
73
- // false
74
- // );
75
- // res.send(parsedData);
76
- // });
77
-
78
- // app.get("/typology", async (req, res) => {
79
- // {
80
- // let typologyRequest = await oeGen.generate(true, false);
81
- // res.send(typologyRequest);
82
- // }
83
- // });
84
-
85
- // app.get("/local-consolidation", async (req, res) => {
86
- // const concepts_facts = embeddingsResp.concepts_facts;
87
-
88
- // let locallyConsolidated = new LocalConsolidation().consolidate(
89
- // concepts_facts,
90
- // "sourceID"
91
- // );
92
- // res.send(locallyConsolidated);
93
- // });
94
-
95
- // app.get("/global-consolidation", async (req, res) => {
96
- // const concepts_facts = embeddingsResp.concepts_facts;
97
-
98
- // // let globallyConsolidated = await new GlobalConsolidation().consolidate(
99
- // // concepts_facts,
100
- // // "sourceID",
101
- // // 0.2
102
- // // );
103
- // // let globallyConsolidated = await oeGen.globalConsolidation(
104
- // // concepts_facts,
105
- // // "sourceID",
106
- // // 0.2
107
- // // );
108
- // // res.send(globallyConsolidated);
109
- // });
110
-
111
- // app.listen(port, () => {
112
- // console.log(`Example app listening at http://localhost:${port}`);
113
- // });
@@ -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: any) {
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
- concepts: data.concepts,
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: any) {
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: data.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
- concepts: data.concepts,
27
+ concepts_facts: data.concepts_facts,
20
28
  explanation: data.card_content.explanation,
21
- facts: data.facts,
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: any) {
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
- concepts: cardData.concepts,
30
- facts: cardData.facts,
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: any) {
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
- concepts: data.concepts,
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(generatedData: any, isGapFill: boolean, sourceTaxonomy: any) {
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
- elem.concepts_facts,
49
+ concepts_facts,
19
50
  sourceTaxonomy.concepts_facts
20
51
  );
21
- elem.concepts = managedCardConcepts;
52
+
22
53
  if (elem.type == "flash") {
23
- const flashCard = new ParseFlashCard().parse(elem);
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(elem);
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(elem);
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(elem);
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: 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: generatedData.type,
137
+ type: "card_gen",
79
138
  };
80
139
  }
81
140
  }
82
141
 
83
- _getCardReference(generatedCardData: any, sourceTaxonomy: any) {
84
- const cardConcepts = (generatedCardData.concepts ?? []).map(
85
- (e: any) => e.text
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 sourceConceptsFacts = sourceTaxonomy.concepts_facts ?? [];
89
- const firstMatchedConcept = sourceConceptsFacts.find((elem: any) =>
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(cardConcepts: any[], sourceConceptsFacts: any[]) {
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,12 @@
1
+ export type MongoConceptFactSource = {
2
+ text: string;
3
+ type: "concept" | "fact";
4
+ reference: string;
5
+ id: string;
6
+ };
7
+
8
+ export type MongoConceptFactCards = {
9
+ text: string;
10
+ type: "concept" | "fact";
11
+ id: string;
12
+ };
@@ -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,6 +1,5 @@
1
- import { OpenAiService } from "../services/open_ai_service";
2
- import { returnTypologyData } from "../parse/response_format_typology";
3
1
  import { ErrorLogger } from "../logger";
2
+ import { OpenAiService } from "../services/open_ai_service";
4
3
 
5
4
  export class GenerateTypology {
6
5
  public openAiService: OpenAiService;
package/.env.example DELETED
@@ -1 +0,0 @@
1
- OPEN_AI_KEY= 'open ai key'
@@ -1 +0,0 @@
1
- {"version":3,"file":"prompt_data.d.ts","sourceRoot":"","sources":["../../src/constants/prompt_data.ts"],"names":[],"mappings":"AAuSA,wBAAgB,gBAAgB;;;EAK/B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"source_data.d.ts","sourceRoot":"","sources":["../../src/constants/source_data.ts"],"names":[],"mappings":"AAonBA,wBAAgB,YAAY,aAqB3B;AAWD,wBAAgB,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAE/B;AAED,wBAAgB,cAAc,aAE7B;AAED,wBAAgB,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEjC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"response_format_card.d.ts","sourceRoot":"","sources":["../../src/parse/response_format_card.ts"],"names":[],"mappings":"AAAA,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;CAkJjB,CAAC;AAEF,QAAA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6Of,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"response_format_typology.d.ts","sourceRoot":"","sources":["../../src/parse/response_format_typology.ts"],"names":[],"mappings":"AAyCA,wBAAgB,kBAAkB,IACL,GAAG,CAC/B"}
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
- ]