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.
Files changed (68) hide show
  1. package/dist/bootstrap/app.d.ts +3 -6
  2. package/dist/bootstrap/app.d.ts.map +1 -1
  3. package/dist/bootstrap/app.js +17 -11
  4. package/dist/bootstrap/app.js.map +1 -1
  5. package/dist/card_gen/generate_cards.d.ts +3 -2
  6. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  7. package/dist/card_gen/generate_cards.js +14 -8
  8. package/dist/card_gen/generate_cards.js.map +1 -1
  9. package/dist/constants/default_generation_variables.d.ts +3 -0
  10. package/dist/constants/default_generation_variables.d.ts.map +1 -0
  11. package/dist/constants/default_generation_variables.js +580 -0
  12. package/dist/constants/default_generation_variables.js.map +1 -0
  13. package/dist/helper/schema_helper/build_card_schema.d.ts +9 -1
  14. package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
  15. package/dist/helper/schema_helper/build_card_schema.js +50 -47
  16. package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
  17. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
  18. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
  19. package/dist/helper/schema_helper/build_concept_facts_schema.js +5 -20
  20. package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
  21. package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
  22. package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
  23. package/dist/helper/schema_helper/build_summary_schema.js +7 -18
  24. package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js +66 -62
  27. package/dist/index.js.map +1 -1
  28. package/dist/services/get_prompts.d.ts +7 -8
  29. package/dist/services/get_prompts.d.ts.map +1 -1
  30. package/dist/services/get_prompts.js +21 -69
  31. package/dist/services/get_prompts.js.map +1 -1
  32. package/dist/services/prompts_test.d.ts +10 -0
  33. package/dist/services/prompts_test.d.ts.map +1 -0
  34. package/dist/services/prompts_test.js +227 -0
  35. package/dist/services/prompts_test.js.map +1 -0
  36. package/dist/types/generation_variables_schema.d.ts +14 -0
  37. package/dist/types/generation_variables_schema.d.ts.map +1 -0
  38. package/dist/types/generation_variables_schema.js +3 -0
  39. package/dist/types/generation_variables_schema.js.map +1 -0
  40. package/dist/typology_gen/generate_concept_facts.d.ts +3 -2
  41. package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
  42. package/dist/typology_gen/generate_concept_facts.js +7 -4
  43. package/dist/typology_gen/generate_concept_facts.js.map +1 -1
  44. package/dist/typology_gen/generate_typology.d.ts +1 -2
  45. package/dist/typology_gen/generate_typology.d.ts.map +1 -1
  46. package/dist/typology_gen/generate_typology.js +3 -3
  47. package/dist/typology_gen/generate_typology.js.map +1 -1
  48. package/dist/typology_gen/summarize.d.ts +3 -2
  49. package/dist/typology_gen/summarize.d.ts.map +1 -1
  50. package/dist/typology_gen/summarize.js +6 -4
  51. package/dist/typology_gen/summarize.js.map +1 -1
  52. package/dist/utils/test.d.ts +2 -0
  53. package/dist/utils/test.d.ts.map +1 -0
  54. package/dist/utils/test.js +5 -0
  55. package/dist/utils/test.js.map +1 -0
  56. package/package.json +1 -1
  57. package/src/bootstrap/app.ts +21 -23
  58. package/src/card_gen/generate_cards.ts +25 -12
  59. package/src/constants/default_generation_variables.ts +624 -0
  60. package/src/helper/schema_helper/build_card_schema.ts +73 -49
  61. package/src/helper/schema_helper/build_concept_facts_schema.ts +4 -18
  62. package/src/helper/schema_helper/build_summary_schema.ts +6 -17
  63. package/src/index.ts +65 -63
  64. package/src/services/get_prompts.ts +22 -74
  65. package/src/types/generation_variables_schema.ts +16 -0
  66. package/src/typology_gen/generate_concept_facts.ts +10 -7
  67. package/src/typology_gen/generate_typology.ts +2 -4
  68. 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
