only_ever_generator 8.4.1 → 8.4.4

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 (62) hide show
  1. package/dist/bootstrap/app.d.ts +1 -6
  2. package/dist/bootstrap/app.d.ts.map +1 -1
  3. package/dist/bootstrap/app.js +6 -11
  4. package/dist/bootstrap/app.js.map +1 -1
  5. package/dist/card_gen/generate_cards.d.ts +1 -2
  6. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  7. package/dist/card_gen/generate_cards.js +3 -3
  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.js +1 -1
  14. package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
  15. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
  16. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
  17. package/dist/helper/schema_helper/build_concept_facts_schema.js +5 -20
  18. package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
  19. package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
  20. package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
  21. package/dist/helper/schema_helper/build_summary_schema.js +7 -18
  22. package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
  23. package/dist/index.d.ts +0 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +12 -9
  26. package/dist/index.js.map +1 -1
  27. package/dist/services/get_prompts.d.ts +7 -8
  28. package/dist/services/get_prompts.d.ts.map +1 -1
  29. package/dist/services/get_prompts.js +21 -69
  30. package/dist/services/get_prompts.js.map +1 -1
  31. package/dist/services/prompts_test.d.ts +10 -0
  32. package/dist/services/prompts_test.d.ts.map +1 -0
  33. package/dist/services/prompts_test.js +227 -0
  34. package/dist/services/prompts_test.js.map +1 -0
  35. package/dist/typology_gen/generate_concept_facts.d.ts +1 -2
  36. package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
  37. package/dist/typology_gen/generate_concept_facts.js +7 -9
  38. package/dist/typology_gen/generate_concept_facts.js.map +1 -1
  39. package/dist/typology_gen/generate_typology.d.ts +1 -2
  40. package/dist/typology_gen/generate_typology.d.ts.map +1 -1
  41. package/dist/typology_gen/generate_typology.js +3 -3
  42. package/dist/typology_gen/generate_typology.js.map +1 -1
  43. package/dist/typology_gen/summarize.d.ts +1 -2
  44. package/dist/typology_gen/summarize.d.ts.map +1 -1
  45. package/dist/typology_gen/summarize.js +6 -9
  46. package/dist/typology_gen/summarize.js.map +1 -1
  47. package/dist/utils/test.d.ts +2 -0
  48. package/dist/utils/test.d.ts.map +1 -0
  49. package/dist/utils/test.js +5 -0
  50. package/dist/utils/test.js.map +1 -0
  51. package/package.json +1 -1
  52. package/src/bootstrap/app.ts +2 -19
  53. package/src/card_gen/generate_cards.ts +2 -4
  54. package/src/constants/default_generation_variables.ts +624 -0
  55. package/src/helper/schema_helper/build_card_schema.ts +1 -1
  56. package/src/helper/schema_helper/build_concept_facts_schema.ts +4 -18
  57. package/src/helper/schema_helper/build_summary_schema.ts +6 -17
  58. package/src/index.ts +12 -10
  59. package/src/services/get_prompts.ts +22 -74
  60. package/src/typology_gen/generate_concept_facts.ts +8 -11
  61. package/src/typology_gen/generate_typology.ts +2 -4
  62. package/src/typology_gen/summarize.ts +7 -10
