only_ever_generator 0.9.5 → 0.9.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/dist/bootstrap/app.js +120 -0
  2. package/dist/card_gen/generate_cards.js +59 -0
  3. package/dist/config.js +9 -0
  4. package/dist/constants/api_constants.js +10 -0
  5. package/dist/constants/prompt_data.js +302 -0
  6. package/dist/constants/prompts/card_gen_prompt.js +167 -0
  7. package/dist/constants/prompts/typology_prompt.js +138 -0
  8. package/dist/constants/source_data.js +973 -0
  9. package/dist/embedding_generation/consolidation/global_consolidation.js +75 -0
  10. package/dist/embedding_generation/consolidation/local_consolidation.js +104 -0
  11. package/dist/embedding_generation/consolidation/write_consolidated_data.js +68 -0
  12. package/dist/embedding_generation/generate_embeddings.js +53 -0
  13. package/dist/embedding_generation/parse_embedding_response.js +28 -0
  14. package/dist/gap_fill/calculate_gap_fill.js +42 -0
  15. package/dist/helper/qdrant_db_methods.js +62 -0
  16. package/dist/index.js +96 -0
  17. package/dist/logger.js +41 -0
  18. package/dist/parse/parse_card/parse_cloze_card.js +125 -0
  19. package/dist/parse/parse_card/parse_flash_cards.js +33 -0
  20. package/dist/parse/parse_card/parse_match_card.js +81 -0
  21. package/dist/parse/parse_card/parse_mcq_card.js +103 -0
  22. package/dist/parse/parse_card_response.js +99 -0
  23. package/dist/parse/parse_source_content.js +185 -0
  24. package/dist/parse/response_format_card.js +371 -0
  25. package/dist/parse/response_format_typology.js +46 -0
  26. package/dist/services/open_ai_service.js +91 -0
  27. package/dist/services/qdrant_service.js +13 -0
  28. package/dist/typology-parsed-response.js +1935 -0
  29. package/dist/typology_gen/generate_typology.js +103 -0
  30. package/dist/utils/generate_args.js +27 -0
  31. package/dist/utils/parse_openai_response.js +23 -0
  32. package/package.json +2 -2
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GlobalConsolidation = void 0;
13
+ const qdrant_db_methods_1 = require("../../helper/qdrant_db_methods");
14
+ class GlobalConsolidation {
15
+ consolidate(locally_consolidated_concepts_facts, sourceId, threshold) {
16
+ return __awaiter(this, void 0, void 0, function* () {
17
+ var _a, _b;
18
+ // / for all concepts_facts, find the ,most similar concepts_facts in qdrant, threshold of 0.8
19
+ const similarConcepts = yield (0, qdrant_db_methods_1.getSimilarConcepts)("concepts-vectors", locally_consolidated_concepts_facts, threshold !== null && threshold !== void 0 ? threshold : 0.8);
20
+ const taxonomyConcepts = [];
21
+ const globalUpdatesOps = [];
22
+ const globalInsertsOps = [];
23
+ for (const index in similarConcepts) {
24
+ const points = similarConcepts[index].points;
25
+ const originalConcept = locally_consolidated_concepts_facts[index];
26
+ if (points.length == 0) {
27
+ taxonomyConcepts.push({
28
+ id: originalConcept.id,
29
+ text: originalConcept.text,
30
+ type: originalConcept.type,
31
+ reference: originalConcept.reference,
32
+ });
33
+ globalInsertsOps.push({
34
+ id: originalConcept.id,
35
+ vector: originalConcept.embedding,
36
+ payload: {
37
+ _sources: [sourceId],
38
+ text: originalConcept.text,
39
+ },
40
+ });
41
+ }
42
+ else {
43
+ const consolidatedId = points[0].id;
44
+ const currentPayload = points[0].payload;
45
+ // const currentSources = currentPayload?['_sources'] ?? [];
46
+ taxonomyConcepts.push({
47
+ id: consolidatedId.toString(),
48
+ text: originalConcept.text,
49
+ type: originalConcept.type,
50
+ reference: originalConcept.reference,
51
+ });
52
+ globalUpdatesOps.push({
53
+ id: consolidatedId.toString(),
54
+ sourceIdToAdd: sourceId,
55
+ currentPayload: {
56
+ // _sources: currentPayload['_sources'] ?? [],
57
+ _sources: ((_a = currentPayload === null || currentPayload === void 0 ? void 0 : currentPayload._sources) !== null && _a !== void 0 ? _a : []),
58
+ text: ((_b = currentPayload === null || currentPayload === void 0 ? void 0 : currentPayload.text) !== null && _b !== void 0 ? _b : "").toString(),
59
+ },
60
+ });
61
+ }
62
+ }
63
+ return {
64
+ source_taxonomy: taxonomyConcepts,
65
+ global_updates: globalUpdatesOps,
66
+ global_inserts: globalInsertsOps,
67
+ };
68
+ /// if threshold is below 0.8, then add the concept_fact to qdrant
69
+ /// if threshold is above 0.8, then replace the id of the local concept_fact with the id of the global concept_fact
70
+ /// add _source.id to qdrant
71
+ /// return the concepts_facts
72
+ });
73
+ }
74
+ }
75
+ exports.GlobalConsolidation = GlobalConsolidation;
@@ -0,0 +1,104 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LocalConsolidation = void 0;
4
+ const crypto_1 = require("crypto");
5
+ class LocalConsolidation {
6
+ constructor() {
7
+ this.cosineSimilarity = (a, b) => {
8
+ const dotProduct = a.reduce((acc, val, index) => acc + val * b[index], 0);
9
+ const magnitudeA = Math.sqrt(a.reduce((acc, val) => acc + val * val, 0));
10
+ const magnitudeB = Math.sqrt(b.reduce((acc, val) => acc + val * val, 0));
11
+ return dotProduct / (magnitudeA * magnitudeB);
12
+ };
13
+ }
14
+ consolidate(concepts_facts, sourceId) {
15
+ try {
16
+ const sourceIds = [];
17
+ const sourceTaxonomyOps = [];
18
+ const globalConceptOps = [];
19
+ const consolidatedConcepts = [];
20
+ const concepts = concepts_facts.map((e) => {
21
+ return {
22
+ id: (0, crypto_1.randomUUID)().toString(),
23
+ text: e.text,
24
+ reference: e.reference,
25
+ embedding: e.embedding,
26
+ type: e.type,
27
+ };
28
+ });
29
+ const afterConsolidation = this.consolidateSimilarEmbeddings(concepts);
30
+ sourceIds.push(JSON.stringify(sourceId));
31
+ console.log(afterConsolidation);
32
+ for (var concept of afterConsolidation.finalConsolidatedConcepts) {
33
+ sourceTaxonomyOps.push({
34
+ text: concept.text,
35
+ id: concept.id,
36
+ embedding: concept.embedding,
37
+ type: concept.type,
38
+ reference: concept.reference,
39
+ });
40
+ globalConceptOps.push({
41
+ id: concept.id.toString(),
42
+ vector: concept.embedding,
43
+ payload: {
44
+ _sources: [sourceId],
45
+ text: concept.text,
46
+ },
47
+ });
48
+ }
49
+ consolidatedConcepts.push(...afterConsolidation.consolidatedConcepts);
50
+ return {
51
+ globalConceptOps: globalConceptOps,
52
+ sourceIds: sourceIds,
53
+ consolidatedConcepts: consolidatedConcepts,
54
+ sourceTaxonomyOps: sourceTaxonomyOps,
55
+ };
56
+ }
57
+ catch (e) {
58
+ console.error("Error occurred while converting the parsed array to db operations:", e);
59
+ throw e;
60
+ }
61
+ // const concepts = concepts_facts.map((e) => {
62
+ // return {
63
+ // id: randomUUID().toString(),
64
+ // text: e.text,
65
+ // type: e.type,
66
+ // embedding: e.embedding,
67
+ // };
68
+ // });
69
+ // const consolidated = this._consolidateSimilarEmbeddings(concepts);
70
+ // return consolidated;
71
+ }
72
+ consolidateSimilarEmbeddings(data, threshold = 0.65) {
73
+ const finalConsolidatedConcepts = [];
74
+ const visited = new Array(data.length).fill(false);
75
+ const consolidatedConcepts = [];
76
+ for (let i = 0; i < data.length; i++) {
77
+ if (visited[i])
78
+ continue;
79
+ const group = [data[i]];
80
+ visited[i] = true;
81
+ for (let j = i + 1; j < data.length; j++) {
82
+ if (visited[j])
83
+ continue;
84
+ const sim = this.cosineSimilarity(data[i].embedding, data[j].embedding);
85
+ if (sim > threshold) {
86
+ group.push(data[j]);
87
+ visited[j] = true;
88
+ consolidatedConcepts.push({
89
+ concept1: data[i].text,
90
+ concept2: data[j].text,
91
+ similarity: sim,
92
+ });
93
+ }
94
+ }
95
+ // Consolidate the group (e.g., just take the first, or merge)
96
+ finalConsolidatedConcepts.push(group[0]); // Or you can customize how to merge
97
+ }
98
+ return {
99
+ finalConsolidatedConcepts: finalConsolidatedConcepts,
100
+ consolidatedConcepts: consolidatedConcepts,
101
+ };
102
+ }
103
+ }
104
+ exports.LocalConsolidation = LocalConsolidation;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.WriteConsolidatedData = void 0;
16
+ const qdrant_service_1 = __importDefault(require("../../services/qdrant_service"));
17
+ class WriteConsolidatedData {
18
+ writeConsolidatedData(data, generation_requests, source_id) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ if (data.global_updates.length > 0) {
21
+ yield this.writeGlobalUpdates(data.global_updates);
22
+ }
23
+ if (data.global_inserts.length > 0) {
24
+ yield this.writeGlobalInserts(data.global_inserts);
25
+ }
26
+ return {
27
+ status: "success",
28
+ };
29
+ });
30
+ }
31
+ writeGlobalUpdates(data) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const operations = data.map((e) => {
34
+ return {
35
+ set_payload: {
36
+ points: [e.id],
37
+ payload: {
38
+ text: e.currentPayload.text,
39
+ _sources: [e.sourceIdToAdd, ...e.currentPayload._sources],
40
+ },
41
+ },
42
+ };
43
+ });
44
+ yield qdrant_service_1.default.batchUpdate("concepts-vectors", {
45
+ wait: true,
46
+ operations: operations,
47
+ });
48
+ });
49
+ }
50
+ writeGlobalInserts(data) {
51
+ return __awaiter(this, void 0, void 0, function* () {
52
+ yield qdrant_service_1.default.upsert("concepts-vectors", {
53
+ wait: true,
54
+ points: data,
55
+ });
56
+ });
57
+ }
58
+ wiriteToMondo(source_taxonomy, generation_requests, source_id) {
59
+ return __awaiter(this, void 0, void 0, function* () {
60
+ const mondo_data = source_taxonomy.map((e) => {
61
+ return {
62
+ id: e.id,
63
+ };
64
+ });
65
+ });
66
+ }
67
+ }
68
+ exports.WriteConsolidatedData = WriteConsolidatedData;
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.GenerateEmbeddings = void 0;
13
+ class GenerateEmbeddings {
14
+ constructor(openAiService) {
15
+ this.openAiService = openAiService;
16
+ }
17
+ generateEmbeddings(concepts_facts) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const texts = concepts_facts.map((e) => e.text);
20
+ const response = yield this.openAiService.sendEmbeddingRequest(texts);
21
+ if (response.status_code !== 200) {
22
+ throw new Error(response.message);
23
+ }
24
+ const embeddings = response.data.data.sort((a) => a.index);
25
+ const model = response.data.model;
26
+ const usage = response.data.usage;
27
+ const embeddings_map = [];
28
+ for (let i = 0; i < concepts_facts.length; i++) {
29
+ embeddings_map.push({
30
+ text: concepts_facts[i].text,
31
+ type: concepts_facts[i].type,
32
+ embedding: embeddings[i].embedding,
33
+ reference: concepts_facts[i].reference,
34
+ });
35
+ }
36
+ // return embeddings_map;
37
+ return {
38
+ concepts_facts: embeddings_map,
39
+ metadata: {
40
+ req_time: new Date().toISOString(),
41
+ req_type: {
42
+ type: "embedding",
43
+ },
44
+ req_tokens: usage.prompt_tokens,
45
+ res_tokens: usage.completion_tokens,
46
+ model: model,
47
+ usage: usage,
48
+ },
49
+ };
50
+ });
51
+ }
52
+ }
53
+ exports.GenerateEmbeddings = GenerateEmbeddings;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ParseEmbeddingResponse = void 0;
4
+ const local_consolidation_1 = require("./consolidation/local_consolidation");
5
+ class ParseEmbeddingResponse {
6
+ parse(response, concepts_facts) {
7
+ const data = response.data;
8
+ const model = data.model;
9
+ const usage = data.usage;
10
+ const rawEmbeddings = data.data;
11
+ const sorted = rawEmbeddings.sort((e) => e.index);
12
+ const embeddings = sorted.map((e) => e.embedding);
13
+ const embeddings_map = new Map();
14
+ const embeddings_map_array = [];
15
+ for (let i = 0; i < concepts_facts.length; i++) {
16
+ embeddings_map_array.push({
17
+ text: concepts_facts[i].text,
18
+ type: concepts_facts[i].type,
19
+ embedding: embeddings[i],
20
+ reference: concepts_facts[i].reference,
21
+ });
22
+ }
23
+ const embeddingMap = embeddings_map;
24
+ const consolidated = new local_consolidation_1.LocalConsolidation().consolidate(embeddings_map_array, "sourceID");
25
+ return consolidated;
26
+ }
27
+ }
28
+ exports.ParseEmbeddingResponse = ParseEmbeddingResponse;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gapFilling = gapFilling;
4
+ function isEmpty(obj) {
5
+ return Object.keys(obj).length === 0;
6
+ }
7
+ function gapFilling(typologyResponse, cardgenResponse) {
8
+ var _a, _b, _c, _d, _e;
9
+ let allConcepts = [];
10
+ let allFacts = [];
11
+ let generatedConceptsList = [];
12
+ let generatedFactsList = [];
13
+ let remainingConcepts = [];
14
+ let remainingFacts = [];
15
+ if (!isEmpty(typologyResponse)) {
16
+ allConcepts.push(...((_a = typologyResponse.concepts) !== null && _a !== void 0 ? _a : []));
17
+ allFacts.push(...((_b = typologyResponse === null || typologyResponse === void 0 ? void 0 : typologyResponse.facts) !== null && _b !== void 0 ? _b : []));
18
+ }
19
+ if (!isEmpty(cardgenResponse)) {
20
+ allConcepts.push(...((_c = cardgenResponse.missing_concepts) !== null && _c !== void 0 ? _c : []));
21
+ allFacts.push(...((_d = cardgenResponse.missing_facts) !== null && _d !== void 0 ? _d : []));
22
+ }
23
+ if (cardgenResponse.cards_data !== undefined &&
24
+ ((_e = cardgenResponse.cards_data) === null || _e === void 0 ? void 0 : _e.length) != 0) {
25
+ for (let card of cardgenResponse.cards_data) {
26
+ if (card.concepts.length != 0) {
27
+ generatedConceptsList.push(...card.concepts);
28
+ }
29
+ if (card.facts.length != 0) {
30
+ generatedFactsList.push(...card.facts);
31
+ }
32
+ }
33
+ let generatedConceptsSet = Array.from(new Set(generatedConceptsList));
34
+ let generatedFactsSet = Array.from(new Set(generatedFactsList));
35
+ remainingConcepts = allConcepts.filter((item) => !generatedConceptsSet.includes(item));
36
+ remainingFacts = allFacts.filter((item) => !generatedFactsSet.includes(item));
37
+ }
38
+ return {
39
+ remainingConcepts: remainingConcepts,
40
+ remainingFacts: remainingFacts,
41
+ };
42
+ }
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.getSimilarConcepts = exports.addEmbeddingsToCollection = exports.getCollection = exports.createCollection = void 0;
16
+ const qdrant_service_1 = __importDefault(require("../services/qdrant_service"));
17
+ const createCollection = (collectionName) => __awaiter(void 0, void 0, void 0, function* () {
18
+ yield qdrant_service_1.default.createCollection(collectionName, {
19
+ vectors: {
20
+ size: 1536,
21
+ distance: "Cosine",
22
+ },
23
+ });
24
+ });
25
+ exports.createCollection = createCollection;
26
+ const getCollection = () => __awaiter(void 0, void 0, void 0, function* () {
27
+ const collection = yield qdrant_service_1.default.getCollections();
28
+ return collection;
29
+ });
30
+ exports.getCollection = getCollection;
31
+ const getCorrespondingConcepts = (collectionName, embeddings, threshold) => __awaiter(void 0, void 0, void 0, function* () {
32
+ try {
33
+ const searchQuery = embeddings.map((e) => {
34
+ return {
35
+ query: e.embedding,
36
+ limit: 1,
37
+ score_threshold: threshold,
38
+ with_payload: true,
39
+ };
40
+ });
41
+ const results = yield qdrant_service_1.default.queryBatch(collectionName, {
42
+ searches: searchQuery,
43
+ });
44
+ return results;
45
+ }
46
+ catch (error) {
47
+ console.log(error);
48
+ throw error;
49
+ }
50
+ });
51
+ exports.getSimilarConcepts = getCorrespondingConcepts;
52
+ const addEmbeddingsToCollection = (collectionName, embeddings) => __awaiter(void 0, void 0, void 0, function* () {
53
+ const CHUNK_SIZE = 1000;
54
+ for (let i = 0; i < embeddings.length; i += CHUNK_SIZE) {
55
+ const batch = embeddings.slice(i, i + CHUNK_SIZE);
56
+ yield qdrant_service_1.default.upsert(collectionName, {
57
+ wait: true,
58
+ points: batch,
59
+ });
60
+ }
61
+ });
62
+ exports.addEmbeddingsToCollection = addEmbeddingsToCollection;
package/dist/index.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ // import express from "express";
3
+ // import {
4
+ // returnCardResponse,
5
+ // returnHeadings,
6
+ // returnSourceData,
7
+ // } from "./constants/source_data";
8
+ // import config from "./config";
9
+ // const app = express();
10
+ // const port = 3000;
11
+ // import { returnPromptData } from "./constants/prompt_data";
12
+ // import { GenerateCards } from "./card_gen/generate_cards";
13
+ // import { OpenAiService } from "./services/open_ai_service";
14
+ // import { ParseCardResponse } from "./parse/parse_card_response";
15
+ // import { returnTypologyPrompt } from "./constants/prompts/typology_prompt";
16
+ // import { returnCardGenPrompt } from "./constants/prompts/card_gen_prompt";
17
+ // import { GenerateArgs } from "./utils/generate_args";
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.OnlyEverGenerator = void 0;
20
+ const app_1 = require("./bootstrap/app");
21
+ Object.defineProperty(exports, "OnlyEverGenerator", { enumerable: true, get: function () { return app_1.OnlyEverGenerator; } });
22
+ // . All the Codes Below uses express and are strictly for development purpose, while publishing the package, comment everything
23
+ // below this line
24
+ // let oeGen = new OnlyEverGenerator(config.openAIKey, "gpt-4o-mini", {
25
+ // prompt: returnPromptData(),
26
+ // content: returnSourceData(),
27
+ // });
28
+ // app.get("/", async (req, res) => {
29
+ // // let data = oeGen.returnParsedContent();
30
+ // // let parsedData = parseResponse()
31
+ // let cardPrompt = "";
32
+ // res.send(cardPrompt);
33
+ // });
34
+ // app.get("/openAI", async (req, res) => {
35
+ // // let prompt = returnPromt();
36
+ // // let prompt = returnCardGenPrompt();
37
+ // // let content = returnSourceData().toString()
38
+ // // let headings = returnHeadings();
39
+ // // // let aiRequest = await openAIRequest(prompt,content);
40
+ // let aiRequest = await oeGen.generate(true, true);
41
+ // res.send(aiRequest);
42
+ // });
43
+ // app.get("/parseCardData", async (req, res) => {
44
+ // let cardResp = returnCardResponse();
45
+ // let headings = returnHeadings();
46
+ // cardResp.metadata = {
47
+ // req_time: cardResp.generated_at ?? new Date(),
48
+ // req_type: "card",
49
+ // req_tokens: cardResp.usage_data?.prompt_tokens,
50
+ // res_tokens: cardResp.usage_data?.completion_tokens,
51
+ // model: "40-mini",
52
+ // };
53
+ // let parsedData = new ParseCardResponse().parse(cardResp, false, {});
54
+ // res.send(parsedData);
55
+ // });
56
+ // app.get("/generate-cards", async (req, res) => {
57
+ // let cardResp = embeddingsResp;
58
+ // oeGen.parsedContent.taxonomy = cardResp;
59
+ // let parsedData = await oeGen.generateCard(
60
+ // returnCardGenPrompt(),
61
+ // JSON.stringify(cardResp),
62
+ // false
63
+ // );
64
+ // res.send(parsedData);
65
+ // });
66
+ // app.get("/typology", async (req, res) => {
67
+ // {
68
+ // let typologyRequest = await oeGen.generate(true, false);
69
+ // res.send(typologyRequest);
70
+ // }
71
+ // });
72
+ // app.get("/local-consolidation", async (req, res) => {
73
+ // const concepts_facts = embeddingsResp.concepts_facts;
74
+ // let locallyConsolidated = new LocalConsolidation().consolidate(
75
+ // concepts_facts,
76
+ // "sourceID"
77
+ // );
78
+ // res.send(locallyConsolidated);
79
+ // });
80
+ // app.get("/global-consolidation", async (req, res) => {
81
+ // const concepts_facts = embeddingsResp.concepts_facts;
82
+ // // let globallyConsolidated = await new GlobalConsolidation().consolidate(
83
+ // // concepts_facts,
84
+ // // "sourceID",
85
+ // // 0.2
86
+ // // );
87
+ // // let globallyConsolidated = await oeGen.globalConsolidation(
88
+ // // concepts_facts,
89
+ // // "sourceID",
90
+ // // 0.2
91
+ // // );
92
+ // // res.send(globallyConsolidated);
93
+ // });
94
+ // app.listen(port, () => {
95
+ // console.log(`Example app listening at http://localhost:${port}`);
96
+ // });
package/dist/logger.js ADDED
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ /// this method will call out atlas function and will write to a doc, incase of any errors:
3
+ /// this is only for developmemt use
4
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
6
+ return new (P || (P = Promise))(function (resolve, reject) {
7
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
8
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
9
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
10
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
11
+ });
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.ErrorLogger = void 0;
18
+ const axios_1 = __importDefault(require("axios"));
19
+ class ErrorLogger {
20
+ constructor(data) {
21
+ this.data = data;
22
+ }
23
+ log() {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ try {
26
+ let response = yield axios_1.default.post("https://us-east-1.aws.data.mongodb-api.com/app/oe-phase1-tkmsy/endpoint/oe_gen_logger", {
27
+ data: this.data,
28
+ }, {
29
+ headers: {
30
+ "Content-Type": ["application/json"],
31
+ },
32
+ });
33
+ return response;
34
+ }
35
+ catch (e) {
36
+ console.log(e);
37
+ }
38
+ });
39
+ }
40
+ }
41
+ exports.ErrorLogger = ErrorLogger;