only_ever_generator 0.3.0 → 0.3.1
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
CHANGED
|
@@ -94,11 +94,10 @@ class OnlyEverGenerator {
|
|
|
94
94
|
}
|
|
95
95
|
generateCard(prompt, additionalContent, isGapFill) {
|
|
96
96
|
return __awaiter(this, void 0, void 0, function* () {
|
|
97
|
-
let
|
|
98
|
-
let cardResp = yield generateCards.generateCards(prompt !== null && prompt !== void 0 ? prompt : "", this.parsedContent + additionalContent, isGapFill);
|
|
97
|
+
let generateCardsResp = yield new generate_cards_1.GenerateCards(this.openAiService).generateCards(prompt !== null && prompt !== void 0 ? prompt : "", this.parsedContent + additionalContent, isGapFill);
|
|
99
98
|
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
100
99
|
// response['type'] = 'card_gen';
|
|
101
|
-
return
|
|
100
|
+
return generateCardsResp;
|
|
102
101
|
});
|
|
103
102
|
}
|
|
104
103
|
generateTypology(prompt) {
|
|
@@ -40,56 +40,54 @@ class GenerateCards {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
parse(generatedData, isGapFill) {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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
|
-
}
|
|
43
|
+
try {
|
|
44
|
+
const cardData = [];
|
|
45
|
+
let usage_data = generatedData.metadata;
|
|
46
|
+
const status_code = generatedData.status_code;
|
|
47
|
+
const missing_concepts = generatedData.generated_content.missing_concepts;
|
|
48
|
+
const missing_facts = generatedData.generated_content.missing_facts;
|
|
49
|
+
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
50
|
+
const type = generatedData.type;
|
|
51
|
+
if (unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
52
|
+
for (let elem of unparsedTestCards) {
|
|
53
|
+
if (elem.type == "flash") {
|
|
54
|
+
cardData.push(this.parseFlashCard(elem));
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
56
|
+
else if (elem.type == "mcq") {
|
|
57
|
+
cardData.push(this.parseMcqCard(elem));
|
|
58
|
+
}
|
|
59
|
+
else if (elem.type == "cloze") {
|
|
60
|
+
cardData.push(this.parseClozeCard(elem));
|
|
61
|
+
}
|
|
62
|
+
else if (elem.type == "match") {
|
|
63
|
+
cardData.push(this.parseMatchCard(elem));
|
|
71
64
|
}
|
|
72
65
|
}
|
|
73
|
-
return {
|
|
74
|
-
status_code: isGapFill ? status_code : cardData.length > 0 ? status_code : 500,
|
|
75
|
-
metadata: usage_data,
|
|
76
|
-
type: type,
|
|
77
|
-
missing_concepts: missing_concepts,
|
|
78
|
-
missing_facts: missing_facts,
|
|
79
|
-
cards_data: cardData,
|
|
80
|
-
};
|
|
81
66
|
}
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
"
|
|
85
|
-
|
|
86
|
-
}).log();
|
|
87
|
-
return {
|
|
88
|
-
status_code: 500,
|
|
89
|
-
type: 'card_gen',
|
|
90
|
-
};
|
|
67
|
+
else {
|
|
68
|
+
if (!isGapFill) {
|
|
69
|
+
usage_data.status = "failed";
|
|
70
|
+
}
|
|
91
71
|
}
|
|
92
|
-
|
|
72
|
+
return {
|
|
73
|
+
status_code: isGapFill ? status_code : cardData.length > 0 ? status_code : 500,
|
|
74
|
+
metadata: usage_data,
|
|
75
|
+
type: type,
|
|
76
|
+
missing_concepts: missing_concepts,
|
|
77
|
+
missing_facts: missing_facts,
|
|
78
|
+
cards_data: cardData,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
catch (e) {
|
|
82
|
+
new logger_1.ErrorLogger({
|
|
83
|
+
"type": 'card_parsing',
|
|
84
|
+
"data": e.message,
|
|
85
|
+
}).log();
|
|
86
|
+
return {
|
|
87
|
+
status_code: 500,
|
|
88
|
+
type: 'card_gen',
|
|
89
|
+
};
|
|
90
|
+
}
|
|
93
91
|
}
|
|
94
92
|
parseFlashCard(data) {
|
|
95
93
|
let displayTitle = this.generateFlashCardDisplayTitle(data.card_content.front, data.card_content.back);
|
|
@@ -5,7 +5,6 @@ function parseOpenAiSuccessResponse(responseData) {
|
|
|
5
5
|
let choices = JSON.parse(responseData.choices[0].message.content);
|
|
6
6
|
let usuage = responseData.usage;
|
|
7
7
|
let createdTime = responseData.created;
|
|
8
|
-
console.log(JSON.stringify(choices));
|
|
9
8
|
return {
|
|
10
9
|
'status_code': 200,
|
|
11
10
|
'usage_data': usuage,
|
package/package.json
CHANGED
package/src/bootstrap/app.ts
CHANGED
|
@@ -122,8 +122,7 @@ export class OnlyEverGenerator {
|
|
|
122
122
|
|
|
123
123
|
|
|
124
124
|
async generateCard(prompt: string, additionalContent: string, isGapFill: boolean) {
|
|
125
|
-
let
|
|
126
|
-
let cardResp = await generateCards.generateCards(
|
|
125
|
+
let generateCardsResp = await new GenerateCards(this.openAiService).generateCards(
|
|
127
126
|
prompt ?? "",
|
|
128
127
|
this.parsedContent + additionalContent,
|
|
129
128
|
isGapFill
|
|
@@ -131,7 +130,7 @@ export class OnlyEverGenerator {
|
|
|
131
130
|
|
|
132
131
|
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
133
132
|
// response['type'] = 'card_gen';
|
|
134
|
-
return
|
|
133
|
+
return generateCardsResp;
|
|
135
134
|
}
|
|
136
135
|
|
|
137
136
|
|
|
@@ -28,7 +28,7 @@ export class GenerateCards {
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
parse(generatedData: any, isGapFill: boolean) {
|
|
32
32
|
try{
|
|
33
33
|
const cardData = [];
|
|
34
34
|
let usage_data = generatedData.metadata;
|
|
@@ -66,7 +66,7 @@ if(unparsedTestCards !== undefined && unparsedTestCards.length != 0) {
|
|
|
66
66
|
cards_data: cardData,
|
|
67
67
|
};
|
|
68
68
|
}catch (e:any){
|
|
69
|
-
|
|
69
|
+
new ErrorLogger({
|
|
70
70
|
"type": 'card_parsing',
|
|
71
71
|
"data": e.message,
|
|
72
72
|
}).log();
|
|
@@ -2,7 +2,6 @@ export function parseOpenAiSuccessResponse(responseData: any){
|
|
|
2
2
|
let choices = JSON.parse(responseData.choices[0].message.content);
|
|
3
3
|
let usuage = responseData.usage;
|
|
4
4
|
let createdTime = responseData.created;
|
|
5
|
-
console.log(JSON.stringify(choices));
|
|
6
5
|
return {
|
|
7
6
|
'status_code': 200,
|
|
8
7
|
'usage_data': usuage,
|