@@ -31,7 +31,7 @@ export const buildCardSchema = async (
31
31
 
32
32
  // Deep clone to avoid mutating the original
33
33
  const populatedSchema = JSON.parse(
34
- JSON.stringify(cardTypeSchemas[firstCardType])
34
+ JSON.stringify(cardTypeSchemas[firstCardType].schema)
35
35
  );
36
36
 
37
37
  // Populate concepts enum
@@ -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,15 +1,18 @@
1
- import express from "express";
2
- import { OnlyEverGenerator } from "./bootstrap/app";
3
- import { ObjectId } from "mongodb";
4
- // import { database, setUp } from "./helper/mongo_helper";
1
+ // import express from "express";
2
+ // import { OnlyEverGenerator } from "./bootstrap/app";
3
+ // import { ObjectId } from "mongodb";
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
- export { OnlyEverGenerator };
8
+ // export { OnlyEverGenerator };
7
9
 
8
10
  // const app = express();
9
11
 
10
12
  // app.get("/generate", async (req, res) => {
11
13
  // const source = new ObjectId("692837542bd1597ff832d383");
12
- // setUp();
14
+ // // setUp();
15
+ // const database = await setUpMongoClient();
13
16
  // const openAiKey = process.env.OPEN_AI_KEY;
14
17
  // const document = await database
15
18
  // .collection("_source")
@@ -45,14 +48,13 @@ export { OnlyEverGenerator };
45
48
  // type: document.type,
46
49
  // },
47
50
  // };
51
+ // const generationVariablesSchema: GenerationVariablesSchema =
52
+ // defaultGenerationVariables;
48
53
  // const generator = new OnlyEverGenerator(
49
54
  // openAiKey ?? "",
50
55
  // "gpt-4o-mini",
51
56
  // generationContent,
52
- // promptIdForClassify ?? "",
53
- // promptIdForConceptFacts ?? "",
54
- // promptIdForCardGeneration ?? "",
55
- // promptIdForSummarize ?? "",
57
+ // generationVariablesSchema,
56
58
  // false,
57
59
  // 1
58
60
  // );
@@ -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
@@ -7,6 +7,7 @@ import {
7
7
  restoreQuotesInString,
8
8
  } from "../utils/sanitize_strings";
9
9
  import { GenerationVariablesSchema } from "../types/generation_variables_schema";
10
+ import { promptIds } from "../services/get_prompts";
10
11
 
11
12
  export class GenerateConceptFacts {
12
13
  public openAiService: OpenAiService;
@@ -21,7 +22,6 @@ export class GenerateConceptFacts {
21
22
  content: any[];
22
23
  };
23
24
  public type: string = "";
24
- public promptIdForConceptFacts: string;
25
25
  constructor(
26
26
  openAiService: OpenAiService,
27
27
  sourceId: string,
@@ -32,14 +32,12 @@ export class GenerateConceptFacts {
32
32
  content: any[];
33
33
  },
34
34
  type: string,
35
- promptIdForConceptFacts: string,
36
35
  generationCurriculum: boolean,
37
36
  generationVariablesSchema: GenerationVariablesSchema
38
37
  ) {
39
38
  this.openAiService = openAiService;
40
39
  this.openAIHelper = new OpenAIHelper(this.openAiService.api_key);
41
40
  this.content = content;
42
- this.promptIdForConceptFacts = promptIdForConceptFacts;
43
41
  this.type = type;
44
42
  this.sourceId = sourceId;
45
43
  this.generationCurriculum = generationCurriculum;
@@ -52,17 +50,16 @@ export class GenerateConceptFacts {
52
50
  this.type === "text"
53
51
  ? this.content.h1_headings || [""]
54
52
  : this.content.timecodes || [""];
55
- const schema =
56
- this.generationVariablesSchema.output_schema.concepts_facts;
57
- // const schema = await buildConceptFactSchema(
58
- // headings.length > 0 ? headings : [""],
59
- // "concept_fact_gen_schema",
60
- // true
61
- // );
53
+ // const schema =
54
+ // this.generationVariablesSchema.output_schema.concepts_facts;
55
+ const schema = await buildConceptFactSchema(
56
+ headings.length > 0 ? headings : [""],
57
+ this.generationVariablesSchema.output_schema.concepts_facts
58
+ );
62
59
  const openAiResponse: any =
63
60
  await this.openAIHelper.openAI.responses.create({
64
61
  prompt: {
65
- id: this.promptIdForConceptFacts,
62
+ id: promptIds.conceptFacts,
66
63
  // version: "200",
67
64
  variables: {
68
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
  },
@@ -4,6 +4,7 @@ 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
6
  import { GenerationVariablesSchema } from "../types/generation_variables_schema";
7
+ import { promptIds } from "../services/get_prompts";
7
8
 
8
9
  export class GenerateSummaryCards {
9
10
  public openAiService: OpenAiService;
@@ -18,7 +19,6 @@ export class GenerateSummaryCards {
18
19
  content: any[];
19
20
  };
20
21
  public type: string = "";
21
- public promptIdForSummaryCards: string;
22
22
  constructor(
23
23
  openAiService: OpenAiService,
24
24
  sourceId: string,
@@ -29,14 +29,12 @@ export class GenerateSummaryCards {
29
29
  content: any[];
30
30
  },
31
31
  type: string,
32
- promptIdForSummaryCards: string,
33
32
  generationCurriculum: boolean,
34
33
  generationVariablesSchema: GenerationVariablesSchema
35
34
  ) {
36
35
  this.openAiService = openAiService;
37
36
  this.openAIHelper = new OpenAIHelper(this.openAiService.api_key);
38
37
  this.content = content;
39
- this.promptIdForSummaryCards = promptIdForSummaryCards;
40
38
  this.type = type;
41
39
  this.sourceId = sourceId;
42
40
  this.generationCurriculum = generationCurriculum;
@@ -49,16 +47,15 @@ export class GenerateSummaryCards {
49
47
  this.type === "text"
50
48
  ? this.content.h1_headings || [""]
51
49
  : this.content.timecodes || [""];
52
- // const schema = await buildSummarySchema(
53
- // headings.length > 0 ? headings : [""],
54
- // "summary_cards",
55
- // true
56
- // );
57
- const schema = this.generationVariablesSchema.output_schema.summary;
50
+ const schema = await buildSummarySchema(
51
+ headings.length > 0 ? headings : [""],
52
+ this.generationVariablesSchema.output_schema.summary
53
+ );
54
+ // const schema = this.generationVariablesSchema.output_schema.summary;
58
55
  const openAiResponse: any =
59
56
  await this.openAIHelper.openAI.responses.create({
60
57
  prompt: {
61
- id: this.promptIdForSummaryCards,
58
+ id: promptIds.summarize,
62
59
  variables: {
63
60
  heading_type: this.type == "video" ? "timecode" : "h1 heading",
64
61
  },