only_ever_generator 8.4.6 → 8.4.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/bootstrap/app.d.ts +6 -3
  2. package/dist/bootstrap/app.d.ts.map +1 -1
  3. package/dist/bootstrap/app.js +11 -17
  4. package/dist/bootstrap/app.js.map +1 -1
  5. package/dist/card_gen/generate_cards.d.ts +2 -3
  6. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  7. package/dist/card_gen/generate_cards.js +22 -15
  8. package/dist/card_gen/generate_cards.js.map +1 -1
  9. package/dist/constants/prompt_data.d.ts +4 -4
  10. package/dist/constants/prompt_data.js +302 -302
  11. package/dist/constants/prompts/card_gen_prompt.js +160 -160
  12. package/dist/constants/prompts/typology_prompt.js +131 -131
  13. package/dist/constants/source_data.d.ts +171 -171
  14. package/dist/constants/source_data.js +973 -973
  15. package/dist/embedding_generation/local_consolidation.js +104 -104
  16. package/dist/helper/build_concept_facts_schema.d.ts +42 -42
  17. package/dist/helper/build_concept_facts_schema.js +44 -44
  18. package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
  19. package/dist/helper/schema_helper/build_card_schema.d.ts +1 -9
  20. package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
  21. package/dist/helper/schema_helper/build_card_schema.js +47 -50
  22. package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
  23. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +1 -1
  24. package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
  25. package/dist/helper/schema_helper/build_concept_facts_schema.js +20 -5
  26. package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
  27. package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
  28. package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
  29. package/dist/helper/schema_helper/build_summary_schema.js +18 -7
  30. package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
  31. package/dist/index.d.ts.map +1 -1
  32. package/dist/index.js +5 -5
  33. package/dist/index.js.map +1 -1
  34. package/dist/parse/response_format_card.d.ts +176 -176
  35. package/dist/parse/response_format_card.js +371 -371
  36. package/dist/parse/response_format_typology.d.ts +1 -1
  37. package/dist/parse/response_format_typology.js +46 -46
  38. package/dist/services/get_prompts.d.ts +8 -7
  39. package/dist/services/get_prompts.d.ts.map +1 -1
  40. package/dist/services/get_prompts.js +69 -21
  41. package/dist/services/get_prompts.js.map +1 -1
  42. package/dist/typology_gen/generate_concept_facts.d.ts +2 -3
  43. package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
  44. package/dist/typology_gen/generate_concept_facts.js +25 -15
  45. package/dist/typology_gen/generate_concept_facts.js.map +1 -1
  46. package/dist/typology_gen/generate_typology.d.ts +2 -1
  47. package/dist/typology_gen/generate_typology.d.ts.map +1 -1
  48. package/dist/typology_gen/generate_typology.js +24 -13
  49. package/dist/typology_gen/generate_typology.js.map +1 -1
  50. package/dist/typology_gen/summarize.d.ts +2 -3
  51. package/dist/typology_gen/summarize.d.ts.map +1 -1
  52. package/dist/typology_gen/summarize.js +24 -13
  53. package/dist/typology_gen/summarize.js.map +1 -1
  54. package/package.json +39 -38
  55. package/src/bootstrap/app.ts +418 -416
  56. package/src/card_gen/generate_cards.ts +347 -345
  57. package/src/config.ts +11 -11
  58. package/src/constants/api_constants.ts +7 -7
  59. package/src/constants/prompts/card_gen_prompt.ts +164 -164
  60. package/src/constants/prompts/typology_prompt.ts +139 -139
  61. package/src/embedding_generation/consolidation/global_consolidation.ts +96 -96
  62. package/src/embedding_generation/consolidation/local_consolidation.ts +141 -141
  63. package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -98
  64. package/src/embedding_generation/generate_embeddings.ts +42 -42
  65. package/src/embedding_generation/parse_embedding_response.ts +31 -31
  66. package/src/enums/card_type_enum.ts +6 -6
  67. package/src/gap_fill/calculate_gap_fill.ts +50 -50
  68. package/src/helper/get_id_from_title.ts +33 -33
  69. package/src/helper/mongo_helper.ts +29 -29
  70. package/src/helper/openai_helper.ts +20 -20
  71. package/src/helper/qdrant_db_methods.ts +77 -77
  72. package/src/helper/schema_helper/build_card_schema.ts +74 -98
  73. package/src/helper/schema_helper/build_classify_summarize_schema.ts +43 -43
  74. package/src/helper/schema_helper/build_concept_facts_schema.ts +45 -31
  75. package/src/helper/schema_helper/build_summary_schema.ts +43 -32
  76. package/src/index.ts +71 -73
  77. package/src/logger.ts +65 -65
  78. package/src/parse/parse_card/parse_cloze_card.ts +146 -146
  79. package/src/parse/parse_card/parse_flash_cards.ts +42 -42
  80. package/src/parse/parse_card/parse_match_card.ts +104 -104
  81. package/src/parse/parse_card/parse_mcq_card.ts +114 -114
  82. package/src/parse/parse_card_response.ts +197 -197
  83. package/src/parse/parse_source_content.ts +212 -212
  84. package/src/services/get_prompts.ts +164 -112
  85. package/src/services/open_ai_service.ts +89 -89
  86. package/src/services/qdrant_service.ts +10 -10
  87. package/src/types/base_param_type.ts +13 -13
  88. package/src/types/mongo_concept_fact_type.ts +12 -12
  89. package/src/types/parsed_card_type.ts +39 -39
  90. package/src/types/raw_card_response_types/generated_card_response_type.ts +59 -59
  91. package/src/types/source_taxonomy_type.ts +24 -24
  92. package/src/typology-parsed-response.ts +1932 -1932
  93. package/src/typology_gen/generate_concept_facts.ts +180 -169
  94. package/src/typology_gen/generate_typology.ts +203 -189
  95. package/src/typology_gen/summarize.ts +176 -164
  96. package/src/utils/distributed_quote_restoration.ts +80 -80
  97. package/src/utils/generate_args.ts +29 -29
  98. package/src/utils/parse_openai_response.ts +19 -19
  99. package/src/utils/sanitize_strings.ts +65 -65
  100. package/tsconfig.json +16 -16
  101. package/dist/constants/default_generation_variables.d.ts +0 -3
  102. package/dist/constants/default_generation_variables.d.ts.map +0 -1
  103. package/dist/constants/default_generation_variables.js +0 -580
  104. package/dist/constants/default_generation_variables.js.map +0 -1
  105. package/dist/services/prompts_test.d.ts +0 -10
  106. package/dist/services/prompts_test.d.ts.map +0 -1
  107. package/dist/services/prompts_test.js +0 -227
  108. package/dist/services/prompts_test.js.map +0 -1
  109. package/dist/types/generation_variables_schema.d.ts +0 -14
  110. package/dist/types/generation_variables_schema.d.ts.map +0 -1
  111. package/dist/types/generation_variables_schema.js +0 -3
  112. package/dist/types/generation_variables_schema.js.map +0 -1
  113. package/dist/utils/test.d.ts +0 -2
  114. package/dist/utils/test.d.ts.map +0 -1
  115. package/dist/utils/test.js +0 -5
  116. package/dist/utils/test.js.map +0 -1
  117. package/src/constants/default_generation_variables.ts +0 -624
  118. package/src/types/generation_variables_schema.ts +0 -16