- // flash:68ef4e1b5a123c94a835c6ab
5
- // cloze:68ef4eb45a123c94a835c6ac
6
- // mcq:68ef4f095a123c94a835c6ad
7
- // match:68ef4fae5a123c94a835c6ae
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
- const database = await setUpMongoClient();
14
- const objectId = new ObjectId("689c5cbd0d9d3bbda64b9584");
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
- // Fetch individual card type schemas based on card_generation_types
29
- const cardTypeObjectIds: { [key: string]: ObjectId } = {
30
- flash: new ObjectId("68ef4e1b5a123c94a835c6ab"),
31
- cloze: new ObjectId("68ef4eb45a123c94a835c6ac"),
32
- mcq: new ObjectId("68ef4f095a123c94a835c6ad"),
33
- match: new ObjectId("68ef4fae5a123c94a835c6ae"),
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
- const cardTypeSchemas: { [key: string]: any } = {};
32
+ // Deep clone to avoid mutating the original
33
+ const populatedSchema = JSON.parse(
34
+ JSON.stringify(cardTypeSchemas[firstCardType].schema)
35
+ );
37
36
 
38
- // Only fetch schemas for the requested card types
39
- for (const cardType of card_generation_types) {
40
- if (cardTypeObjectIds[cardType]) {
41
- const cardSchemaObj = await database.collection("_prompts").findOne({
42
- _id: cardTypeObjectIds[cardType],
43
- });
44
- if (cardSchemaObj && cardSchemaObj.schema) {
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
- // Deep clone to avoid mutating the original
51
- const populatedSchema = JSON.parse(schema);
52
- populatedSchema.schema.properties.test_cards.items.properties.concepts.items.enum =
53
- conceptsSanitized;
54
- populatedSchema.schema.properties.test_cards.items.properties.facts.items.enum =
55
- factsSanitized;
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
- populatedSchema.schema.properties.test_cards.items.properties.type.enum =
59
- card_generation_types;
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
- // Replace anyOf array with individual schemas based on card type
62
- if (Object.keys(cardTypeSchemas).length > 0) {
63
- populatedSchema.schema.properties.test_cards.items.properties.card_content =
64
- {
65
- anyOf: Object.values(cardTypeSchemas),
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
- name: string = "concept_fact_gen_schema",
9
- strict: boolean = true
8
+ conceptFactSchema: any
10
9
  ) {
11
- const database = await setUpMongoClient();
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
- name: string = "summary_cards",
8
- strict: boolean = true
7
+ summarySchema: any
9
8
  ) {
10
- const database = await setUpMongoClient();
11
- const objectId = new ObjectId("690ae043116a8c929f3a4cd5");
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 schema = schemaObj.schema;
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
- // import { database, setUp } from "./helper/mongo_helper";
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
- // const app = express();
10
+ const app = express();
9
11
 
10
- // app.get("/generate", async (req, res) => {
11
- // const source = new ObjectId("692837542bd1597ff832d383");
12
- // setUp();
13
- // const openAiKey = process.env.OPEN_AI_KEY;
14
- // const document = await database
15
- // .collection("_source")
16
- // .findOne({ _id: source });
17
- // if (!document) {
18
- // return res.status(404).json({ error: "Source not found" });
19
- // }
20
- // const promptIdForClassify =
21
- // "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594";
22
- // const promptIdForConceptFacts =
23
- // "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8";
24
- // const promptIdForCardGeneration =
25
- // "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6";
26
- // const promptIdForMissingConceptsFacts =
27
- // "pmpt_687ab50298dc8194b214804999d23df10e03b855371691f9";
28
- // const promptIdForSummarize =
29
- // "pmpt_6902c30a973481968395935cc6dfa78605f50d2b01d4afbd";
30
- // // const generationCurriculum = process.env.GENERATION_CURRICULUM;
31
- // const n = process.env.N;
32
- // const generationContent = {
33
- // content: {
34
- // source_id: document.source_id,
35
- // title: document.title,
36
- // headings: document.headings,
37
- // content: document.content,
38
- // fields: [],
39
- // taxonomy: {
40
- // concepts_facts: document.concepts_facts ?? [],
41
- // fields: document.fields ?? [],
42
- // summary_cards: document.summary_cards ?? [],
43
- // learn_value: document.learn_value,
44
- // },
45
- // type: document.type,
46
- // },
47
- // };
48
- // const generator = new OnlyEverGenerator(
49
- // openAiKey ?? "",
50
- // "gpt-4o-mini",
51
- // generationContent,
52
- // promptIdForClassify ?? "",
53
- // promptIdForConceptFacts ?? "",
54
- // promptIdForCardGeneration ?? "",
55
- // promptIdForSummarize ?? "",
56
- // false,
57
- // 1
58
- // );
59
- // const response = await generator.generate(true, true, [
60
- // "cloze",
61
- // "mcq",
62
- // "flash",
63
- // "match",
64
- // ]);
65
- // console.log("Close");
66
- // res.json(response);
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
- // app.listen(3000, () => {
70
- // console.log("Server is running on port 3000");
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 videoTypologyDocs = {
27
- role: "676529e259c0563f42607ae5",
28
- inputs: "676529f059c0563f42607ae6",
29
- steps: "6765298b59c0563f42607adf",
30
- schema: "67652a2559c0563f42607ae7",
31
- fields: "676529a259c0563f42607ae1",
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
- ObjectId.createFromHexString(e.toString())
65
- );
66
- const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
67
- ObjectId.createFromHexString(e)
68
- );
69
- const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
70
- (e: any) => ObjectId.createFromHexString(e)
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
- const typology = await getPromptString(typologyObjectIds);
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
- if (sourceType === "video") {
104
- return {
105
- typology: {
106
- prompt: video_typology,
107
- ids: Object.values(videoTypologyDocs),
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
- promptIdForConceptFacts: string,
34
- generationCurriculum: boolean
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
- "concept_fact_gen_schema",
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: this.promptIdForConceptFacts,
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: this.promptIdForTypology,
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
- promptIdForSummaryCards: string,
31
- generationCurriculum: boolean
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
- "summary_cards",
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: this.promptIdForSummaryCards,
58
+ id: promptIds.summarize,
57
59
  variables: {
58
60
  heading_type: this.type == "video" ? "timecode" : "h1 heading",
59
61
  },