only_ever_generator 8.4.6 → 8.4.7
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.d.ts +6 -3
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +11 -17
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +2 -3
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +22 -15
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/prompt_data.d.ts +4 -4
- package/dist/constants/prompt_data.js +302 -302
- package/dist/constants/prompts/card_gen_prompt.js +160 -160
- package/dist/constants/prompts/typology_prompt.js +131 -131
- package/dist/constants/source_data.d.ts +171 -171
- package/dist/constants/source_data.js +973 -973
- package/dist/embedding_generation/local_consolidation.js +104 -104
- package/dist/helper/build_concept_facts_schema.d.ts +42 -42
- package/dist/helper/build_concept_facts_schema.js +44 -44
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.d.ts +1 -9
- package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.js +47 -50
- package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.js +20 -5
- package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.js +18 -7
- package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -9
- package/dist/index.js.map +1 -1
- package/dist/parse/response_format_card.d.ts +176 -176
- package/dist/parse/response_format_card.js +371 -371
- package/dist/parse/response_format_typology.d.ts +1 -1
- package/dist/parse/response_format_typology.js +46 -46
- package/dist/services/get_prompts.d.ts +8 -7
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +69 -21
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts +2 -3
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +25 -15
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +2 -1
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +24 -13
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts +2 -3
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +24 -13
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +39 -38
- package/src/bootstrap/app.ts +418 -416
- package/src/card_gen/generate_cards.ts +347 -345
- package/src/config.ts +11 -11
- package/src/constants/api_constants.ts +7 -7
- package/src/constants/prompts/card_gen_prompt.ts +164 -164
- package/src/constants/prompts/typology_prompt.ts +139 -139
- package/src/embedding_generation/consolidation/global_consolidation.ts +96 -96
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -141
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -98
- package/src/embedding_generation/generate_embeddings.ts +42 -42
- package/src/embedding_generation/parse_embedding_response.ts +31 -31
- package/src/enums/card_type_enum.ts +6 -6
- package/src/gap_fill/calculate_gap_fill.ts +50 -50
- package/src/helper/get_id_from_title.ts +33 -33
- package/src/helper/mongo_helper.ts +29 -29
- package/src/helper/openai_helper.ts +20 -20
- package/src/helper/qdrant_db_methods.ts +77 -77
- package/src/helper/schema_helper/build_card_schema.ts +74 -98
- package/src/helper/schema_helper/build_classify_summarize_schema.ts +43 -43
- package/src/helper/schema_helper/build_concept_facts_schema.ts +45 -31
- package/src/helper/schema_helper/build_summary_schema.ts +43 -32
- package/src/index.ts +71 -73
- package/src/logger.ts +65 -65
- package/src/parse/parse_card/parse_cloze_card.ts +146 -146
- package/src/parse/parse_card/parse_flash_cards.ts +42 -42
- package/src/parse/parse_card/parse_match_card.ts +104 -104
- package/src/parse/parse_card/parse_mcq_card.ts +114 -114
- package/src/parse/parse_card_response.ts +197 -197
- package/src/parse/parse_source_content.ts +212 -212
- package/src/services/get_prompts.ts +164 -112
- package/src/services/open_ai_service.ts +89 -89
- package/src/services/qdrant_service.ts +10 -10
- package/src/types/base_param_type.ts +13 -13
- package/src/types/mongo_concept_fact_type.ts +12 -12
- package/src/types/parsed_card_type.ts +39 -39
- package/src/types/raw_card_response_types/generated_card_response_type.ts +59 -59
- package/src/types/source_taxonomy_type.ts +24 -24
- package/src/typology-parsed-response.ts +1932 -1932
- package/src/typology_gen/generate_concept_facts.ts +180 -169
- package/src/typology_gen/generate_typology.ts +203 -189
- package/src/typology_gen/summarize.ts +176 -164
- package/src/utils/distributed_quote_restoration.ts +80 -80
- package/src/utils/generate_args.ts +29 -29
- package/src/utils/parse_openai_response.ts +19 -19
- package/src/utils/sanitize_strings.ts +65 -65
- package/tsconfig.json +16 -16
- package/dist/constants/default_generation_variables.d.ts +0 -3
- package/dist/constants/default_generation_variables.d.ts.map +0 -1
- package/dist/constants/default_generation_variables.js +0 -580
- package/dist/constants/default_generation_variables.js.map +0 -1
- package/dist/services/prompts_test.d.ts +0 -10
- package/dist/services/prompts_test.d.ts.map +0 -1
- package/dist/services/prompts_test.js +0 -227
- package/dist/services/prompts_test.js.map +0 -1
- package/dist/types/generation_variables_schema.d.ts +0 -14
- package/dist/types/generation_variables_schema.d.ts.map +0 -1
- package/dist/types/generation_variables_schema.js +0 -3
- package/dist/types/generation_variables_schema.js.map +0 -1
- package/dist/utils/test.d.ts +0 -2
- package/dist/utils/test.d.ts.map +0 -1
- package/dist/utils/test.js +0 -5
- package/dist/utils/test.js.map +0 -1
- package/src/constants/default_generation_variables.ts +0 -624
- package/src/types/generation_variables_schema.ts +0 -16
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function returnTypologyData(): any;
|
|
1
|
+
export declare function returnTypologyData(): any;
|
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.returnTypologyData = returnTypologyData;
|
|
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
|
-
}
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.returnTypologyData = returnTypologyData;
|
|
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
47
|
//# sourceMappingURL=response_format_typology.js.map
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
export declare const promptIds: {
|
|
2
|
-
classify: string;
|
|
3
|
-
conceptFacts: string;
|
|
4
|
-
cardGeneration: string;
|
|
5
|
-
missingConceptsFacts: string;
|
|
6
|
-
summarize: string;
|
|
7
|
-
};
|
|
8
1
|
export declare const getPrompts: (sourceType: string, cardGenerationType: string[]) => Promise<{
|
|
2
|
+
typology: {
|
|
3
|
+
prompt: any;
|
|
4
|
+
ids: string[];
|
|
5
|
+
};
|
|
6
|
+
card_gen: {
|
|
7
|
+
prompt: any;
|
|
8
|
+
ids: string[];
|
|
9
|
+
};
|
|
9
10
|
card_instructions: any;
|
|
10
11
|
card_examples: any;
|
|
11
12
|
bloom_instructions: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_prompts.d.ts","sourceRoot":"","sources":["../../src/services/get_prompts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get_prompts.d.ts","sourceRoot":"","sources":["../../src/services/get_prompts.ts"],"names":[],"mappings":"AAuDA,eAAO,MAAM,UAAU,GACrB,YAAY,MAAM,EAClB,oBAAoB,MAAM,EAAE;;;;;;;;;;;;EA0G7B,CAAC"}
|
|
@@ -9,14 +9,40 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.getPrompts =
|
|
12
|
+
exports.getPrompts = void 0;
|
|
13
13
|
const mongo_helper_1 = require("../helper/mongo_helper");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
14
|
+
const typologyDocs = {
|
|
15
|
+
role: "676528fc59c0563f42607add",
|
|
16
|
+
input: "6765298059c0563f42607ade",
|
|
17
|
+
steps: "6765298b59c0563f42607adf",
|
|
18
|
+
schema: "6765299559c0563f42607ae0",
|
|
19
|
+
fields: "676529a259c0563f42607ae1",
|
|
20
|
+
concepts: "676529b759c0563f42607ae2",
|
|
21
|
+
facts: "67652b1659c0563f42607aea",
|
|
22
|
+
generate: "676529c259c0563f42607ae3",
|
|
23
|
+
summarize: "676529d259c0563f42607ae4",
|
|
24
|
+
};
|
|
25
|
+
const cardGenDocs = {
|
|
26
|
+
role: "676526c959c0563f42607ad4",
|
|
27
|
+
inputs: "676526c959c0563f42607ad5",
|
|
28
|
+
steps: "676526c959c0563f42607ad6",
|
|
29
|
+
schema: "676526c959c0563f42607ad7",
|
|
30
|
+
cloze: "6765270859c0563f42607ad8",
|
|
31
|
+
flash: "6765274159c0563f42607ad9",
|
|
32
|
+
match: "6765276959c0563f42607adb",
|
|
33
|
+
mcq: "6765275f59c0563f42607ada",
|
|
34
|
+
coverage: "6765277a59c0563f42607adc",
|
|
35
|
+
};
|
|
36
|
+
const videoTypologyDocs = {
|
|
37
|
+
role: "676529e259c0563f42607ae5",
|
|
38
|
+
inputs: "676529f059c0563f42607ae6",
|
|
39
|
+
steps: "6765298b59c0563f42607adf",
|
|
40
|
+
schema: "67652a2559c0563f42607ae7",
|
|
41
|
+
fields: "676529a259c0563f42607ae1",
|
|
42
|
+
concepts: "67652a3459c0563f42607ae8",
|
|
43
|
+
facts: "67652a4459c0563f42607ae9",
|
|
44
|
+
generate: "676529c259c0563f42607ae3",
|
|
45
|
+
summarize: "676529d259c0563f42607ae4",
|
|
20
46
|
};
|
|
21
47
|
const cardGenInstructionsDocs = {
|
|
22
48
|
cloze: "6780d21318f81be17e39f5c1",
|
|
@@ -37,15 +63,9 @@ const getPrompts = (sourceType, cardGenerationType) => __awaiter(void 0, void 0,
|
|
|
37
63
|
// const typologyDocs = JSON.parse(baseConfig.typologyPrompts);
|
|
38
64
|
// const cardGenerationDocs = JSON.parse(baseConfig.cardGenerationPrompts);
|
|
39
65
|
// const videoTypologyDocs = JSON.parse(baseConfig.videoTypologyPrompts);
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
// const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
|
|
44
|
-
// ObjectId.createFromHexString(e)
|
|
45
|
-
// );
|
|
46
|
-
// const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
|
|
47
|
-
// (e: any) => ObjectId.createFromHexString(e)
|
|
48
|
-
// );
|
|
66
|
+
const typologyObjectIds = Object.values(typologyDocs).map((e) => mongo_helper_1.ObjectId.createFromHexString(e.toString()));
|
|
67
|
+
const cardGenObjectIds = Object.values(cardGenDocs).map((e) => mongo_helper_1.ObjectId.createFromHexString(e));
|
|
68
|
+
const typologyVideoObjectIds = Object.values(videoTypologyDocs).map((e) => mongo_helper_1.ObjectId.createFromHexString(e));
|
|
49
69
|
// Filter card generation instructions and examples based on cardGenerationType array
|
|
50
70
|
const filteredCardGenInstructions = {};
|
|
51
71
|
const filteredCardGenExamples = {};
|
|
@@ -62,14 +82,42 @@ const getPrompts = (sourceType, cardGenerationType) => __awaiter(void 0, void 0,
|
|
|
62
82
|
const cardGenInstructionsObjectIds = Object.values(filteredCardGenInstructions).map((e) => mongo_helper_1.ObjectId.createFromHexString(e));
|
|
63
83
|
const cardGenExamplesObjectIds = Object.values(filteredCardGenExamples).map((e) => mongo_helper_1.ObjectId.createFromHexString(e));
|
|
64
84
|
const bloomInstructionsObjectIds = Object.values(bloomInstructionsDocs).map((e) => mongo_helper_1.ObjectId.createFromHexString(e));
|
|
85
|
+
const typology = yield getPromptString(typologyObjectIds);
|
|
86
|
+
const card_generation = yield getPromptString(cardGenObjectIds);
|
|
87
|
+
const video_typology = yield getPromptString(typologyVideoObjectIds);
|
|
65
88
|
const cardInstructions = yield getPromptString(cardGenInstructionsObjectIds);
|
|
66
89
|
const cardExamples = yield getPromptString(cardGenExamplesObjectIds);
|
|
67
90
|
const bloomInstructions = yield getPromptString(bloomInstructionsObjectIds);
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
91
|
+
if (sourceType === "video") {
|
|
92
|
+
return {
|
|
93
|
+
typology: {
|
|
94
|
+
prompt: video_typology,
|
|
95
|
+
ids: Object.values(videoTypologyDocs),
|
|
96
|
+
},
|
|
97
|
+
card_gen: {
|
|
98
|
+
prompt: card_generation,
|
|
99
|
+
ids: Object.values(cardGenDocs),
|
|
100
|
+
},
|
|
101
|
+
card_instructions: cardInstructions,
|
|
102
|
+
card_examples: cardExamples,
|
|
103
|
+
bloom_instructions: bloomInstructions,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
return {
|
|
108
|
+
typology: {
|
|
109
|
+
prompt: typology,
|
|
110
|
+
ids: Object.values(typologyDocs),
|
|
111
|
+
},
|
|
112
|
+
card_gen: {
|
|
113
|
+
prompt: card_generation,
|
|
114
|
+
ids: Object.values(cardGenDocs),
|
|
115
|
+
},
|
|
116
|
+
card_instructions: cardInstructions,
|
|
117
|
+
card_examples: cardExamples,
|
|
118
|
+
bloom_instructions: bloomInstructions,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
73
121
|
function getPromptString(promptIds) {
|
|
74
122
|
return __awaiter(this, void 0, void 0, function* () {
|
|
75
123
|
const database = yield (0, mongo_helper_1.setUpMongoClient)();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get_prompts.js","sourceRoot":"","sources":["../../src/services/get_prompts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAoE;
|
|
1
|
+
{"version":3,"file":"get_prompts.js","sourceRoot":"","sources":["../../src/services/get_prompts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,yDAAoE;AACpE,MAAM,YAAY,GAAG;IACnB,IAAI,EAAE,0BAA0B;IAChC,KAAK,EAAE,0BAA0B;IACjC,KAAK,EAAE,0BAA0B;IACjC,MAAM,EAAE,0BAA0B;IAClC,MAAM,EAAE,0BAA0B;IAClC,QAAQ,EAAE,0BAA0B;IACpC,KAAK,EAAE,0BAA0B;IACjC,QAAQ,EAAE,0BAA0B;IACpC,SAAS,EAAE,0BAA0B;CACtC,CAAC;AAEF,MAAM,WAAW,GAAG;IAClB,IAAI,EAAE,0BAA0B;IAChC,MAAM,EAAE,0BAA0B;IAClC,KAAK,EAAE,0BAA0B;IACjC,MAAM,EAAE,0BAA0B;IAClC,KAAK,EAAE,0BAA0B;IACjC,KAAK,EAAE,0BAA0B;IACjC,KAAK,EAAE,0BAA0B;IACjC,GAAG,EAAE,0BAA0B;IAC/B,QAAQ,E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iBACF;gBACD;oBACE,sHAAsH;oBACtH,QAAQ,EAAE;wBACR,mBAAmB,EAAE;4BACnB,OAAO,EAAE;gCACP,KAAK,EAAE,aAAa;gCACpB,YAAY,EAAE,EAAE;gCAChB,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE;6BACvC;yBACF;qBACF;iBACF;aACF,CAAC;iBACD,OAAO,EAAE,CAAC;YACb,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC;QAChE,CAAC;KAAA;AACH,CAAC,CAAA,CAAC;AA5GW,QAAA,UAAU,cA4GrB"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
2
|
import { OpenAiService } from "../services/open_ai_service";
|
|
3
|
-
import { GenerationVariablesSchema } from "../types/generation_variables_schema";
|
|
4
3
|
export declare class GenerateConceptFacts {
|
|
5
4
|
openAiService: OpenAiService;
|
|
6
5
|
openAIHelper: OpenAIHelper;
|
|
7
6
|
sourceId: string;
|
|
8
7
|
generationCurriculum: boolean;
|
|
9
|
-
generationVariablesSchema: GenerationVariablesSchema;
|
|
10
8
|
content: {
|
|
11
9
|
title: string;
|
|
12
10
|
h1_headings?: string[];
|
|
@@ -14,12 +12,13 @@ export declare class GenerateConceptFacts {
|
|
|
14
12
|
content: any[];
|
|
15
13
|
};
|
|
16
14
|
type: string;
|
|
15
|
+
promptIdForConceptFacts: string;
|
|
17
16
|
constructor(openAiService: OpenAiService, sourceId: string, content: {
|
|
18
17
|
title: string;
|
|
19
18
|
h1_headings?: string[];
|
|
20
19
|
timecodes?: string[];
|
|
21
20
|
content: any[];
|
|
22
|
-
}, type: string,
|
|
21
|
+
}, type: string, promptIdForConceptFacts: string, generationCurriculum: boolean);
|
|
23
22
|
generate(): Promise<{
|
|
24
23
|
concepts_facts: any;
|
|
25
24
|
metadata: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_concept_facts.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"generate_concept_facts.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAQ5D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,IAAI,EAAE,MAAM,CAAM;IAClB,uBAAuB,EAAE,MAAM,CAAC;gBAErC,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,EACD,IAAI,EAAE,MAAM,EACZ,uBAAuB,EAAE,MAAM,EAC/B,oBAAoB,EAAE,OAAO;IAWzB,QAAQ;;;;IAuGd,SAAS,CAAC,QAAQ,EAAE,GAAG;CA+BxB"}
|
|
@@ -14,17 +14,17 @@ const build_concept_facts_schema_1 = require("../helper/schema_helper/build_conc
|
|
|
14
14
|
const openai_helper_1 = require("../helper/openai_helper");
|
|
15
15
|
const logger_1 = require("../logger");
|
|
16
16
|
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
17
|
-
const
|
|
17
|
+
const jsonrepair_1 = require("jsonrepair");
|
|
18
18
|
class GenerateConceptFacts {
|
|
19
|
-
constructor(openAiService, sourceId, content, type,
|
|
19
|
+
constructor(openAiService, sourceId, content, type, promptIdForConceptFacts, generationCurriculum) {
|
|
20
20
|
this.type = "";
|
|
21
21
|
this.openAiService = openAiService;
|
|
22
22
|
this.openAIHelper = new openai_helper_1.OpenAIHelper(this.openAiService.api_key);
|
|
23
23
|
this.content = content;
|
|
24
|
+
this.promptIdForConceptFacts = promptIdForConceptFacts;
|
|
24
25
|
this.type = type;
|
|
25
26
|
this.sourceId = sourceId;
|
|
26
27
|
this.generationCurriculum = generationCurriculum;
|
|
27
|
-
this.generationVariablesSchema = generationVariablesSchema;
|
|
28
28
|
}
|
|
29
29
|
generate() {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,13 +33,11 @@ class GenerateConceptFacts {
|
|
|
33
33
|
const headings = this.type === "text"
|
|
34
34
|
? this.content.h1_headings || [""]
|
|
35
35
|
: this.content.timecodes || [""];
|
|
36
|
-
|
|
37
|
-
// this.generationVariablesSchema.output_schema.concepts_facts;
|
|
38
|
-
const schema = yield (0, build_concept_facts_schema_1.buildConceptFactSchema)(headings.length > 0 ? headings : [""], this.generationVariablesSchema.output_schema.concepts_facts);
|
|
36
|
+
const schema = yield (0, build_concept_facts_schema_1.buildConceptFactSchema)(headings.length > 0 ? headings : [""], "concept_fact_gen_schema", true);
|
|
39
37
|
const openAiResponse = yield this.openAIHelper.openAI.responses.create({
|
|
40
38
|
prompt: {
|
|
41
|
-
id:
|
|
42
|
-
|
|
39
|
+
id: this.promptIdForConceptFacts,
|
|
40
|
+
version: "200",
|
|
43
41
|
variables: {
|
|
44
42
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
45
43
|
},
|
|
@@ -126,17 +124,29 @@ class GenerateConceptFacts {
|
|
|
126
124
|
});
|
|
127
125
|
}
|
|
128
126
|
parseJson(response) {
|
|
127
|
+
let parsedJson;
|
|
129
128
|
try {
|
|
130
|
-
|
|
131
|
-
if (concepts_facts) {
|
|
132
|
-
return concepts_facts.map((item) => {
|
|
133
|
-
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
134
|
-
});
|
|
135
|
-
}
|
|
129
|
+
parsedJson = JSON.parse(response.output_text);
|
|
136
130
|
}
|
|
137
131
|
catch (e) {
|
|
138
|
-
|
|
132
|
+
// If original JSON parse fails, attempt to repair and parse
|
|
133
|
+
try {
|
|
134
|
+
const repairedJson = (0, jsonrepair_1.jsonrepair)(response.output_text);
|
|
135
|
+
parsedJson = JSON.parse(repairedJson);
|
|
136
|
+
}
|
|
137
|
+
catch (repairError) {
|
|
138
|
+
// If repair also fails, throw exception
|
|
139
|
+
throw new logger_1.ParsingError("Something went wrong in repairing the json", response);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Process the parsed content (same flow for both original and repaired JSON)
|
|
143
|
+
const concepts_facts = parsedJson.concepts_facts;
|
|
144
|
+
if (concepts_facts) {
|
|
145
|
+
return concepts_facts.map((item) => {
|
|
146
|
+
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
147
|
+
});
|
|
139
148
|
}
|
|
149
|
+
return [];
|
|
140
150
|
}
|
|
141
151
|
}
|
|
142
152
|
exports.GenerateConceptFacts = GenerateConceptFacts;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_concept_facts.js","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mGAA4F;AAC5F,2DAAuD;AAEvD,sCAAiE;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AAM,YAAY,GAAG,IAAA,uBAAU,EAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;gBACtD,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;YACxC,CAAC;YAAC,OAAO,WAAW,EAAE,CAAC;gBACrB,wCAAwC;gBACxC,MAAM,IAAI,qBAAY,CACpB,4CAA4C,EAC5C,QAAQ,CACT,CAAC;YACJ,CAAC;QACH,CAAC;QAED,6EAA6E;QAC7E,MAAM,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;QACjD,IAAI,cAAc,EAAE,CAAC;YACnB,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;gBACtC,uCACK,IAAI,KACP,SAAS,EAAE,IAAA,wCAAqB,EAAC,IAAI,CAAC,SAAS,CAAC,IAChD;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;CACF;AAzKD,oDAyKC"}
|
|
@@ -10,13 +10,14 @@ export declare class GenerateTypology {
|
|
|
10
10
|
timecodes?: string[];
|
|
11
11
|
content: any[];
|
|
12
12
|
};
|
|
13
|
+
promptIdForTypology: string;
|
|
13
14
|
expectedFields: Array<string>;
|
|
14
15
|
constructor(openAiService: OpenAiService, type: string, sourceId: string, content: {
|
|
15
16
|
title: string;
|
|
16
17
|
h1_headings?: string[];
|
|
17
18
|
timecodes?: string[];
|
|
18
19
|
content: any[];
|
|
19
|
-
}, expected_fields: Array<string>, generationCurriculum: boolean);
|
|
20
|
+
}, expected_fields: Array<string>, promptIdForTypology: string, generationCurriculum: boolean);
|
|
20
21
|
generate(): Promise<any>;
|
|
21
22
|
parseTypologyOnSuccess(responseData: any): {
|
|
22
23
|
status_code: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAI5D,qBAAa,gBAAgB;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAM;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,mBAAmB,EAAE,MAAM,CAAC;IACnC,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBAE5B,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,EACD,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,EAC9B,mBAAmB,EAAE,MAAM,EAC3B,oBAAoB,EAAE,OAAO;IAYzB,QAAQ;IA2Fd,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;;;;;;;IAgBxC,SAAS,CAAC,QAAQ,EAAE,GAAG;IAoCvB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;;;;IAQ3B,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;CAQ/C"}
|
|
@@ -12,16 +12,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.GenerateTypology = void 0;
|
|
13
13
|
const openai_helper_1 = require("../helper/openai_helper");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
|
-
const get_prompts_1 = require("../services/get_prompts");
|
|
16
15
|
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
16
|
+
const jsonrepair_1 = require("jsonrepair");
|
|
17
17
|
class GenerateTypology {
|
|
18
|
-
constructor(openAiService, type, sourceId, content, expected_fields, generationCurriculum) {
|
|
18
|
+
constructor(openAiService, type, sourceId, content, expected_fields, promptIdForTypology, generationCurriculum) {
|
|
19
19
|
this.type = "";
|
|
20
20
|
this.openAiService = openAiService;
|
|
21
21
|
this.type = type;
|
|
22
22
|
this.sourceId = sourceId;
|
|
23
23
|
this.content = content;
|
|
24
24
|
this.expectedFields = expected_fields.map((elem) => elem.toString().toUpperCase());
|
|
25
|
+
this.promptIdForTypology = promptIdForTypology;
|
|
25
26
|
this.generationCurriculum = generationCurriculum;
|
|
26
27
|
}
|
|
27
28
|
generate() {
|
|
@@ -31,7 +32,7 @@ class GenerateTypology {
|
|
|
31
32
|
const openAIHelper = new openai_helper_1.OpenAIHelper(this.openAiService.api_key);
|
|
32
33
|
const openAiResponse = yield openAIHelper.openAI.responses.create({
|
|
33
34
|
prompt: {
|
|
34
|
-
id:
|
|
35
|
+
id: this.promptIdForTypology,
|
|
35
36
|
variables: {
|
|
36
37
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
37
38
|
},
|
|
@@ -131,20 +132,30 @@ class GenerateTypology {
|
|
|
131
132
|
}
|
|
132
133
|
parseJson(response) {
|
|
133
134
|
var _a;
|
|
135
|
+
let generatedContent;
|
|
134
136
|
try {
|
|
135
|
-
|
|
136
|
-
const summaryCards = (_a = generatedContent === null || generatedContent === void 0 ? void 0 : generatedContent.summary_cards) !== null && _a !== void 0 ? _a : [];
|
|
137
|
-
if (summaryCards) {
|
|
138
|
-
const remappedSummaryCards = summaryCards.map((item) => {
|
|
139
|
-
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
140
|
-
});
|
|
141
|
-
return Object.assign(Object.assign({}, generatedContent), { summary_cards: remappedSummaryCards });
|
|
142
|
-
}
|
|
143
|
-
return generatedContent;
|
|
137
|
+
generatedContent = JSON.parse(response.output_text);
|
|
144
138
|
}
|
|
145
139
|
catch (e) {
|
|
146
|
-
|
|
140
|
+
// If original JSON parse fails, attempt to repair and parse
|
|
141
|
+
try {
|
|
142
|
+
const repairedJson = (0, jsonrepair_1.jsonrepair)(response.output_text);
|
|
143
|
+
generatedContent = JSON.parse(repairedJson);
|
|
144
|
+
}
|
|
145
|
+
catch (repairError) {
|
|
146
|
+
// If repair also fails, throw exception
|
|
147
|
+
throw new logger_1.ParsingError("Something went wrong in repairing the json", response);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
// Process the parsed content (same flow for both original and repaired JSON)
|
|
151
|
+
const summaryCards = (_a = generatedContent === null || generatedContent === void 0 ? void 0 : generatedContent.summary_cards) !== null && _a !== void 0 ? _a : [];
|
|
152
|
+
if (summaryCards) {
|
|
153
|
+
const remappedSummaryCards = summaryCards.map((item) => {
|
|
154
|
+
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
155
|
+
});
|
|
156
|
+
return Object.assign(Object.assign({}, generatedContent), { summary_cards: remappedSummaryCards });
|
|
147
157
|
}
|
|
158
|
+
return generatedContent;
|
|
148
159
|
}
|
|
149
160
|
parseFields(fields) {
|
|
150
161
|
const fieldKeys = ["primary_field", "secondary_field", "tertiary_field"];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;AACvD,sCAAoD;
|
|
1
|
+
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;AACvD,sCAAoD;AAEpD,gEAAkE;AAClE,2CAAwC;AAExC,M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Ac,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;SAC7D,CAAC,CAAC,CAAC;IACN,CAAC;IAEK,sBAAsB,CAAC,YAAiB;;YAC5C,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;YAExC,OAAO;gBACL,WAAW,EAAE,YAAY,CAAC,WAAW;gBACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;aAChC,CAAC;QACJ,CAAC;KAAA;CACF;AApMD,4CAoMC"}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
2
|
import { OpenAiService } from "../services/open_ai_service";
|
|
3
|
-
import { GenerationVariablesSchema } from "../types/generation_variables_schema";
|
|
4
3
|
export declare class GenerateSummaryCards {
|
|
5
4
|
openAiService: OpenAiService;
|
|
6
5
|
openAIHelper: OpenAIHelper;
|
|
7
6
|
sourceId: string;
|
|
8
7
|
generationCurriculum: boolean;
|
|
9
|
-
generationVariablesSchema: GenerationVariablesSchema;
|
|
10
8
|
content: {
|
|
11
9
|
title: string;
|
|
12
10
|
h1_headings?: string[];
|
|
@@ -14,12 +12,13 @@ export declare class GenerateSummaryCards {
|
|
|
14
12
|
content: any[];
|
|
15
13
|
};
|
|
16
14
|
type: string;
|
|
15
|
+
promptIdForSummaryCards: string;
|
|
17
16
|
constructor(openAiService: OpenAiService, sourceId: string, content: {
|
|
18
17
|
title: string;
|
|
19
18
|
h1_headings?: string[];
|
|
20
19
|
timecodes?: string[];
|
|
21
20
|
content: any[];
|
|
22
|
-
}, type: string,
|
|
21
|
+
}, type: string, promptIdForSummaryCards: string, generationCurriculum: boolean);
|
|
23
22
|
generate(): Promise<{
|
|
24
23
|
summary_cards: any;
|
|
25
24
|
metadata: any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAM5D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,IAAI,EAAE,MAAM,CAAM;IAClB,uBAAuB,EAAE,MAAM,CAAC;gBAErC,aAAa,EAAE,aAAa,EAC5B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,EACD,IAAI,EAAE,MAAM,EACZ,uBAAuB,EAAE,MAAM,EAC/B,oBAAoB,EAAE,OAAO;IAWzB,QAAQ;;;;IAsGd,SAAS,CAAC,QAAQ,EAAE,GAAG;CA+BxB"}
|
|
@@ -14,17 +14,17 @@ const openai_helper_1 = require("../helper/openai_helper");
|
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
16
16
|
const build_summary_schema_1 = require("../helper/schema_helper/build_summary_schema");
|
|
17
|
-
const
|
|
17
|
+
const jsonrepair_1 = require("jsonrepair");
|
|
18
18
|
class GenerateSummaryCards {
|
|
19
|
-
constructor(openAiService, sourceId, content, type,
|
|
19
|
+
constructor(openAiService, sourceId, content, type, promptIdForSummaryCards, generationCurriculum) {
|
|
20
20
|
this.type = "";
|
|
21
21
|
this.openAiService = openAiService;
|
|
22
22
|
this.openAIHelper = new openai_helper_1.OpenAIHelper(this.openAiService.api_key);
|
|
23
23
|
this.content = content;
|
|
24
|
+
this.promptIdForSummaryCards = promptIdForSummaryCards;
|
|
24
25
|
this.type = type;
|
|
25
26
|
this.sourceId = sourceId;
|
|
26
27
|
this.generationCurriculum = generationCurriculum;
|
|
27
|
-
this.generationVariablesSchema = generationVariablesSchema;
|
|
28
28
|
}
|
|
29
29
|
generate() {
|
|
30
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -33,11 +33,10 @@ class GenerateSummaryCards {
|
|
|
33
33
|
const headings = this.type === "text"
|
|
34
34
|
? this.content.h1_headings || [""]
|
|
35
35
|
: this.content.timecodes || [""];
|
|
36
|
-
const schema = yield (0, build_summary_schema_1.buildSummarySchema)(headings.length > 0 ? headings : [""],
|
|
37
|
-
// const schema = this.generationVariablesSchema.output_schema.summary;
|
|
36
|
+
const schema = yield (0, build_summary_schema_1.buildSummarySchema)(headings.length > 0 ? headings : [""], "summary_cards", true);
|
|
38
37
|
const openAiResponse = yield this.openAIHelper.openAI.responses.create({
|
|
39
38
|
prompt: {
|
|
40
|
-
id:
|
|
39
|
+
id: this.promptIdForSummaryCards,
|
|
41
40
|
variables: {
|
|
42
41
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
43
42
|
},
|
|
@@ -125,17 +124,29 @@ class GenerateSummaryCards {
|
|
|
125
124
|
});
|
|
126
125
|
}
|
|
127
126
|
parseJson(response) {
|
|
127
|
+
let parsedJson;
|
|
128
128
|
try {
|
|
129
|
-
|
|
130
|
-
if (summaryCards) {
|
|
131
|
-
return summaryCards.map((item) => {
|
|
132
|
-
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
133
|
-
});
|
|
134
|
-
}
|
|
129
|
+
parsedJson = JSON.parse(response.output_text);
|
|
135
130
|
}
|
|
136
131
|
catch (e) {
|
|
137
|
-
|
|
132
|
+
// If original JSON parse fails, attempt to repair and parse
|
|
133
|
+
try {
|
|
134
|
+
const repairedJson = (0, jsonrepair_1.jsonrepair)(response.output_text);
|
|
135
|
+
parsedJson = JSON.parse(repairedJson);
|
|
136
|
+
}
|
|
137
|
+
catch (repairError) {
|
|
138
|
+
// If repair also fails, throw exception
|
|
139
|
+
throw new logger_1.ParsingError("Something went wrong in repairing the json", response);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
// Process the parsed content (same flow for both original and repaired JSON)
|
|
143
|
+
const summaryCards = parsedJson.summary_cards;
|
|
144
|
+
if (summaryCards) {
|
|
145
|
+
return summaryCards.map((item) => {
|
|
146
|
+
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
147
|
+
});
|
|
138
148
|
}
|
|
149
|
+
return [];
|
|
139
150
|
}
|
|
140
151
|
}
|
|
141
152
|
exports.GenerateSummaryCards = GenerateSummaryCards;
|