only_ever_generator 0.2.6 → 0.2.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.
- package/dist/bootstrap/app.js +47 -44
- package/dist/card_gen/generate_cards.js +47 -32
- package/dist/constants/prompt_data.js +273 -273
- package/dist/constants/prompts/card_gen_prompt.js +180 -180
- package/dist/constants/prompts/typology_prompt.js +93 -93
- package/dist/logger.js +41 -0
- package/dist/parse/parse_source_content.js +23 -9
- package/dist/typology_gen/generate_typology.js +21 -12
- package/dist/utils/generate_args.js +1 -11
- package/package.json +33 -33
- package/readme.md +23 -23
- package/src/bootstrap/app.ts +150 -141
- package/src/card_gen/generate_cards.ts +251 -239
- package/src/config.ts +6 -6
- package/src/constants/api_constants.ts +2 -2
- package/src/constants/prompt_data.ts +296 -296
- package/src/constants/prompts/card_gen_prompt.ts +372 -372
- package/src/constants/prompts/typology_prompt.ts +202 -202
- package/src/constants/source_data.ts +47 -47
- package/src/gap_fill/calculate_gap_fill.ts +52 -52
- package/src/index.ts +61 -61
- package/src/logger.ts +31 -0
- package/src/parse/parse_card_response.ts +289 -289
- package/src/parse/parse_source_content.ts +94 -81
- package/src/parse/response_format_card.ts +210 -210
- package/src/parse/response_format_typology.ts +43 -43
- package/src/services/open_ai_service.ts +55 -54
- package/src/typology_gen/generate_typology.ts +71 -64
- package/src/utils/generate_args.ts +28 -37
- package/src/utils/parse_openai_response.ts +20 -20
- package/tsconfig.json +12 -12
- package/dist/class/parse/parse_source_content.js +0 -62
- package/dist/class/services/open_ai_service.js +0 -25
- package/dist/parse_response/parse_card_response.js +0 -288
- package/dist/parse_response/response_format_card.js +0 -210
- package/dist/parse_response/response_format_typology.js +0 -47
- package/dist/service/open_ai_request.js +0 -57
package/dist/bootstrap/app.js
CHANGED
|
@@ -20,13 +20,10 @@ const generate_args_1 = require("../utils/generate_args");
|
|
|
20
20
|
const calculate_gap_fill_1 = require("../gap_fill/calculate_gap_fill");
|
|
21
21
|
/// OnlyEverGenerator
|
|
22
22
|
class OnlyEverGenerator {
|
|
23
|
-
constructor(apiKey, model, generationContent
|
|
24
|
-
// prompt: any,
|
|
25
|
-
// content: any,
|
|
26
|
-
// expected_fields: Array<string>
|
|
27
|
-
) {
|
|
23
|
+
constructor(apiKey, model, generationContent) {
|
|
28
24
|
this.api_key = "";
|
|
29
|
-
|
|
25
|
+
/// these fields will be populated inside the constructor
|
|
26
|
+
this.parsedContent = {};
|
|
30
27
|
this.promptForTypology = "";
|
|
31
28
|
this.promptForCardGen = "";
|
|
32
29
|
this.typologyResponse = {};
|
|
@@ -35,72 +32,78 @@ class OnlyEverGenerator {
|
|
|
35
32
|
this.gapFillResponse = {};
|
|
36
33
|
this.api_key = apiKey;
|
|
37
34
|
this.openAiService = new open_ai_service_1.OpenAiService(apiKey, model !== null && model !== void 0 ? model : "gpt-3.5-turbo-1106");
|
|
38
|
-
|
|
35
|
+
const parsedData = new parse_source_content_1.ParseSourceContent(generationContent.content).parseData();
|
|
36
|
+
this.parsedContent = {
|
|
37
|
+
title: parsedData.title,
|
|
38
|
+
headings: parsedData.headings,
|
|
39
|
+
content: parsedData.content,
|
|
40
|
+
},
|
|
41
|
+
// parsedData.type == 'cards' ? this.typologyResponse = parsedData.taxonomy : this.typologyResponse = null;
|
|
42
|
+
this.typologyResponse = parsedData.taxonomy;
|
|
39
43
|
this.expectedFields = generationContent.content.fields; //returnFields();
|
|
40
44
|
this.promptForTypology = (0, typology_prompt_1.returnTypologyPrompt)(generationContent.prompt.typology);
|
|
41
45
|
this.promptForCardGen = (0, card_gen_prompt_1.returnCardGenPrompt)(generationContent.prompt.card_generation);
|
|
42
46
|
}
|
|
43
47
|
generate() {
|
|
44
48
|
return __awaiter(this, arguments, void 0, function* (generate_typology = false, generate_card = false) {
|
|
45
|
-
|
|
46
|
-
//let typologyPrompt = returnTypologyPrompt();
|
|
47
|
-
let typologyPrompt = this.promptForTypology;
|
|
48
|
-
// let cardPrompt = returnCardGenPrompt();
|
|
49
|
-
let cardPrompt = this.promptForCardGen;
|
|
50
|
-
let args = new generate_args_1.GenerateArgs(generate_card, generate_typology, false, {
|
|
51
|
-
typology_prompt: typologyPrompt,
|
|
52
|
-
card_gen_prompt: cardPrompt,
|
|
53
|
-
summary_prompt: "",
|
|
54
|
-
});
|
|
49
|
+
let args = new generate_args_1.GenerateArgs(generate_card, generate_typology, false);
|
|
55
50
|
const responseToReturn = [];
|
|
56
51
|
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
57
52
|
for (let elem of whatNeedsToBeGenerated)
|
|
58
53
|
if (elem == "generate_tyopology") {
|
|
59
|
-
this.typologyResponse = yield this.generateTypology(
|
|
54
|
+
this.typologyResponse = yield this.generateTypology(this.promptForTypology);
|
|
60
55
|
responseToReturn.push(this.typologyResponse);
|
|
61
56
|
}
|
|
62
57
|
else if (elem == "generate_card") {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
58
|
+
/// for cards gen to occur, there must be presence of source taxonomy
|
|
59
|
+
if (this.shouldTheCardBeGeneratedAfterTypologyResponse()) {
|
|
60
|
+
this.cardgenResponse = yield this.generateCard(this.promptForCardGen, JSON.stringify(this.typologyResponse), false);
|
|
61
|
+
responseToReturn.push(this.cardgenResponse);
|
|
62
|
+
/// check if gap fill is required ie coverage determination
|
|
63
|
+
if (this.cardgenResponse.status_code == 200) {
|
|
64
|
+
this.gapFillResponse = yield this.generationForGapFill(this.typologyResponse, this.cardgenResponse);
|
|
65
|
+
responseToReturn.push(this.gapFillResponse);
|
|
66
66
|
}
|
|
67
|
-
else {
|
|
68
|
-
this.cardgenResponse = yield this.generateCard((_b = args.prompts.card_gen_prompt) !== null && _b !== void 0 ? _b : "", this.parsedContent + JSON.stringify(this.typologyResponse), false);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
this.cardgenResponse = yield this.generateCard((_c = args.prompts.card_gen_prompt) !== null && _c !== void 0 ? _c : "", this.parsedContent, false);
|
|
73
67
|
}
|
|
74
|
-
responseToReturn.push(this.cardgenResponse);
|
|
75
|
-
}
|
|
76
|
-
if (this.cardgenResponse.status_code == 200) {
|
|
77
|
-
let gapFill = (0, calculate_gap_fill_1.gapFilling)(this.typologyResponse, this.cardgenResponse);
|
|
78
|
-
if (gapFill.remainingConcepts.length !== 0 ||
|
|
79
|
-
gapFill.remainingFacts.length !== 0) {
|
|
80
|
-
this.gapFillResponse = yield this.generateCard((_d = args.prompts.card_gen_prompt) !== null && _d !== void 0 ? _d : "", this.parsedContent +
|
|
81
|
-
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
82
|
-
JSON.stringify(gapFill) +
|
|
83
|
-
"Exclude generating these cards" +
|
|
84
|
-
JSON.stringify(this.cardgenResponse.cards_data), true);
|
|
85
68
|
}
|
|
86
|
-
responseToReturn.push(this.gapFillResponse);
|
|
87
|
-
}
|
|
88
69
|
return responseToReturn;
|
|
89
70
|
// return [typologyPrompt, cardPrompt];
|
|
90
71
|
});
|
|
91
72
|
}
|
|
92
|
-
|
|
73
|
+
shouldTheCardBeGeneratedAfterTypologyResponse() {
|
|
74
|
+
if (this.typologyResponse) {
|
|
75
|
+
return this.typologyResponse.generate_cards.state == true;
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
generationForGapFill(typologyData, cardGenData) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
let gapFill = (0, calculate_gap_fill_1.gapFilling)(typologyData, cardGenData);
|
|
84
|
+
let response;
|
|
85
|
+
if (gapFill.remainingConcepts.length !== 0 ||
|
|
86
|
+
gapFill.remainingFacts.length !== 0) {
|
|
87
|
+
response = yield this.generateCard(this.promptForCardGen +
|
|
88
|
+
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
89
|
+
JSON.stringify(gapFill) +
|
|
90
|
+
"Exclude generating these cards", JSON.stringify(cardGenData.cards_data), true);
|
|
91
|
+
}
|
|
92
|
+
return response;
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
generateCard(prompt, additionalContent, isGapFill) {
|
|
93
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
94
97
|
let generateCards = new generate_cards_1.GenerateCards(this.openAiService);
|
|
95
|
-
|
|
98
|
+
this.cardgenResponse = yield generateCards.generateCards(prompt !== null && prompt !== void 0 ? prompt : "", this.parsedContent + additionalContent, isGapFill);
|
|
96
99
|
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
97
100
|
// response['type'] = 'card_gen';
|
|
98
|
-
return cardgenResponse;
|
|
101
|
+
return this.cardgenResponse;
|
|
99
102
|
});
|
|
100
103
|
}
|
|
101
104
|
generateTypology(prompt) {
|
|
102
105
|
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
-
let response = yield new generate_typology_1.GenerateTypology(this.openAiService, prompt, this.parsedContent, this.expectedFields).generate();
|
|
106
|
+
let response = yield new generate_typology_1.GenerateTypology(this.openAiService, prompt, JSON.stringify(this.parsedContent), this.expectedFields).generate();
|
|
104
107
|
return response;
|
|
105
108
|
});
|
|
106
109
|
}
|
|
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GenerateCards = void 0;
|
|
13
|
+
const logger_1 = require("../logger");
|
|
13
14
|
class GenerateCards {
|
|
14
15
|
constructor(openAiService) {
|
|
15
16
|
this.openAiService = openAiService;
|
|
@@ -39,42 +40,56 @@ class GenerateCards {
|
|
|
39
40
|
});
|
|
40
41
|
}
|
|
41
42
|
parse(generatedData, isGapFill) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
43
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
try {
|
|
45
|
+
const cardData = [];
|
|
46
|
+
let usage_data = generatedData.metadata;
|
|
47
|
+
const status_code = generatedData.status_code;
|
|
48
|
+
const missing_concepts = generatedData.generated_content.missing_concepts;
|
|
49
|
+
const missing_facts = generatedData.generated_content.missing_facts;
|
|
50
|
+
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
51
|
+
const type = generatedData.type;
|
|
52
|
+
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
53
|
+
for (let elem of unparsedTestCards) {
|
|
54
|
+
if (elem.type == "flash") {
|
|
55
|
+
cardData.push(this.parseFlashCard(elem));
|
|
56
|
+
}
|
|
57
|
+
else if (elem.type == "mcq") {
|
|
58
|
+
cardData.push(this.parseMcqCard(elem));
|
|
59
|
+
}
|
|
60
|
+
else if (elem.type == "cloze") {
|
|
61
|
+
cardData.push(this.parseClozeCard(elem));
|
|
62
|
+
}
|
|
63
|
+
else if (elem.type == "match") {
|
|
64
|
+
cardData.push(this.parseMatchCard(elem));
|
|
65
|
+
}
|
|
66
|
+
}
|
|
59
67
|
}
|
|
60
|
-
else
|
|
61
|
-
|
|
68
|
+
else {
|
|
69
|
+
if (!isGapFill) {
|
|
70
|
+
usage_data.status = "failed";
|
|
71
|
+
}
|
|
62
72
|
}
|
|
73
|
+
return {
|
|
74
|
+
status_code: status_code,
|
|
75
|
+
metadata: usage_data,
|
|
76
|
+
type: type,
|
|
77
|
+
missing_concepts: missing_concepts,
|
|
78
|
+
missing_facts: missing_facts,
|
|
79
|
+
cards_data: cardData,
|
|
80
|
+
};
|
|
63
81
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
82
|
+
catch (e) {
|
|
83
|
+
yield new logger_1.ErrorLogger({
|
|
84
|
+
"type": 'card_parsing',
|
|
85
|
+
"data": e.message,
|
|
86
|
+
}).log();
|
|
87
|
+
return {
|
|
88
|
+
status_code: 500,
|
|
89
|
+
type: 'card_gen',
|
|
90
|
+
};
|
|
68
91
|
}
|
|
69
|
-
}
|
|
70
|
-
return {
|
|
71
|
-
status_code: status_code,
|
|
72
|
-
metadata: usage_data,
|
|
73
|
-
type: type,
|
|
74
|
-
missing_concepts: missing_concepts,
|
|
75
|
-
missing_facts: missing_facts,
|
|
76
|
-
cards_data: cardData,
|
|
77
|
-
};
|
|
92
|
+
});
|
|
78
93
|
}
|
|
79
94
|
parseFlashCard(data) {
|
|
80
95
|
let displayTitle = this.generateFlashCardDisplayTitle(data.card_content.front, data.card_content.back);
|