only_ever_generator 8.4.0 → 8.4.3
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 +3 -6
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +17 -11
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +3 -2
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +14 -8
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/default_generation_variables.d.ts +3 -0
- package/dist/constants/default_generation_variables.d.ts.map +1 -0
- package/dist/constants/default_generation_variables.js +580 -0
- package/dist/constants/default_generation_variables.js.map +1 -0
- package/dist/helper/schema_helper/build_card_schema.d.ts +9 -1
- package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.js +50 -47
- 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 +5 -20
- 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 +7 -18
- package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +66 -62
- package/dist/index.js.map +1 -1
- package/dist/services/get_prompts.d.ts +7 -8
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +21 -69
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/services/prompts_test.d.ts +10 -0
- package/dist/services/prompts_test.d.ts.map +1 -0
- package/dist/services/prompts_test.js +227 -0
- package/dist/services/prompts_test.js.map +1 -0
- package/dist/types/generation_variables_schema.d.ts +14 -0
- package/dist/types/generation_variables_schema.d.ts.map +1 -0
- package/dist/types/generation_variables_schema.js +3 -0
- package/dist/types/generation_variables_schema.js.map +1 -0
- package/dist/typology_gen/generate_concept_facts.d.ts +3 -2
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +7 -4
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +1 -2
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +3 -3
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts +3 -2
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +6 -4
- package/dist/typology_gen/summarize.js.map +1 -1
- package/dist/utils/test.d.ts +2 -0
- package/dist/utils/test.d.ts.map +1 -0
- package/dist/utils/test.js +5 -0
- package/dist/utils/test.js.map +1 -0
- package/package.json +1 -1
- package/src/bootstrap/app.ts +21 -23
- package/src/card_gen/generate_cards.ts +25 -12
- package/src/constants/default_generation_variables.ts +624 -0
- package/src/helper/schema_helper/build_card_schema.ts +73 -49
- package/src/helper/schema_helper/build_concept_facts_schema.ts +4 -18
- package/src/helper/schema_helper/build_summary_schema.ts +6 -17
- package/src/index.ts +65 -63
- package/src/services/get_prompts.ts +22 -74
- package/src/types/generation_variables_schema.ts +16 -0
- package/src/typology_gen/generate_concept_facts.ts +10 -7
- package/src/typology_gen/generate_typology.ts +2 -4
- package/src/typology_gen/summarize.ts +9 -7
|
@@ -1,74 +1,98 @@
|
|
|
1
1
|
import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
|
|
2
|
-
import { setUpMongoClient, ObjectId } from "../mongo_helper";
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Builds card output schema by populating the integrated schemas with concepts, facts, and card-specific schemas
|
|
5
|
+
* @param concepts - Array of concept strings
|
|
6
|
+
* @param facts - Array of fact strings
|
|
7
|
+
* @param card_generation_types - Array of card types to generate (e.g., ["flash", "mcq", "cloze"])
|
|
8
|
+
* @param cardTypeSchemas - Object mapping card types to their integrated schemas from getPrompts (e.g., { flash: {...}, mcq: {...} })
|
|
9
|
+
* @returns Populated schema object ready for use
|
|
10
|
+
*/
|
|
8
11
|
export const buildCardSchema = async (
|
|
9
12
|
concepts: string[],
|
|
10
13
|
facts: string[],
|
|
11
|
-
card_generation_types: string[]
|
|
14
|
+
card_generation_types: string[],
|
|
15
|
+
cardTypeSchemas: Record<string, any>
|
|
12
16
|
) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
const schemaObj = await database.collection("_prompts").findOne({
|
|
16
|
-
_id: objectId,
|
|
17
|
-
});
|
|
18
|
-
if (!schemaObj) {
|
|
19
|
-
throw new Error("Schema not found");
|
|
20
|
-
}
|
|
21
|
-
const schema = schemaObj.schema;
|
|
22
|
-
if (!schema) {
|
|
23
|
-
throw new Error("Schema not found");
|
|
17
|
+
if (!cardTypeSchemas || Object.keys(cardTypeSchemas).length === 0) {
|
|
18
|
+
throw new Error("Card type schemas are required");
|
|
24
19
|
}
|
|
20
|
+
|
|
25
21
|
const conceptsSanitized = sanitizeStringsForSchema(concepts);
|
|
26
22
|
const factsSanitized = sanitizeStringsForSchema(facts);
|
|
27
23
|
|
|
28
|
-
//
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}
|
|
24
|
+
// Use the first available card type schema as the base (all have the same base structure)
|
|
25
|
+
const firstCardType = card_generation_types.find(
|
|
26
|
+
(type) => cardTypeSchemas[type]
|
|
27
|
+
);
|
|
28
|
+
if (!firstCardType) {
|
|
29
|
+
throw new Error("No valid card type schema found");
|
|
30
|
+
}
|
|
35
31
|
|
|
36
|
-
|
|
32
|
+
// Deep clone to avoid mutating the original
|
|
33
|
+
const populatedSchema = JSON.parse(
|
|
34
|
+
JSON.stringify(cardTypeSchemas[firstCardType].schema)
|
|
35
|
+
);
|
|
37
36
|
|
|
38
|
-
//
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
cardTypeSchemas[cardType] = JSON.parse(cardSchemaObj.schema);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
37
|
+
// Populate concepts enum
|
|
38
|
+
if (
|
|
39
|
+
populatedSchema.schema?.properties?.test_cards?.items?.properties?.concepts
|
|
40
|
+
?.items?.enum
|
|
41
|
+
) {
|
|
42
|
+
populatedSchema.schema.properties.test_cards.items.properties.concepts.items.enum =
|
|
43
|
+
conceptsSanitized;
|
|
48
44
|
}
|
|
49
45
|
|
|
50
|
-
//
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
46
|
+
// Populate facts enum
|
|
47
|
+
if (
|
|
48
|
+
populatedSchema.schema?.properties?.test_cards?.items?.properties?.facts
|
|
49
|
+
?.items?.enum
|
|
50
|
+
) {
|
|
51
|
+
populatedSchema.schema.properties.test_cards.items.properties.facts.items.enum =
|
|
52
|
+
factsSanitized;
|
|
53
|
+
}
|
|
56
54
|
|
|
57
55
|
// Replace the type enum with the requested card generation types
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
if (
|
|
57
|
+
populatedSchema.schema?.properties?.test_cards?.items?.properties?.type
|
|
58
|
+
?.enum
|
|
59
|
+
) {
|
|
60
|
+
populatedSchema.schema.properties.test_cards.items.properties.type.enum =
|
|
61
|
+
card_generation_types;
|
|
62
|
+
}
|
|
60
63
|
|
|
61
|
-
//
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
64
|
+
// Extract card-specific schemas from the anyOf of each card type schema
|
|
65
|
+
const filteredCardTypeSchemas: any[] = [];
|
|
66
|
+
for (const cardType of card_generation_types) {
|
|
67
|
+
if (cardTypeSchemas[cardType]) {
|
|
68
|
+
const cardSchema = cardTypeSchemas[cardType];
|
|
69
|
+
// Extract the card-specific schema from the anyOf array
|
|
70
|
+
const cardContentSchema =
|
|
71
|
+
cardSchema.schema?.properties?.test_cards?.items?.properties
|
|
72
|
+
?.card_content?.anyOf?.[0];
|
|
73
|
+
if (cardContentSchema) {
|
|
74
|
+
filteredCardTypeSchemas.push(cardContentSchema);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Replace anyOf array with all card-specific schemas
|
|
80
|
+
if (filteredCardTypeSchemas.length > 0) {
|
|
81
|
+
if (
|
|
82
|
+
populatedSchema.schema?.properties?.test_cards?.items?.properties
|
|
83
|
+
?.card_content
|
|
84
|
+
) {
|
|
85
|
+
populatedSchema.schema.properties.test_cards.items.properties.card_content =
|
|
86
|
+
{
|
|
87
|
+
anyOf: filteredCardTypeSchemas,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
67
90
|
}
|
|
68
91
|
|
|
69
92
|
console.log(
|
|
70
93
|
"Populated Schema",
|
|
71
94
|
JSON.stringify(populatedSchema.schema.properties.test_cards.items, null, 2)
|
|
72
95
|
);
|
|
96
|
+
|
|
73
97
|
return populatedSchema;
|
|
74
98
|
};
|
|
@@ -5,27 +5,13 @@ import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
|
|
|
5
5
|
// Function to populate enums in a parsed schema
|
|
6
6
|
export async function buildConceptFactSchema(
|
|
7
7
|
headings: string[],
|
|
8
|
-
|
|
9
|
-
strict: boolean = true
|
|
8
|
+
conceptFactSchema: any
|
|
10
9
|
) {
|
|
11
|
-
const
|
|
12
|
-
const objectId = new ObjectId("6895ac4baa1cad73b0018061");
|
|
13
|
-
const schemaObj = await database.collection("_prompts").findOne({
|
|
14
|
-
_id: objectId,
|
|
15
|
-
});
|
|
16
|
-
if (!schemaObj) {
|
|
17
|
-
throw new Error("Schema not found");
|
|
18
|
-
}
|
|
19
|
-
const schema = schemaObj.schema;
|
|
20
|
-
if (!schema) {
|
|
21
|
-
throw new Error("Schema not found");
|
|
22
|
-
}
|
|
23
|
-
// Deep clone to avoid mutating the original
|
|
24
|
-
const populatedSchema = JSON.parse(schema);
|
|
10
|
+
const populatedSchema = conceptFactSchema;
|
|
25
11
|
|
|
26
12
|
// Update name and strict mode
|
|
27
|
-
populatedSchema.name = name;
|
|
28
|
-
populatedSchema.strict = strict;
|
|
13
|
+
populatedSchema.name = conceptFactSchema.name;
|
|
14
|
+
populatedSchema.strict = conceptFactSchema.strict;
|
|
29
15
|
|
|
30
16
|
const allowedRefs = [...headings, ""];
|
|
31
17
|
|
|
@@ -4,27 +4,16 @@ import { setUpMongoClient, ObjectId } from "../mongo_helper";
|
|
|
4
4
|
// Function to populate enums in a parsed schema
|
|
5
5
|
export async function buildSummarySchema(
|
|
6
6
|
headings: string[],
|
|
7
|
-
|
|
8
|
-
strict: boolean = true
|
|
7
|
+
summarySchema: any
|
|
9
8
|
) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const schemaObj = await database.collection("_prompts").findOne({
|
|
13
|
-
_id: objectId,
|
|
14
|
-
});
|
|
15
|
-
if (!schemaObj) {
|
|
16
|
-
throw new Error("Schema not found");
|
|
9
|
+
if (!summarySchema) {
|
|
10
|
+
return {};
|
|
17
11
|
}
|
|
18
|
-
const
|
|
19
|
-
if (!schema) {
|
|
20
|
-
throw new Error("Schema not found");
|
|
21
|
-
}
|
|
22
|
-
// Deep clone to avoid mutating the original
|
|
23
|
-
const populatedSchema = JSON.parse(schema);
|
|
12
|
+
const populatedSchema = summarySchema;
|
|
24
13
|
|
|
25
14
|
// Update name and strict mode
|
|
26
|
-
populatedSchema.name = name;
|
|
27
|
-
populatedSchema.strict = strict;
|
|
15
|
+
populatedSchema.name = summarySchema.name;
|
|
16
|
+
populatedSchema.strict = summarySchema.strict;
|
|
28
17
|
|
|
29
18
|
// Sanitize headings to remove quotes for OpenAI structured outputs
|
|
30
19
|
const sanitizedStrings = sanitizeStringsForSchema(headings);
|
package/src/index.ts
CHANGED
|
@@ -1,71 +1,73 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import { OnlyEverGenerator } from "./bootstrap/app";
|
|
3
3
|
import { ObjectId } from "mongodb";
|
|
4
|
-
|
|
4
|
+
import { setUpMongoClient } from "./helper/mongo_helper";
|
|
5
|
+
import { GenerationVariablesSchema } from "./types/generation_variables_schema";
|
|
6
|
+
import { defaultGenerationVariables } from "./constants/default_generation_variables";
|
|
5
7
|
|
|
6
8
|
export { OnlyEverGenerator };
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const app = express();
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
// setUp();
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
12
|
+
app.get("/generate", async (req, res) => {
|
|
13
|
+
const source = new ObjectId("692837542bd1597ff832d383");
|
|
14
|
+
// setUp();
|
|
15
|
+
const database = await setUpMongoClient();
|
|
16
|
+
const openAiKey = process.env.OPEN_AI_KEY;
|
|
17
|
+
const document = await database
|
|
18
|
+
.collection("_source")
|
|
19
|
+
.findOne({ _id: source });
|
|
20
|
+
if (!document) {
|
|
21
|
+
return res.status(404).json({ error: "Source not found" });
|
|
22
|
+
}
|
|
23
|
+
const promptIdForClassify =
|
|
24
|
+
"pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594";
|
|
25
|
+
const promptIdForConceptFacts =
|
|
26
|
+
"pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8";
|
|
27
|
+
const promptIdForCardGeneration =
|
|
28
|
+
"pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6";
|
|
29
|
+
const promptIdForMissingConceptsFacts =
|
|
30
|
+
"pmpt_687ab50298dc8194b214804999d23df10e03b855371691f9";
|
|
31
|
+
const promptIdForSummarize =
|
|
32
|
+
"pmpt_6902c30a973481968395935cc6dfa78605f50d2b01d4afbd";
|
|
33
|
+
// const generationCurriculum = process.env.GENERATION_CURRICULUM;
|
|
34
|
+
const n = process.env.N;
|
|
35
|
+
const generationContent = {
|
|
36
|
+
content: {
|
|
37
|
+
source_id: document.source_id,
|
|
38
|
+
title: document.title,
|
|
39
|
+
headings: document.headings,
|
|
40
|
+
content: document.content,
|
|
41
|
+
fields: [],
|
|
42
|
+
taxonomy: {
|
|
43
|
+
concepts_facts: document.concepts_facts ?? [],
|
|
44
|
+
fields: document.fields ?? [],
|
|
45
|
+
summary_cards: document.summary_cards ?? [],
|
|
46
|
+
learn_value: document.learn_value,
|
|
47
|
+
},
|
|
48
|
+
type: document.type,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const generationVariablesSchema: GenerationVariablesSchema =
|
|
52
|
+
defaultGenerationVariables;
|
|
53
|
+
const generator = new OnlyEverGenerator(
|
|
54
|
+
openAiKey ?? "",
|
|
55
|
+
"gpt-4o-mini",
|
|
56
|
+
generationContent,
|
|
57
|
+
generationVariablesSchema,
|
|
58
|
+
false,
|
|
59
|
+
1
|
|
60
|
+
);
|
|
61
|
+
const response = await generator.generate(true, true, [
|
|
62
|
+
"cloze",
|
|
63
|
+
"mcq",
|
|
64
|
+
"flash",
|
|
65
|
+
"match",
|
|
66
|
+
]);
|
|
67
|
+
console.log("Close");
|
|
68
|
+
res.json(response);
|
|
69
|
+
});
|
|
68
70
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
app.listen(3000, () => {
|
|
72
|
+
console.log("Server is running on port 3000");
|
|
73
|
+
});
|
|
@@ -1,38 +1,11 @@
|
|
|
1
1
|
import { setUpMongoClient, ObjectId } from "../helper/mongo_helper";
|
|
2
|
-
const typologyDocs = {
|
|
3
|
-
role: "676528fc59c0563f42607add",
|
|
4
|
-
input: "6765298059c0563f42607ade",
|
|
5
|
-
steps: "6765298b59c0563f42607adf",
|
|
6
|
-
schema: "6765299559c0563f42607ae0",
|
|
7
|
-
fields: "676529a259c0563f42607ae1",
|
|
8
|
-
concepts: "676529b759c0563f42607ae2",
|
|
9
|
-
facts: "67652b1659c0563f42607aea",
|
|
10
|
-
generate: "676529c259c0563f42607ae3",
|
|
11
|
-
summarize: "676529d259c0563f42607ae4",
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
const cardGenDocs = {
|
|
15
|
-
role: "676526c959c0563f42607ad4",
|
|
16
|
-
inputs: "676526c959c0563f42607ad5",
|
|
17
|
-
steps: "676526c959c0563f42607ad6",
|
|
18
|
-
schema: "676526c959c0563f42607ad7",
|
|
19
|
-
cloze: "6765270859c0563f42607ad8",
|
|
20
|
-
flash: "6765274159c0563f42607ad9",
|
|
21
|
-
match: "6765276959c0563f42607adb",
|
|
22
|
-
mcq: "6765275f59c0563f42607ada",
|
|
23
|
-
coverage: "6765277a59c0563f42607adc",
|
|
24
|
-
};
|
|
25
2
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
concepts: "67652a3459c0563f42607ae8",
|
|
33
|
-
facts: "67652a4459c0563f42607ae9",
|
|
34
|
-
generate: "676529c259c0563f42607ae3",
|
|
35
|
-
summarize: "676529d259c0563f42607ae4",
|
|
3
|
+
export const promptIds = {
|
|
4
|
+
classify: "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
5
|
+
conceptFacts: "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
6
|
+
cardGeneration: "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6",
|
|
7
|
+
missingConceptsFacts: "pmpt_687ab50298dc8194b214804999d23df10e03b855371691f9",
|
|
8
|
+
summarize: "pmpt_6902c30a973481968395935cc6dfa78605f50d2b01d4afbd",
|
|
36
9
|
};
|
|
37
10
|
|
|
38
11
|
const cardGenInstructionsDocs = {
|
|
@@ -60,15 +33,15 @@ export const getPrompts = async (
|
|
|
60
33
|
// const typologyDocs = JSON.parse(baseConfig.typologyPrompts);
|
|
61
34
|
// const cardGenerationDocs = JSON.parse(baseConfig.cardGenerationPrompts);
|
|
62
35
|
// const videoTypologyDocs = JSON.parse(baseConfig.videoTypologyPrompts);
|
|
63
|
-
const typologyObjectIds = Object.values(typologyDocs).map((e: any) =>
|
|
64
|
-
|
|
65
|
-
);
|
|
66
|
-
const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
|
|
67
|
-
|
|
68
|
-
);
|
|
69
|
-
const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
|
|
70
|
-
|
|
71
|
-
);
|
|
36
|
+
// const typologyObjectIds = Object.values(typologyDocs).map((e: any) =>
|
|
37
|
+
// ObjectId.createFromHexString(e.toString())
|
|
38
|
+
// );
|
|
39
|
+
// const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
|
|
40
|
+
// ObjectId.createFromHexString(e)
|
|
41
|
+
// );
|
|
42
|
+
// const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
|
|
43
|
+
// (e: any) => ObjectId.createFromHexString(e)
|
|
44
|
+
// );
|
|
72
45
|
|
|
73
46
|
// Filter card generation instructions and examples based on cardGenerationType array
|
|
74
47
|
const filteredCardGenInstructions: Record<string, string> = {};
|
|
@@ -94,41 +67,16 @@ export const getPrompts = async (
|
|
|
94
67
|
const bloomInstructionsObjectIds = Object.values(bloomInstructionsDocs).map(
|
|
95
68
|
(e: any) => ObjectId.createFromHexString(e)
|
|
96
69
|
);
|
|
97
|
-
|
|
98
|
-
const card_generation = await getPromptString(cardGenObjectIds);
|
|
99
|
-
const video_typology = await getPromptString(typologyVideoObjectIds);
|
|
70
|
+
|
|
100
71
|
const cardInstructions = await getPromptString(cardGenInstructionsObjectIds);
|
|
101
72
|
const cardExamples = await getPromptString(cardGenExamplesObjectIds);
|
|
102
73
|
const bloomInstructions = await getPromptString(bloomInstructionsObjectIds);
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
card_gen: {
|
|
110
|
-
prompt: card_generation,
|
|
111
|
-
ids: Object.values(cardGenDocs),
|
|
112
|
-
},
|
|
113
|
-
card_instructions: cardInstructions,
|
|
114
|
-
card_examples: cardExamples,
|
|
115
|
-
bloom_instructions: bloomInstructions,
|
|
116
|
-
};
|
|
117
|
-
} else {
|
|
118
|
-
return {
|
|
119
|
-
typology: {
|
|
120
|
-
prompt: typology,
|
|
121
|
-
ids: Object.values(typologyDocs),
|
|
122
|
-
},
|
|
123
|
-
card_gen: {
|
|
124
|
-
prompt: card_generation,
|
|
125
|
-
ids: Object.values(cardGenDocs),
|
|
126
|
-
},
|
|
127
|
-
card_instructions: cardInstructions,
|
|
128
|
-
card_examples: cardExamples,
|
|
129
|
-
bloom_instructions: bloomInstructions,
|
|
130
|
-
};
|
|
131
|
-
}
|
|
74
|
+
return {
|
|
75
|
+
card_instructions: cardInstructions,
|
|
76
|
+
card_examples: cardExamples,
|
|
77
|
+
bloom_instructions: bloomInstructions,
|
|
78
|
+
};
|
|
79
|
+
|
|
132
80
|
async function getPromptString(promptIds: ObjectId[]) {
|
|
133
81
|
const database = await setUpMongoClient();
|
|
134
82
|
let result = await database
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export type GenerationVariablesSchema = {
|
|
2
|
+
bloom_instructions: any;
|
|
3
|
+
output_schema: {
|
|
4
|
+
concepts_facts: any;
|
|
5
|
+
summary: any;
|
|
6
|
+
classification: any;
|
|
7
|
+
};
|
|
8
|
+
cards: Record<
|
|
9
|
+
string,
|
|
10
|
+
{
|
|
11
|
+
instructions: string;
|
|
12
|
+
examples: string;
|
|
13
|
+
schema: any;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
};
|
|
@@ -6,12 +6,15 @@ import {
|
|
|
6
6
|
restoreQuotesInObject,
|
|
7
7
|
restoreQuotesInString,
|
|
8
8
|
} from "../utils/sanitize_strings";
|
|
9
|
+
import { GenerationVariablesSchema } from "../types/generation_variables_schema";
|
|
10
|
+
import { promptIds } from "../services/get_prompts";
|
|
9
11
|
|
|
10
12
|
export class GenerateConceptFacts {
|
|
11
13
|
public openAiService: OpenAiService;
|
|
12
14
|
public openAIHelper: OpenAIHelper;
|
|
13
15
|
public sourceId: string;
|
|
14
16
|
public generationCurriculum: boolean;
|
|
17
|
+
public generationVariablesSchema: GenerationVariablesSchema;
|
|
15
18
|
public content: {
|
|
16
19
|
title: string;
|
|
17
20
|
h1_headings?: string[];
|
|
@@ -19,7 +22,6 @@ export class GenerateConceptFacts {
|
|
|
19
22
|
content: any[];
|
|
20
23
|
};
|
|
21
24
|
public type: string = "";
|
|
22
|
-
public promptIdForConceptFacts: string;
|
|
23
25
|
constructor(
|
|
24
26
|
openAiService: OpenAiService,
|
|
25
27
|
sourceId: string,
|
|
@@ -30,16 +32,16 @@ export class GenerateConceptFacts {
|
|
|
30
32
|
content: any[];
|
|
31
33
|
},
|
|
32
34
|
type: string,
|
|
33
|
-
|
|
34
|
-
|
|
35
|
+
generationCurriculum: boolean,
|
|
36
|
+
generationVariablesSchema: GenerationVariablesSchema
|
|
35
37
|
) {
|
|
36
38
|
this.openAiService = openAiService;
|
|
37
39
|
this.openAIHelper = new OpenAIHelper(this.openAiService.api_key);
|
|
38
40
|
this.content = content;
|
|
39
|
-
this.promptIdForConceptFacts = promptIdForConceptFacts;
|
|
40
41
|
this.type = type;
|
|
41
42
|
this.sourceId = sourceId;
|
|
42
43
|
this.generationCurriculum = generationCurriculum;
|
|
44
|
+
this.generationVariablesSchema = generationVariablesSchema;
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
async generate() {
|
|
@@ -48,15 +50,16 @@ export class GenerateConceptFacts {
|
|
|
48
50
|
this.type === "text"
|
|
49
51
|
? this.content.h1_headings || [""]
|
|
50
52
|
: this.content.timecodes || [""];
|
|
53
|
+
// const schema =
|
|
54
|
+
// this.generationVariablesSchema.output_schema.concepts_facts;
|
|
51
55
|
const schema = await buildConceptFactSchema(
|
|
52
56
|
headings.length > 0 ? headings : [""],
|
|
53
|
-
|
|
54
|
-
true
|
|
57
|
+
this.generationVariablesSchema.output_schema.concepts_facts
|
|
55
58
|
);
|
|
56
59
|
const openAiResponse: any =
|
|
57
60
|
await this.openAIHelper.openAI.responses.create({
|
|
58
61
|
prompt: {
|
|
59
|
-
id:
|
|
62
|
+
id: promptIds.conceptFacts,
|
|
60
63
|
// version: "200",
|
|
61
64
|
variables: {
|
|
62
65
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
2
|
import { log_error, ParsingError } from "../logger";
|
|
3
|
+
import { promptIds } from "../services/get_prompts";
|
|
3
4
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
5
|
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
5
6
|
|
|
@@ -14,7 +15,6 @@ export class GenerateTypology {
|
|
|
14
15
|
timecodes?: string[];
|
|
15
16
|
content: any[];
|
|
16
17
|
};
|
|
17
|
-
public promptIdForTypology: string;
|
|
18
18
|
expectedFields: Array<string>;
|
|
19
19
|
constructor(
|
|
20
20
|
openAiService: OpenAiService,
|
|
@@ -27,7 +27,6 @@ export class GenerateTypology {
|
|
|
27
27
|
content: any[];
|
|
28
28
|
},
|
|
29
29
|
expected_fields: Array<string>,
|
|
30
|
-
promptIdForTypology: string,
|
|
31
30
|
generationCurriculum: boolean
|
|
32
31
|
) {
|
|
33
32
|
this.openAiService = openAiService;
|
|
@@ -37,7 +36,6 @@ export class GenerateTypology {
|
|
|
37
36
|
this.expectedFields = expected_fields.map((elem: string) =>
|
|
38
37
|
elem.toString().toUpperCase()
|
|
39
38
|
);
|
|
40
|
-
this.promptIdForTypology = promptIdForTypology;
|
|
41
39
|
this.generationCurriculum = generationCurriculum;
|
|
42
40
|
}
|
|
43
41
|
async generate() {
|
|
@@ -45,7 +43,7 @@ export class GenerateTypology {
|
|
|
45
43
|
const openAIHelper = new OpenAIHelper(this.openAiService.api_key);
|
|
46
44
|
const openAiResponse: any = await openAIHelper.openAI.responses.create({
|
|
47
45
|
prompt: {
|
|
48
|
-
id:
|
|
46
|
+
id: promptIds.classify,
|
|
49
47
|
variables: {
|
|
50
48
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
51
49
|
},
|
|
@@ -3,12 +3,15 @@ import { OpenAiService } from "../services/open_ai_service";
|
|
|
3
3
|
import { log_error, ParsingError } from "../logger";
|
|
4
4
|
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
5
5
|
import { buildSummarySchema } from "../helper/schema_helper/build_summary_schema";
|
|
6
|
+
import { GenerationVariablesSchema } from "../types/generation_variables_schema";
|
|
7
|
+
import { promptIds } from "../services/get_prompts";
|
|
6
8
|
|
|
7
9
|
export class GenerateSummaryCards {
|
|
8
10
|
public openAiService: OpenAiService;
|
|
9
11
|
public openAIHelper: OpenAIHelper;
|
|
10
12
|
public sourceId: string;
|
|
11
13
|
public generationCurriculum: boolean;
|
|
14
|
+
public generationVariablesSchema: GenerationVariablesSchema;
|
|
12
15
|
public content: {
|
|
13
16
|
title: string;
|
|
14
17
|
h1_headings?: string[];
|
|
@@ -16,7 +19,6 @@ export class GenerateSummaryCards {
|
|
|
16
19
|
content: any[];
|
|
17
20
|
};
|
|
18
21
|
public type: string = "";
|
|
19
|
-
public promptIdForSummaryCards: string;
|
|
20
22
|
constructor(
|
|
21
23
|
openAiService: OpenAiService,
|
|
22
24
|
sourceId: string,
|
|
@@ -27,16 +29,16 @@ export class GenerateSummaryCards {
|
|
|
27
29
|
content: any[];
|
|
28
30
|
},
|
|
29
31
|
type: string,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
generationCurriculum: boolean,
|
|
33
|
+
generationVariablesSchema: GenerationVariablesSchema
|
|
32
34
|
) {
|
|
33
35
|
this.openAiService = openAiService;
|
|
34
36
|
this.openAIHelper = new OpenAIHelper(this.openAiService.api_key);
|
|
35
37
|
this.content = content;
|
|
36
|
-
this.promptIdForSummaryCards = promptIdForSummaryCards;
|
|
37
38
|
this.type = type;
|
|
38
39
|
this.sourceId = sourceId;
|
|
39
40
|
this.generationCurriculum = generationCurriculum;
|
|
41
|
+
this.generationVariablesSchema = generationVariablesSchema;
|
|
40
42
|
}
|
|
41
43
|
|
|
42
44
|
async generate() {
|
|
@@ -47,13 +49,13 @@ export class GenerateSummaryCards {
|
|
|
47
49
|
: this.content.timecodes || [""];
|
|
48
50
|
const schema = await buildSummarySchema(
|
|
49
51
|
headings.length > 0 ? headings : [""],
|
|
50
|
-
|
|
51
|
-
true
|
|
52
|
+
this.generationVariablesSchema.output_schema.summary
|
|
52
53
|
);
|
|
54
|
+
// const schema = this.generationVariablesSchema.output_schema.summary;
|
|
53
55
|
const openAiResponse: any =
|
|
54
56
|
await this.openAIHelper.openAI.responses.create({
|
|
55
57
|
prompt: {
|
|
56
|
-
id:
|
|
58
|
+
id: promptIds.summarize,
|
|
57
59
|
variables: {
|
|
58
60
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
59
61
|
},
|