only_ever_generator 0.3.7 → 0.3.9
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 +23 -8
- package/dist/card_gen/generate_cards.js +7 -7
- package/dist/constants/api_constants.js +1 -2
- package/dist/constants/prompt_data.js +1 -2
- package/dist/constants/prompts/card_gen_prompt.js +1 -2
- package/dist/constants/prompts/typology_prompt.js +1 -2
- package/dist/constants/source_data.js +940 -534
- package/dist/gap_fill/calculate_gap_fill.js +5 -2
- package/dist/parse/response_format_card.js +2 -3
- package/dist/parse/response_format_typology.js +1 -2
- package/dist/typology_gen/generate_typology.js +5 -4
- package/dist/utils/parse_openai_response.js +2 -4
- package/package.json +7 -7
- package/readme.md +12 -0
- package/src/bootstrap/app.ts +31 -10
- package/src/card_gen/generate_cards.ts +4 -4
- package/src/constants/source_data.ts +937 -530
- package/src/gap_fill/calculate_gap_fill.ts +4 -0
- package/src/typology_gen/generate_typology.ts +2 -1
- package/src/utils/parse_openai_response.ts +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.gapFilling =
|
|
3
|
+
exports.gapFilling = gapFilling;
|
|
4
4
|
function isEmpty(obj) {
|
|
5
5
|
return Object.keys(obj).length === 0;
|
|
6
6
|
}
|
|
@@ -35,8 +35,11 @@ function gapFilling(typologyResponse, cardgenResponse) {
|
|
|
35
35
|
remainingFacts = allFacts.filter((item) => !generatedFactsSet.includes(item));
|
|
36
36
|
}
|
|
37
37
|
return {
|
|
38
|
+
// allConcepts: allConcepts,
|
|
39
|
+
// allFacts: allFacts,
|
|
40
|
+
// generatedConcepts: generatedConceptsSet,
|
|
41
|
+
// generatedFacts: generatedFactsSet,
|
|
38
42
|
remainingConcepts: remainingConcepts,
|
|
39
43
|
remainingFacts: remainingFacts,
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
|
-
exports.gapFilling = gapFilling;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.returnResponse = returnResponse;
|
|
4
|
+
exports.parseResponse = parseResponse;
|
|
4
5
|
const responseData = {
|
|
5
6
|
"flash_cards": [
|
|
6
7
|
{
|
|
@@ -142,7 +143,6 @@ const responseData = {
|
|
|
142
143
|
function returnResponse() {
|
|
143
144
|
return responseData;
|
|
144
145
|
}
|
|
145
|
-
exports.returnResponse = returnResponse;
|
|
146
146
|
function parseResponse() {
|
|
147
147
|
let cardData = [];
|
|
148
148
|
let data = returnResponse();
|
|
@@ -162,7 +162,6 @@ function parseResponse() {
|
|
|
162
162
|
}
|
|
163
163
|
return cardData;
|
|
164
164
|
}
|
|
165
|
-
exports.parseResponse = parseResponse;
|
|
166
165
|
/// takes array of
|
|
167
166
|
function parseFlashCard(cards) {
|
|
168
167
|
let flashCardData = [];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.returnTypologyData =
|
|
3
|
+
exports.returnTypologyData = returnTypologyData;
|
|
4
4
|
const typologyResponse = {
|
|
5
5
|
"usage_data": {
|
|
6
6
|
"prompt_tokens": 11611,
|
|
@@ -44,4 +44,3 @@ const typologyResponse = {
|
|
|
44
44
|
function returnTypologyData() {
|
|
45
45
|
return typologyResponse;
|
|
46
46
|
}
|
|
47
|
-
exports.returnTypologyData = returnTypologyData;
|
|
@@ -22,15 +22,16 @@ class GenerateTypology {
|
|
|
22
22
|
}
|
|
23
23
|
generate() {
|
|
24
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
-
var _a, _b, _c;
|
|
25
|
+
var _a, _b, _c, _d;
|
|
26
26
|
try {
|
|
27
27
|
const response = yield ((_a = this.openAiService) === null || _a === void 0 ? void 0 : _a.sendRequest(this.prompt, this.content));
|
|
28
28
|
response['type'] = 'typology';
|
|
29
29
|
response.metadata = {
|
|
30
|
-
"req_time": response.generated_at,
|
|
30
|
+
"req_time": (_b = response.generated_at) !== null && _b !== void 0 ? _b : new Date(),
|
|
31
31
|
"req_type": response.type,
|
|
32
|
-
"req_tokens": (
|
|
33
|
-
"res_tokens": (
|
|
32
|
+
"req_tokens": (_c = response.usage_data) === null || _c === void 0 ? void 0 : _c.prompt_tokens,
|
|
33
|
+
"res_tokens": (_d = response.usage_data) === null || _d === void 0 ? void 0 : _d.completion_tokens,
|
|
34
|
+
"model": this.openAiService.model
|
|
34
35
|
};
|
|
35
36
|
if (response.status_code == 200) {
|
|
36
37
|
return this.parseTypologyOnSuccess(response);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.parseOpenAiSuccessResponse = parseOpenAiSuccessResponse;
|
|
4
|
+
exports.parseOpenAiFailureResponse = parseOpenAiFailureResponse;
|
|
4
5
|
function parseOpenAiSuccessResponse(responseData) {
|
|
5
6
|
let choices = JSON.parse(responseData.choices[0].message.content);
|
|
6
7
|
let usuage = responseData.usage;
|
|
@@ -12,14 +13,11 @@ function parseOpenAiSuccessResponse(responseData) {
|
|
|
12
13
|
'generated_at': new Date(createdTime * 1000)
|
|
13
14
|
};
|
|
14
15
|
}
|
|
15
|
-
exports.parseOpenAiSuccessResponse = parseOpenAiSuccessResponse;
|
|
16
16
|
function parseOpenAiFailureResponse(errorResponse) {
|
|
17
17
|
var _a, _b;
|
|
18
|
-
let usuage = errorResponse.usuage;
|
|
19
18
|
// let statusCode =
|
|
20
19
|
return {
|
|
21
20
|
'status_code': errorResponse.status,
|
|
22
21
|
'message': (_b = (_a = errorResponse.data) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.code
|
|
23
22
|
};
|
|
24
23
|
}
|
|
25
|
-
exports.parseOpenAiFailureResponse = parseOpenAiFailureResponse;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "only_ever_generator",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.9",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"start": "npm run build && nodemon dist/index.js",
|
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"devDependencies": {
|
|
14
14
|
"@types/express": "^4.17.21",
|
|
15
15
|
"@types/node": "^20.14.2",
|
|
16
|
+
"dotenv": "^16.4.5",
|
|
17
|
+
"express": "^4.19.2",
|
|
16
18
|
"nodemon": "^3.1.3",
|
|
17
19
|
"ts-node": "^10.9.2",
|
|
18
|
-
"typescript": "^5.4
|
|
19
|
-
"dotenv": "^16.4.5",
|
|
20
|
-
"express": "^4.19.2"
|
|
20
|
+
"typescript": "^5.5.4"
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
|
-
"axios": "^1.7.
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
"axios": "^1.7.7",
|
|
24
|
+
"n": "^10.0.0",
|
|
25
|
+
"stable": "^0.1.8"
|
|
26
26
|
},
|
|
27
27
|
"eslintConfig": {
|
|
28
28
|
"parser": "typescript-eslint-parser",
|
package/readme.md
CHANGED
|
@@ -20,4 +20,16 @@ let oeGenerator = new OnlyEverGenerator(
|
|
|
20
20
|
let responsesArray = await oeGenerator.generate(true,true);
|
|
21
21
|
|
|
22
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
|
+
|
|
23
35
|
```
|
package/src/bootstrap/app.ts
CHANGED
|
@@ -72,17 +72,14 @@ export class OnlyEverGenerator {
|
|
|
72
72
|
if(this.shouldTheCardBeGeneratedAfterTypologyResponse()){
|
|
73
73
|
this.cardgenResponse = await this.generateCard(
|
|
74
74
|
this.promptForCardGen,
|
|
75
|
-
|
|
76
|
-
"facts": this.typologyResponse.facts,
|
|
77
|
-
"concepts": this.typologyResponse.concepts
|
|
78
|
-
}),
|
|
75
|
+
JSON.stringify(this.typologyResponse),
|
|
79
76
|
false,
|
|
80
77
|
)
|
|
81
78
|
responseToReturn.push(this.cardgenResponse);
|
|
82
79
|
|
|
83
80
|
/// check if gap fill is required ie coverage determination
|
|
84
81
|
if(this.cardgenResponse.status_code == 200) {
|
|
85
|
-
this.gapFillResponse = await this.
|
|
82
|
+
this.gapFillResponse = await this._generationForGapFill(this.typologyResponse, this.cardgenResponse);
|
|
86
83
|
responseToReturn.push(this.gapFillResponse);
|
|
87
84
|
}
|
|
88
85
|
|
|
@@ -102,7 +99,7 @@ export class OnlyEverGenerator {
|
|
|
102
99
|
|
|
103
100
|
}
|
|
104
101
|
|
|
105
|
-
async
|
|
102
|
+
async _generationForGapFill(typologyData: any, cardGenData: any) {
|
|
106
103
|
let gapFill = gapFilling(typologyData, cardGenData);
|
|
107
104
|
let response :any ;
|
|
108
105
|
if (
|
|
@@ -110,10 +107,11 @@ export class OnlyEverGenerator {
|
|
|
110
107
|
gapFill.remainingFacts.length !== 0
|
|
111
108
|
) {
|
|
112
109
|
response = await this.generateCard(
|
|
113
|
-
this.promptForCardGen
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
110
|
+
this.promptForCardGen +
|
|
111
|
+
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
112
|
+
JSON.stringify(gapFill) +
|
|
113
|
+
"Exclude generating cards with content in the following",
|
|
114
|
+
JSON.stringify(cardGenData.cards_data),
|
|
117
115
|
true
|
|
118
116
|
);
|
|
119
117
|
}
|
|
@@ -147,6 +145,29 @@ export class OnlyEverGenerator {
|
|
|
147
145
|
return response;
|
|
148
146
|
}
|
|
149
147
|
|
|
148
|
+
async gapFill(factsMaps: any, aiCards: Array<any>) {
|
|
149
|
+
/// factsmap
|
|
150
|
+
/// {
|
|
151
|
+
/// remaining_facts: [],
|
|
152
|
+
/// remaining_concepts: [],
|
|
153
|
+
//}
|
|
154
|
+
|
|
155
|
+
/// aicards is data
|
|
156
|
+
let response :any ;
|
|
157
|
+
|
|
158
|
+
response = await this.generateCard(
|
|
159
|
+
this.promptForCardGen +
|
|
160
|
+
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
161
|
+
JSON.stringify(factsMaps) +
|
|
162
|
+
"Exclude generating cards with content in the following",
|
|
163
|
+
JSON.stringify(aiCards),
|
|
164
|
+
true
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
return response;
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
150
171
|
|
|
151
172
|
|
|
152
173
|
}
|
|
@@ -12,11 +12,11 @@ export class GenerateCards {
|
|
|
12
12
|
// console.log("response to card generation ", response);
|
|
13
13
|
response["type"] = isGapFill ? "gap_fill":"card_gen";
|
|
14
14
|
response.metadata = {
|
|
15
|
-
"req_time": response.generated_at,
|
|
15
|
+
"req_time": response.generated_at ?? new Date(),
|
|
16
16
|
"req_type": response.type,
|
|
17
17
|
"req_tokens": response.usage_data?.prompt_tokens,
|
|
18
18
|
"res_tokens": response.usage_data?.completion_tokens,
|
|
19
|
-
|
|
19
|
+
"model": this.openAiService.model
|
|
20
20
|
};
|
|
21
21
|
if(response.status_code == 200){
|
|
22
22
|
response.metadata.status = "completed";
|
|
@@ -165,7 +165,7 @@ return question;
|
|
|
165
165
|
|
|
166
166
|
parseClozeCard(data: any) {
|
|
167
167
|
let displayTitle = this.generateClozeCardDisplayTitle(
|
|
168
|
-
data.card_content.
|
|
168
|
+
data.card_content.prompt,
|
|
169
169
|
data.card_content.options
|
|
170
170
|
);
|
|
171
171
|
let clozeCardData = {
|
|
@@ -176,7 +176,7 @@ return question;
|
|
|
176
176
|
heading: data.card_reference,
|
|
177
177
|
displayTitle: displayTitle,
|
|
178
178
|
content: {
|
|
179
|
-
question: data.card_content.
|
|
179
|
+
question: data.card_content.prompt,
|
|
180
180
|
options: data.card_content.options,
|
|
181
181
|
},
|
|
182
182
|
concepts: data.concepts,
|