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