only_ever_generator 0.0.6 → 0.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.
- package/dist/bootstrap/app.js +77 -63
- package/dist/card_gen/generate_cards.js +184 -0
- package/dist/constants/api_constants.js +7 -0
- package/dist/constants/prompts/card_gen_prompt.js +30 -24
- package/dist/constants/source_data.js +5 -1
- package/dist/index.js +4 -78
- package/dist/parse/parse_card_response.js +288 -0
- package/dist/parse/parse_source_content.js +62 -0
- package/dist/parse/response_format_card.js +210 -0
- package/dist/parse/response_format_typology.js +47 -0
- package/dist/service/open_ai_request.js +0 -1
- package/dist/services/open_ai_service.js +60 -0
- package/dist/typology_gen/generate_typology.js +14 -6
- package/package.json +1 -1
- package/src/bootstrap/app.ts +74 -64
- package/src/card_gen/generate_cards.ts +192 -0
- package/src/constants/api_constants.ts +3 -0
- package/src/constants/prompts/card_gen_prompt.ts +30 -25
- package/src/constants/source_data.ts +5 -0
- package/src/index.ts +4 -81
- package/src/services/open_ai_service.ts +54 -0
- package/src/typology_gen/generate_typology.ts +18 -10
- package/src/class/services/open_ai_service.ts +0 -18
- package/src/service/open_ai_request.ts +0 -46
- /package/src/{parse_response → parse}/parse_card_response.ts +0 -0
- /package/src/{class/parse → parse}/parse_source_content.ts +0 -0
- /package/src/{parse_response → parse}/response_format_card.ts +0 -0
- /package/src/{parse_response → parse}/response_format_typology.ts +0 -0
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.returnTypologyData = void 0;
|
|
4
|
+
const typologyResponse = {
|
|
5
|
+
"usage_data": {
|
|
6
|
+
"prompt_tokens": 11611,
|
|
7
|
+
"completion_tokens": 441,
|
|
8
|
+
"total_tokens": 12052
|
|
9
|
+
},
|
|
10
|
+
"generated_content": {
|
|
11
|
+
"field": [
|
|
12
|
+
"Sciences",
|
|
13
|
+
"Technology & Engineering",
|
|
14
|
+
"Education, Learning & Personal Development"
|
|
15
|
+
],
|
|
16
|
+
"concepts": [
|
|
17
|
+
"Electrolysis",
|
|
18
|
+
"Faraday's Laws of Electrolysis",
|
|
19
|
+
"Electrolytic Cell",
|
|
20
|
+
"Decomposition Potential",
|
|
21
|
+
"Oxidation and Reduction at the Electrodes",
|
|
22
|
+
"Electrolysis of Water",
|
|
23
|
+
"Electrolysis of Carbon Dioxide",
|
|
24
|
+
"Electrocrystallization"
|
|
25
|
+
],
|
|
26
|
+
"facts": [
|
|
27
|
+
"Electrolysis is the passing of a direct electric current through an electrolyte producing chemical reactions at the electrodes and decomposition of the materials.",
|
|
28
|
+
"In electrolysis, the quantity of the products is proportional to the current, and when two or more electrolytic cells are connected in series to the same power source, the products produced in the cells are proportional to their equivalent weight.",
|
|
29
|
+
"The main components required to achieve electrolysis are an electrolyte, electrodes, and an external power source.",
|
|
30
|
+
"Faraday's laws of electrolysis detail the amount of the products of electrolysis is related to the number of electrons in the reaction at the electrodes.",
|
|
31
|
+
"Decomposition potential or decomposition voltage refers to the minimum voltage between anode and cathode of an electrolytic cell that is needed for electrolysis to occur.",
|
|
32
|
+
"The electrochemical reduction of carbon dioxide can produce value-added chemicals such as methane, ethylene, and ethanol."
|
|
33
|
+
],
|
|
34
|
+
"generate_cards": true,
|
|
35
|
+
"summary_cards": [
|
|
36
|
+
"Electrolysis is the process of passing direct electric current through an electrolyte, resulting in chemical reactions and the decomposition of materials.",
|
|
37
|
+
"Faraday's laws of electrolysis determine the relationship between the amounts of products generated and the electrons involved in the reaction at the electrodes.",
|
|
38
|
+
"Decomposition potential is the minimum voltage required between anode and cathode for electrolysis to occur.",
|
|
39
|
+
"The electrochemical reduction of carbon dioxide is a potential method for producing valuable chemicals such as methane, ethylene, and ethanol."
|
|
40
|
+
]
|
|
41
|
+
},
|
|
42
|
+
"generated_at": "Tue, 20 Jan 1970 21:17:46 GMT"
|
|
43
|
+
};
|
|
44
|
+
function returnTypologyData() {
|
|
45
|
+
return typologyResponse;
|
|
46
|
+
}
|
|
47
|
+
exports.returnTypologyData = returnTypologyData;
|
|
@@ -43,7 +43,6 @@ function openAIRequest(content, prompt, token, model) {
|
|
|
43
43
|
if (response.status == 200) {
|
|
44
44
|
console.log('success');
|
|
45
45
|
return (0, parse_openai_response_js_1.parseOpenAiSuccessResponse)(response.data);
|
|
46
|
-
// return JSON.parse(response.data.choices[0].message.content);
|
|
47
46
|
}
|
|
48
47
|
else {
|
|
49
48
|
console.log('failed');
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.OpenAiService = void 0;
|
|
16
|
+
const axios_1 = __importDefault(require("axios"));
|
|
17
|
+
const parse_openai_response_1 = require("../utils/parse_openai_response");
|
|
18
|
+
const api_constants_1 = require("../constants/api_constants");
|
|
19
|
+
class OpenAiService {
|
|
20
|
+
constructor(apiKey, model) {
|
|
21
|
+
this.api_key = apiKey;
|
|
22
|
+
this.model = model;
|
|
23
|
+
}
|
|
24
|
+
sendRequest(prompt, content) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
try {
|
|
27
|
+
let message = [
|
|
28
|
+
{
|
|
29
|
+
"role": "system", "content": prompt
|
|
30
|
+
}, {
|
|
31
|
+
"role": "user", "content": content
|
|
32
|
+
}
|
|
33
|
+
];
|
|
34
|
+
const url = (0, api_constants_1.openAiEndPoint)();
|
|
35
|
+
let response = yield axios_1.default.post(url, {
|
|
36
|
+
"model": this.model,
|
|
37
|
+
"messages": message,
|
|
38
|
+
"response_format": { "type": "json_object" },
|
|
39
|
+
}, {
|
|
40
|
+
headers: {
|
|
41
|
+
Authorization: "Bearer " + this.api_key,
|
|
42
|
+
"Content-Type": ['application/json']
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
if (response.status == 200) {
|
|
46
|
+
console.log('success');
|
|
47
|
+
return (0, parse_openai_response_1.parseOpenAiSuccessResponse)(response.data);
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
console.log('failed');
|
|
51
|
+
return response.statusText;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
return (0, parse_openai_response_1.parseOpenAiFailureResponse)(err.response);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
exports.OpenAiService = OpenAiService;
|
|
@@ -11,23 +11,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GenerateTypology = void 0;
|
|
13
13
|
class GenerateTypology {
|
|
14
|
-
constructor(openAiService, prompt, content) {
|
|
14
|
+
constructor(openAiService, prompt, content, expected_fields) {
|
|
15
15
|
this.prompt = '';
|
|
16
16
|
this.content = '';
|
|
17
17
|
this.openAiService = openAiService;
|
|
18
18
|
this.prompt = prompt;
|
|
19
19
|
this.content = content;
|
|
20
|
+
this.expectedFields = expected_fields.map((elem) => elem.toLowerCase());
|
|
20
21
|
}
|
|
21
22
|
generate() {
|
|
22
23
|
return __awaiter(this, void 0, void 0, function* () {
|
|
23
|
-
var _a;
|
|
24
|
+
var _a, _b, _c;
|
|
24
25
|
const response = yield ((_a = this.openAiService) === null || _a === void 0 ? void 0 : _a.sendRequest(this.prompt, this.content));
|
|
25
26
|
response['type'] = 'typology';
|
|
26
27
|
response.metadata = {
|
|
27
28
|
"req_time": response.generated_at,
|
|
28
29
|
"req_type": response.type,
|
|
29
|
-
"req_tokens": response.usage_data.prompt_tokens,
|
|
30
|
-
"res_tokens": response.usage_data.completion_tokens,
|
|
30
|
+
"req_tokens": (_b = response.usage_data) === null || _b === void 0 ? void 0 : _b.prompt_tokens,
|
|
31
|
+
"res_tokens": (_c = response.usage_data) === null || _c === void 0 ? void 0 : _c.completion_tokens,
|
|
31
32
|
};
|
|
32
33
|
if (response.status_code == 200) {
|
|
33
34
|
return this.parseTypologyOnSuccess(response);
|
|
@@ -43,14 +44,21 @@ class GenerateTypology {
|
|
|
43
44
|
return {
|
|
44
45
|
status_code: 200,
|
|
45
46
|
metadata: responseData.metadata,
|
|
46
|
-
field: generatedContent.field,
|
|
47
|
+
field: this.parseFields(generatedContent.field),
|
|
47
48
|
concepts: generatedContent.concepts,
|
|
48
49
|
facts: generatedContent.facts,
|
|
49
50
|
generate_cards: generatedContent.generate_cards,
|
|
50
51
|
summary_cards: generatedContent.summary_cards,
|
|
51
|
-
type: responseData.type
|
|
52
|
+
type: responseData.type
|
|
52
53
|
};
|
|
53
54
|
}
|
|
55
|
+
parseFields(fields) {
|
|
56
|
+
const fieldKeys = ['primary_field', 'secondary_field', 'tertiary_field'];
|
|
57
|
+
return fields.slice(0, 3).map((item, index) => ({
|
|
58
|
+
[fieldKeys[index]]: item,
|
|
59
|
+
"reconcile": !(this.expectedFields.includes(item.toLowerCase()))
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
54
62
|
parseTypologyOnFailure(responseData) {
|
|
55
63
|
return __awaiter(this, void 0, void 0, function* () {
|
|
56
64
|
responseData.metadata.status = 'failed';
|
package/package.json
CHANGED
package/src/bootstrap/app.ts
CHANGED
|
@@ -1,78 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { GenerateCards } from "../card_gen/generate_cards";
|
|
2
|
+
import { ParseSourceContent } from "../parse/parse_source_content";
|
|
3
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
+
import { returnCardGenPrompt } from "../constants/prompts/card_gen_prompt";
|
|
5
|
+
import { returnTypologyPrompt } from "../constants/prompts/typology_prompt";
|
|
6
|
+
import { GenerateTypology } from "../typology_gen/generate_typology";
|
|
7
|
+
import { GenerateArgs } from "../utils/generate_args";
|
|
8
|
+
import { returnFields } from "../constants/source_data";
|
|
9
|
+
import { returnTypologyData } from "../parse/response_format_typology";
|
|
7
10
|
|
|
8
|
-
// export class OnlyEverGenerator{
|
|
9
|
-
// public api_key: string = '';
|
|
10
|
-
// public openAiService: OpenAiService;
|
|
11
|
-
// parsedContent: string = '';
|
|
12
|
-
// constructor(apiKey:string, model: string, content: Array<any>){
|
|
13
|
-
// this.api_key = apiKey;
|
|
14
|
-
// this.openAiService = new OpenAiService(apiKey,model ?? 'gpt-3.5-turbo-1106');
|
|
15
|
-
// this.parsedContent = new ParseSourceContent(content).parse();
|
|
16
|
-
// };
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
12
|
+
/// OnlyEverGenerator
|
|
13
|
+
|
|
14
|
+
export class OnlyEverGenerator{
|
|
15
|
+
public api_key: string = '';
|
|
16
|
+
public openAiService: OpenAiService;
|
|
17
|
+
parsedContent: string = '';
|
|
18
|
+
expectedFields: Array<string>
|
|
19
|
+
constructor(apiKey:string, model: string, content: Array<any>, expected_fields: Array<string>){
|
|
20
|
+
this.api_key = apiKey;
|
|
21
|
+
this.openAiService = new OpenAiService(apiKey,model ?? 'gpt-3.5-turbo-1106');
|
|
22
|
+
this.parsedContent = new ParseSourceContent(content).parse();
|
|
23
|
+
this.expectedFields = returnFields()
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
typologyResponse = {};
|
|
27
|
+
cardgenResponse = {};
|
|
28
|
+
summarizeResponse = {};
|
|
21
29
|
|
|
22
30
|
|
|
23
31
|
|
|
24
32
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
33
|
+
async generate(
|
|
34
|
+
generate_typology: boolean =false,
|
|
35
|
+
generate_card : boolean = false,
|
|
36
|
+
): Promise<Array<any>> {
|
|
37
|
+
let typologyPrompt = returnTypologyPrompt();
|
|
38
|
+
let cardPrompt = returnCardGenPrompt();
|
|
39
|
+
let args = new GenerateArgs(
|
|
40
|
+
generate_card,
|
|
41
|
+
generate_typology,
|
|
42
|
+
false,
|
|
43
|
+
{
|
|
44
|
+
typology_prompt: typologyPrompt,
|
|
45
|
+
card_gen_prompt: cardPrompt,
|
|
46
|
+
summary_prompt: ''
|
|
47
|
+
},
|
|
40
48
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
// }
|
|
49
|
+
);
|
|
50
|
+
const responseToReturn = [];
|
|
51
|
+
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
52
|
+
for(let elem of whatNeedsToBeGenerated)
|
|
53
|
+
if(elem == 'generate_tyopology'){
|
|
54
|
+
this.typologyResponse = await this.generateTypology(args.prompts.typology_prompt ?? '');
|
|
55
|
+
responseToReturn.push(this.typologyResponse);
|
|
56
|
+
}else if(elem == 'generate_card'){
|
|
57
|
+
this.cardgenResponse = await this.generateCard(args.prompts.card_gen_prompt ?? '', this.parsedContent + JSON.stringify(this.typologyResponse));
|
|
58
|
+
responseToReturn.push(this.cardgenResponse);
|
|
59
|
+
}
|
|
53
60
|
|
|
54
|
-
|
|
61
|
+
return responseToReturn;
|
|
55
62
|
|
|
56
|
-
|
|
63
|
+
}
|
|
57
64
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
_returnParsedContent(){
|
|
66
|
+
return this.parsedContent;
|
|
67
|
+
}
|
|
61
68
|
|
|
62
69
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
//
|
|
67
|
-
//
|
|
70
|
+
async generateCard(prompt: string, content: string){
|
|
71
|
+
let generateCards = new GenerateCards(this.openAiService);
|
|
72
|
+
let cardgenResponse = await generateCards.generateCards(prompt ?? '', content);
|
|
73
|
+
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
74
|
+
// response['type'] = 'card_gen';
|
|
75
|
+
return cardgenResponse;
|
|
76
|
+
}
|
|
68
77
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
78
|
+
async generateTypology(prompt:string){
|
|
79
|
+
let response = await new GenerateTypology(
|
|
80
|
+
this.openAiService,
|
|
81
|
+
prompt,
|
|
82
|
+
this.parsedContent,
|
|
83
|
+
this.expectedFields,
|
|
84
|
+
).generate();
|
|
85
|
+
return response;
|
|
86
|
+
}
|
|
77
87
|
|
|
78
|
-
|
|
88
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
2
|
+
|
|
3
|
+
export class GenerateCards {
|
|
4
|
+
openAiService: OpenAiService;
|
|
5
|
+
constructor(openAiService: OpenAiService) {
|
|
6
|
+
this.openAiService = openAiService;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
async generateCards(prompt: string, parsedContent: string) {
|
|
10
|
+
let response = await this.openAiService?.sendRequest(prompt, parsedContent);
|
|
11
|
+
console.log("response to card generation ", response);
|
|
12
|
+
response["type"] = "card_gen";
|
|
13
|
+
response.metadata = {
|
|
14
|
+
"req_time": response.generated_at,
|
|
15
|
+
"req_type": response.type,
|
|
16
|
+
"req_tokens": response.usage_data?.prompt_tokens,
|
|
17
|
+
"res_tokens": response.usage_data?.completion_tokens,
|
|
18
|
+
};
|
|
19
|
+
if(response.status_code == 200){
|
|
20
|
+
return this.parse(response);
|
|
21
|
+
} else {
|
|
22
|
+
return response;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
parse(generatedData: any) {
|
|
27
|
+
const cardData = [];
|
|
28
|
+
const usage_data = generatedData.metadata;
|
|
29
|
+
const created_at = generatedData.created_at;
|
|
30
|
+
const status_code = generatedData.status_code;
|
|
31
|
+
const missing_concepts = generatedData.generated_content.missing_concepts;
|
|
32
|
+
const missing_facts = generatedData.generated_content.missing_facts;
|
|
33
|
+
const unparsedTestCards = generatedData.generated_content.test_cards;
|
|
34
|
+
|
|
35
|
+
for (let elem of unparsedTestCards) {
|
|
36
|
+
if (elem.type == "flash") {
|
|
37
|
+
cardData.push(this.parseFlashCard(elem));
|
|
38
|
+
} else if (elem.type == "mcq") {
|
|
39
|
+
cardData.push(this.parseMcqCard(elem));
|
|
40
|
+
} else if (elem.type == "cloze") {
|
|
41
|
+
cardData.push(this.parseClozeCard(elem));
|
|
42
|
+
} else if (elem.type == "match") {
|
|
43
|
+
cardData.push(this.parseMatchCard(elem));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
usage_data["created_at"] = created_at;
|
|
47
|
+
usage_data["type"] = "card_gen";
|
|
48
|
+
|
|
49
|
+
return {
|
|
50
|
+
status_code: status_code,
|
|
51
|
+
metadata: usage_data,
|
|
52
|
+
missing_concepts: missing_concepts,
|
|
53
|
+
missing_facts: missing_facts,
|
|
54
|
+
cards_data: cardData,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
parseFlashCard(data: any) {
|
|
59
|
+
let displayTitle = this.generateFlashCardDisplayTitle(
|
|
60
|
+
data.card_content.front,
|
|
61
|
+
data.card_content.back
|
|
62
|
+
);
|
|
63
|
+
let flashCardData = {
|
|
64
|
+
type: data.type,
|
|
65
|
+
heading: data.card_reference,
|
|
66
|
+
displayTitle: displayTitle,
|
|
67
|
+
content: {
|
|
68
|
+
front_content: data.card_content.front,
|
|
69
|
+
back_content: data.card_content.back,
|
|
70
|
+
},
|
|
71
|
+
concepts: data.concepts,
|
|
72
|
+
facts: data.facts,
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return flashCardData;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
generateFlashCardDisplayTitle(front: string, back: string) {
|
|
79
|
+
return `${front} ---- ${back}`;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
parseMcqCard(data: any) {
|
|
83
|
+
let mcqAnswers = [];
|
|
84
|
+
for (let choice of data.card_content.choices) {
|
|
85
|
+
let answer = {
|
|
86
|
+
answer: choice.choice,
|
|
87
|
+
is_correct: choice.is_correct,
|
|
88
|
+
};
|
|
89
|
+
mcqAnswers.push(answer);
|
|
90
|
+
}
|
|
91
|
+
let displayTitle = this.generateMcqCardDisplayTitle(
|
|
92
|
+
data.card_content.prompt,
|
|
93
|
+
mcqAnswers
|
|
94
|
+
);
|
|
95
|
+
let mcqCard = {
|
|
96
|
+
type: data.type,
|
|
97
|
+
heading: data.card_reference,
|
|
98
|
+
displayTitle: displayTitle,
|
|
99
|
+
content: {
|
|
100
|
+
question: data.card_content.prompt,
|
|
101
|
+
answers: mcqAnswers,
|
|
102
|
+
},
|
|
103
|
+
concepts: data.concepts,
|
|
104
|
+
facts: data.facts,
|
|
105
|
+
};
|
|
106
|
+
return mcqCard;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
generateMcqCardDisplayTitle(question: string, answers: any) {
|
|
110
|
+
let answersString = [];
|
|
111
|
+
for (let option of answers) {
|
|
112
|
+
let currentIndex = answers.indexOf(option) + 1;
|
|
113
|
+
let temp = `${currentIndex} . ${option.answer} `;
|
|
114
|
+
answersString.push(temp);
|
|
115
|
+
}
|
|
116
|
+
let resultString = answersString.join("");
|
|
117
|
+
let finalDisplayTitle = `${question} ---- ${resultString}`;
|
|
118
|
+
return finalDisplayTitle;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
parseClozeCard(data: any) {
|
|
122
|
+
let displayTitle = this.generateClozeCardDisplayTitle(
|
|
123
|
+
data.card_content.text,
|
|
124
|
+
data.card_content.options
|
|
125
|
+
);
|
|
126
|
+
let clozeCardData = {
|
|
127
|
+
type: data.type,
|
|
128
|
+
heading: data.card_reference,
|
|
129
|
+
displayTitle: displayTitle,
|
|
130
|
+
content: {
|
|
131
|
+
question: data.card_content.text,
|
|
132
|
+
options: data.card_content.options,
|
|
133
|
+
},
|
|
134
|
+
concepts: data.concepts,
|
|
135
|
+
facts: data.facts,
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
return clozeCardData;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
generateClozeCardDisplayTitle(question: string, answers: any) {
|
|
142
|
+
let optionsString = answers
|
|
143
|
+
.map((item: { option: any }) => item.option)
|
|
144
|
+
.join(", ");
|
|
145
|
+
return `${question} ---- ${optionsString}`;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
parseMatchCard(cardData: any) {
|
|
149
|
+
let data = cardData.card_content;
|
|
150
|
+
const transformedData: { [key: string]: string[] } = {};
|
|
151
|
+
|
|
152
|
+
for (let key in data) {
|
|
153
|
+
if (data.hasOwnProperty(key)) {
|
|
154
|
+
transformedData[key] = [data[key]];
|
|
155
|
+
// let value = data[key].replace(/[\[\]]/g, '');
|
|
156
|
+
// let items = data[key].split(',').map((item: string) => item.trim());
|
|
157
|
+
// map.set(key, items);
|
|
158
|
+
// }
|
|
159
|
+
}
|
|
160
|
+
let displayTitle = this.generateMatchCardDisplayTitle(transformedData);
|
|
161
|
+
let matchCard = {
|
|
162
|
+
type: cardData.type,
|
|
163
|
+
heading: cardData.card_reference,
|
|
164
|
+
content: transformedData,
|
|
165
|
+
// content: cardData.card_content,
|
|
166
|
+
displayTitle: displayTitle,
|
|
167
|
+
concepts: cardData.concepts,
|
|
168
|
+
facts: cardData.facts,
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
return matchCard;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
generateMatchCardDisplayTitle(answers: any) {
|
|
176
|
+
let titles: string[] = [];
|
|
177
|
+
let counter = 65;
|
|
178
|
+
for (let key in answers) {
|
|
179
|
+
if (answers.hasOwnProperty(key)) {
|
|
180
|
+
let value = answers[key];
|
|
181
|
+
// let items = value.split(',').map((item: string) => item.trim());
|
|
182
|
+
// items.forEach((item: any) => {
|
|
183
|
+
let letter = String.fromCharCode(counter);
|
|
184
|
+
titles.push(`${letter}. ${key} -- ${value}`);
|
|
185
|
+
counter++;
|
|
186
|
+
// });
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
let displayTitle = titles.join(",");
|
|
190
|
+
return displayTitle;
|
|
191
|
+
}
|
|
192
|
+
}
|
|
@@ -32,7 +32,7 @@ json
|
|
|
32
32
|
|
|
33
33
|
**Criteria**
|
|
34
34
|
• Each test card must include at least one concept or fact.
|
|
35
|
-
• Flashcards must not exceed 15% of the total number of cards.
|
|
35
|
+
• Deprioritize the Flashcards, must not exceed 15% of the total number of cards.
|
|
36
36
|
• Each concept and fact must have at least one test card.
|
|
37
37
|
|
|
38
38
|
Further instructions are provided below.
|
|
@@ -117,16 +117,17 @@ json
|
|
|
117
117
|
json
|
|
118
118
|
{
|
|
119
119
|
"type": "cloze",
|
|
120
|
-
"card_content":
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
{"option": "
|
|
124
|
-
{"option": "
|
|
125
|
-
{"option": "
|
|
126
|
-
|
|
127
|
-
"
|
|
120
|
+
"card_content":{
|
|
121
|
+
"text": "<clozed_text>",
|
|
122
|
+
"options": [
|
|
123
|
+
{"option" : "<cloze_0>", "cloze" : "<position_0>"},
|
|
124
|
+
{"option" : "<cloze_1>", "cloze" : "<position_1>,
|
|
125
|
+
{"option" : "<cloze_2>", "cloze" : "<position_2>"},
|
|
126
|
+
....
|
|
127
|
+
{"option" : "<cloze_6>", "cloze" : "<position_6>"},
|
|
128
128
|
]
|
|
129
|
-
|
|
129
|
+
|
|
130
|
+
}
|
|
130
131
|
"card_reference": "source_title#heading",
|
|
131
132
|
"concepts": ["Concept1", "Concept2", "..."],
|
|
132
133
|
"facts": ["Fact1", "Fact2", "..."]
|
|
@@ -144,10 +145,12 @@ json
|
|
|
144
145
|
{
|
|
145
146
|
"type": "match",
|
|
146
147
|
"card_content": {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
148
|
+
"<left_text1>": "<right_text1>",
|
|
149
|
+
"<left_text2>": "<right_text2>",
|
|
150
|
+
"<left_text3>": "<right_text3>",
|
|
151
|
+
...
|
|
152
|
+
"<left_text8>": "<right_text8>"
|
|
153
|
+
}
|
|
151
154
|
"card_reference": "source_title#heading",
|
|
152
155
|
"concepts": ["Concept1", "Concept2", "..."],
|
|
153
156
|
"facts": ["Fact1", "Fact2", "..."]
|
|
@@ -205,6 +208,10 @@ json
|
|
|
205
208
|
"option: "notes",
|
|
206
209
|
"cloze": "c0"
|
|
207
210
|
},
|
|
211
|
+
{
|
|
212
|
+
"option: "chords",
|
|
213
|
+
"cloze": null
|
|
214
|
+
},
|
|
208
215
|
{
|
|
209
216
|
"option: "scale",
|
|
210
217
|
"cloze": "c1"
|
|
@@ -213,17 +220,14 @@ json
|
|
|
213
220
|
"option: "mode",
|
|
214
221
|
"cloze": "c2"
|
|
215
222
|
},
|
|
216
|
-
|
|
217
|
-
"option: "chords",
|
|
218
|
-
"cloze": "null"
|
|
219
|
-
},
|
|
223
|
+
|
|
220
224
|
{
|
|
221
225
|
"option: "tilda",
|
|
222
|
-
"cloze":
|
|
226
|
+
"cloze": null
|
|
223
227
|
},
|
|
224
228
|
{
|
|
225
229
|
"option: "score",
|
|
226
|
-
"cloze":
|
|
230
|
+
"cloze": null
|
|
227
231
|
},
|
|
228
232
|
"... up to a maximum of 8 choices total"
|
|
229
233
|
]
|
|
@@ -238,10 +242,11 @@ Maximum character length for an individual cloze: 90
|
|
|
238
242
|
The schema for match type cards are as follows.
|
|
239
243
|
json
|
|
240
244
|
{
|
|
241
|
-
"
|
|
242
|
-
"
|
|
243
|
-
"
|
|
244
|
-
|
|
245
|
+
"<left_text1>": "<right_text1>",
|
|
246
|
+
"<left_text2>": "<right_text2>",
|
|
247
|
+
"<left_text3>": "<right_text3>",
|
|
248
|
+
...
|
|
249
|
+
"<left_text8>": "<right_text8>"
|
|
245
250
|
}
|
|
246
251
|
|
|
247
252
|
Maximum character length for each item in a pair: 42
|
|
@@ -259,6 +264,7 @@ Once you are done generating the test cards, review the full list of concepts an
|
|
|
259
264
|
3. Repeat this step until all concepts and facts are covered.
|
|
260
265
|
|
|
261
266
|
Only stop generating test questions once you believe there is sufficient testing material for learners to fully understand the concepts and remember the facts. The same concept or fact can have multiple test cards, so continue creating test cards until you are confident that there are enough for learners to fully grasp the source material.
|
|
267
|
+
|
|
262
268
|
`;
|
|
263
269
|
|
|
264
270
|
|
|
@@ -266,4 +272,3 @@ export function returnCardGenPrompt(){
|
|
|
266
272
|
return promptString;
|
|
267
273
|
}
|
|
268
274
|
|
|
269
|
-
|