@@ -1,43 +1,43 @@
1
- import { setUpMongoClient, ObjectId } from "../mongo_helper";
2
- import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
3
-
4
- // Function to populate enums in a parsed schema
5
- export const buildClassifySummarizeSchema = async (headings: string[]) => {
6
- const database = await setUpMongoClient();
7
- const objectId = new ObjectId("6895ab99aa1cad73b0018060");
8
- const schemaObj = await database.collection("_prompts").findOne({
9
- _id: objectId,
10
- });
11
- if (!schemaObj) {
12
- throw new Error("Schema not found");
13
- }
14
- const schema = schemaObj.schema;
15
- if (!schema) {
16
- throw new Error("Schema not found");
17
- }
18
- // Deep clone to avoid mutating the original
19
- const populatedSchema = JSON.parse(schema);
20
-
21
- // Sanitize headings to remove quotes for OpenAI structured outputs
22
- const sanitizedStrings = sanitizeStringsForSchema(headings);
23
-
24
- // Type-safe enum population for reference field in summary_cards
25
- if (
26
- populatedSchema.schema?.properties?.summary_cards?.items?.properties
27
- ?.reference?.enum
28
- ) {
29
- populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
30
- sanitizedStrings;
31
- }
32
-
33
- return populatedSchema;
34
- };
35
-
36
- // export const buildClassifySummarizeSchema = (headings: string[]) => {
37
- // const schema = JSON.parse(JSON.stringify(baseClassifySummarizeSchema));
38
- // // Populate the enum after schema creation
39
- // (schema.schema.properties.summary_cards.items.properties.reference
40
- // .enum as string[]) = headings;
41
-
42
- // return schema;
43
- // };
1
+ import { setUpMongoClient, ObjectId } from "../mongo_helper";
2
+ import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
3
+
4
+ // Function to populate enums in a parsed schema
5
+ export const buildClassifySummarizeSchema = async (headings: string[]) => {
6
+ const database = await setUpMongoClient();
7
+ const objectId = new ObjectId("6895ab99aa1cad73b0018060");
8
+ const schemaObj = await database.collection("_prompts").findOne({
9
+ _id: objectId,
10
+ });
11
+ if (!schemaObj) {
12
+ throw new Error("Schema not found");
13
+ }
14
+ const schema = schemaObj.schema;
15
+ if (!schema) {
16
+ throw new Error("Schema not found");
17
+ }
18
+ // Deep clone to avoid mutating the original
19
+ const populatedSchema = JSON.parse(schema);
20
+
21
+ // Sanitize headings to remove quotes for OpenAI structured outputs
22
+ const sanitizedStrings = sanitizeStringsForSchema(headings);
23
+
24
+ // Type-safe enum population for reference field in summary_cards
25
+ if (
26
+ populatedSchema.schema?.properties?.summary_cards?.items?.properties
27
+ ?.reference?.enum
28
+ ) {
29
+ populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
30
+ sanitizedStrings;
31
+ }
32
+
33
+ return populatedSchema;
34
+ };
35
+
36
+ // export const buildClassifySummarizeSchema = (headings: string[]) => {
37
+ // const schema = JSON.parse(JSON.stringify(baseClassifySummarizeSchema));
38
+ // // Populate the enum after schema creation
39
+ // (schema.schema.properties.summary_cards.items.properties.reference
40
+ // .enum as string[]) = headings;
41
+
42
+ // return schema;
43
+ // };
@@ -1,31 +1,45 @@
1
- import { ObjectId } from "mongodb";
2
- import { setUpMongoClient } from "../mongo_helper";
3
- import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
4
-
5
- // Function to populate enums in a parsed schema
6
- export async function buildConceptFactSchema(
7
- headings: string[],
8
- conceptFactSchema: any
9
- ) {
10
- const populatedSchema = conceptFactSchema;
11
-
12
- // Update name and strict mode
13
- populatedSchema.name = conceptFactSchema.name;
14
- populatedSchema.strict = conceptFactSchema.strict;
15
-
16
- const allowedRefs = [...headings, ""];
17
-
18
- // Sanitize headings to remove quotes for OpenAI structured outputs
19
- const sanitizedStrings = sanitizeStringsForSchema(allowedRefs);
20
-
21
- // Type-safe enum population for reference field
22
- if (
23
- populatedSchema.schema?.properties?.concepts_facts?.items?.properties
24
- ?.reference?.enum
25
- ) {
26
- populatedSchema.schema.properties.concepts_facts.items.properties.reference.enum =
27
- sanitizedStrings;
28
- }
29
-
30
- return populatedSchema;
31
- }
1
+ import { ObjectId } from "mongodb";
2
+ import { setUpMongoClient } from "../mongo_helper";
3
+ import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
4
+
5
+ // Function to populate enums in a parsed schema
6
+ export async function buildConceptFactSchema(
7
+ headings: string[],
8
+ name: string = "concept_fact_gen_schema",
9
+ strict: boolean = true
10
+ ) {
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);
25
+
26
+ // Update name and strict mode
27
+ populatedSchema.name = name;
28
+ populatedSchema.strict = strict;
29
+
30
+ const allowedRefs = [...headings, ""];
31
+
32
+ // Sanitize headings to remove quotes for OpenAI structured outputs
33
+ const sanitizedStrings = sanitizeStringsForSchema(allowedRefs);
34
+
35
+ // Type-safe enum population for reference field
36
+ if (
37
+ populatedSchema.schema?.properties?.concepts_facts?.items?.properties
38
+ ?.reference?.enum
39
+ ) {
40
+ populatedSchema.schema.properties.concepts_facts.items.properties.reference.enum =
41
+ sanitizedStrings;
42
+ }
43
+
44
+ return populatedSchema;
45
+ }
@@ -1,32 +1,43 @@
1
- import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
2
- import { setUpMongoClient, ObjectId } from "../mongo_helper";
3
-
4
- // Function to populate enums in a parsed schema
5
- export async function buildSummarySchema(
6
- headings: string[],
7
- summarySchema: any
8
- ) {
9
- if (!summarySchema) {
10
- return {};
11
- }
12
- const populatedSchema = summarySchema;
13
-
14
- // Update name and strict mode
15
- populatedSchema.name = summarySchema.name;
16
- populatedSchema.strict = summarySchema.strict;
17
-
18
- // Sanitize headings to remove quotes for OpenAI structured outputs
19
- const sanitizedStrings = sanitizeStringsForSchema(headings);
20
-
21
- // Type-safe enum population for reference field in summary_cards items
22
- // This populates the enum for cards 2-N (takeaway cards)
23
- if (
24
- populatedSchema.schema?.properties?.summary_cards?.items?.properties
25
- ?.reference?.enum
26
- ) {
27
- populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
28
- sanitizedStrings;
29
- }
30
-
31
- return populatedSchema;
32
- }
1
+ import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
2
+ import { setUpMongoClient, ObjectId } from "../mongo_helper";
3
+
4
+ // Function to populate enums in a parsed schema
5
+ export async function buildSummarySchema(
6
+ headings: string[],
7
+ name: string = "summary_cards",
8
+ strict: boolean = true
9
+ ) {
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");
17
+ }
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);
24
+
25
+ // Update name and strict mode
26
+ populatedSchema.name = name;
27
+ populatedSchema.strict = strict;
28
+
29
+ // Sanitize headings to remove quotes for OpenAI structured outputs
30
+ const sanitizedStrings = sanitizeStringsForSchema(headings);
31
+
32
+ // Type-safe enum population for reference field in summary_cards items
33
+ // This populates the enum for cards 2-N (takeaway cards)
34
+ if (
35
+ populatedSchema.schema?.properties?.summary_cards?.items?.properties
36
+ ?.reference?.enum
37
+ ) {
38
+ populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
39
+ sanitizedStrings;
40
+ }
41
+
42
+ return populatedSchema;
43
+ }
package/src/index.ts CHANGED
@@ -1,73 +1,71 @@
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";
7
-
8
- export { OnlyEverGenerator };
9
-
10
- // const app = express();
11
-
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
- // });
70
-
71
- // app.listen(3000, () => {
72
- // console.log("Server is running on port 3000");
73
- // });
1
+ import express from "express";
2
+ import { OnlyEverGenerator } from "./bootstrap/app";
3
+ import { ObjectId } from "mongodb";
4
+ // import { database, setUp } from "./helper/mongo_helper";
5
+
6
+ export { OnlyEverGenerator };
7
+
8
+ // const app = express();
9
+
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
+ // });
68
+
69
+ // app.listen(3000, () => {
70
+ // console.log("Server is running on port 3000");
71
+ // });
package/src/logger.ts CHANGED
@@ -1,65 +1,65 @@
1
- /// this method will call out atlas function and will write to a doc, incase of any errors:
2
- /// this is only for developmemt use
3
-
4
- import axios from "axios";
5
- import { setUpMongoClient } from "./helper/mongo_helper";
6
-
7
- type log_type = {
8
- flow: string;
9
- data: any;
10
- error: string;
11
- timestamp: Date;
12
- source_id: string;
13
- type: {
14
- request_type: string;
15
- n: number;
16
- card_types?: string;
17
- bloom_level?: number;
18
- };
19
- };
20
-
21
- export class ParsingError extends Error {
22
- public response: any;
23
- constructor(message: string, response: any) {
24
- super(message); // Pass message to the Error constructor
25
- this.name = "ParsingError"; // Set a custom name
26
- this.response = response; // Set the response
27
- Object.setPrototypeOf(this, new.target.prototype); // Fix prototype chain
28
- }
29
- }
30
-
31
- export class ErrorLogger {
32
- data: any;
33
- constructor(data: any) {
34
- this.data = data;
35
- }
36
-
37
- async log() {
38
- try {
39
- let response = await axios.post(
40
- "https://us-east-1.aws.data.mongodb-api.com/app/oe-phase1-tkmsy/endpoint/oe_gen_logger",
41
- {
42
- data: this.data,
43
- },
44
- {
45
- headers: {
46
- "Content-Type": ["application/json"],
47
- },
48
- }
49
- );
50
- return response;
51
- } catch (e) {
52
- console.log(e);
53
- }
54
- }
55
- }
56
- export async function log_error(error: log_type) {
57
- try {
58
- const database = await setUpMongoClient();
59
- const db = database.collection("_generation_log");
60
- const result = await db.insertOne(error);
61
- return result;
62
- } catch (e) {
63
- console.log(e);
64
- }
65
- }
1
+ /// this method will call out atlas function and will write to a doc, incase of any errors:
2
+ /// this is only for developmemt use
3
+
4
+ import axios from "axios";
5
+ import { setUpMongoClient } from "./helper/mongo_helper";
6
+
7
+ type log_type = {
8
+ flow: string;
9
+ data: any;
10
+ error: string;
11
+ timestamp: Date;
12
+ source_id: string;
13
+ type: {
14
+ request_type: string;
15
+ n: number;
16
+ card_types?: string;
17
+ bloom_level?: number;
18
+ };
19
+ };
20
+
21
+ export class ParsingError extends Error {
22
+ public response: any;
23
+ constructor(message: string, response: any) {
24
+ super(message); // Pass message to the Error constructor
25
+ this.name = "ParsingError"; // Set a custom name
26
+ this.response = response; // Set the response
27
+ Object.setPrototypeOf(this, new.target.prototype); // Fix prototype chain
28
+ }
29
+ }
30
+
31
+ export class ErrorLogger {
32
+ data: any;
33
+ constructor(data: any) {
34
+ this.data = data;
35
+ }
36
+
37
+ async log() {
38
+ try {
39
+ let response = await axios.post(
40
+ "https://us-east-1.aws.data.mongodb-api.com/app/oe-phase1-tkmsy/endpoint/oe_gen_logger",
41
+ {
42
+ data: this.data,
43
+ },
44
+ {
45
+ headers: {
46
+ "Content-Type": ["application/json"],
47
+ },
48
+ }
49
+ );
50
+ return response;
51
+ } catch (e) {
52
+ console.log(e);
53
+ }
54
+ }
55
+ }
56
+ export async function log_error(error: log_type) {
57
+ try {
58
+ const database = await setUpMongoClient();
59
+ const db = database.collection("_generation_log");
60
+ const result = await db.insertOne(error);
61
+ return result;
62
+ } catch (e) {
63
+ console.log(e);
64
+ }
65
+ }