only_ever_generator 5.0.5 → 5.0.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.
- package/dist/card_gen/generate_cards.d.ts +1 -0
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +68 -25
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/index.js +60 -63
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +17 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js +25 -1
- package/dist/logger.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts +1 -0
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +33 -9
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +1 -0
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +31 -9
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/package.json +1 -1
- package/src/card_gen/generate_cards.ts +71 -26
- package/src/index.ts +61 -60
- package/src/logger.ts +33 -0
- package/src/typology_gen/generate_concept_facts.ts +37 -10
- package/src/typology_gen/generate_typology.ts +35 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_cards.d.ts","sourceRoot":"","sources":["../../src/card_gen/generate_cards.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAIvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAE5D,OAAO,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAE/D,qBAAa,aAAa;IACxB,aAAa,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,cAAc,CAAC;IACzB,mBAAmB,EAAE;QAC1B,kBAAkB,EAAE,MAAM,CAAC;QAC3B,iBAAiB,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|
|
@@ -11,6 +11,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
12
|
exports.GenerateCards = void 0;
|
|
13
13
|
const openai_helper_1 = require("../helper/openai_helper");
|
|
14
|
+
const build_card_schema_1 = require("../helper/schema_helper/build_card_schema");
|
|
14
15
|
const logger_1 = require("../logger");
|
|
15
16
|
const parse_card_response_1 = require("../parse/parse_card_response");
|
|
16
17
|
class GenerateCards {
|
|
@@ -48,33 +49,59 @@ class GenerateCards {
|
|
|
48
49
|
},
|
|
49
50
|
],
|
|
50
51
|
store: false,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
52
|
+
text: {
|
|
53
|
+
format: {
|
|
54
|
+
type: "json_schema",
|
|
55
|
+
name: "card_gen_schema",
|
|
56
|
+
strict: true,
|
|
57
|
+
schema: build_card_schema_1.cardSchema,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
59
60
|
});
|
|
60
61
|
if (!response) {
|
|
61
|
-
yield
|
|
62
|
-
|
|
63
|
-
data: response,
|
|
62
|
+
yield (0, logger_1.log_error)({
|
|
63
|
+
flow: "manual_generation",
|
|
64
|
+
data: JSON.stringify(response),
|
|
65
|
+
timestamp: new Date(),
|
|
66
|
+
error: "empty_openai_response",
|
|
64
67
|
title: this.content,
|
|
65
|
-
|
|
68
|
+
type: {
|
|
69
|
+
request_type: "depth",
|
|
70
|
+
n: 1,
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
return;
|
|
66
74
|
}
|
|
67
|
-
console.log("generation completed");
|
|
68
|
-
console.log(response);
|
|
69
75
|
return response;
|
|
70
76
|
}
|
|
71
77
|
catch (error) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
if (error instanceof logger_1.ParsingError) {
|
|
79
|
+
yield (0, logger_1.log_error)({
|
|
80
|
+
flow: "manual_generation",
|
|
81
|
+
data: JSON.stringify(error.response),
|
|
82
|
+
timestamp: new Date(),
|
|
83
|
+
error: "parsing_error",
|
|
84
|
+
title: this.content,
|
|
85
|
+
type: {
|
|
86
|
+
request_type: "depth",
|
|
87
|
+
n: 1,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
console.log(error);
|
|
93
|
+
yield (0, logger_1.log_error)({
|
|
94
|
+
flow: "manual_generation",
|
|
95
|
+
data: JSON.stringify(error),
|
|
96
|
+
timestamp: new Date(),
|
|
97
|
+
error: "error_in_card_generation",
|
|
98
|
+
title: this.content,
|
|
99
|
+
type: {
|
|
100
|
+
request_type: "depth",
|
|
101
|
+
n: 1,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
78
105
|
}
|
|
79
106
|
});
|
|
80
107
|
}
|
|
@@ -104,7 +131,7 @@ class GenerateCards {
|
|
|
104
131
|
if (response.status == "completed") {
|
|
105
132
|
response.metadata.status = "completed";
|
|
106
133
|
/// map response to generated_content
|
|
107
|
-
const testCardsArray =
|
|
134
|
+
const testCardsArray = this.parseJson(response);
|
|
108
135
|
const generated_data = {
|
|
109
136
|
metadata: response.metadata,
|
|
110
137
|
generated_content: {
|
|
@@ -134,13 +161,29 @@ class GenerateCards {
|
|
|
134
161
|
}
|
|
135
162
|
}
|
|
136
163
|
catch (e) {
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
data: e
|
|
140
|
-
|
|
164
|
+
yield (0, logger_1.log_error)({
|
|
165
|
+
flow: "manual_generation",
|
|
166
|
+
data: JSON.stringify(e),
|
|
167
|
+
timestamp: new Date(),
|
|
168
|
+
error: "error_in_card_generation",
|
|
169
|
+
title: this.content,
|
|
170
|
+
type: {
|
|
171
|
+
request_type: "depth",
|
|
172
|
+
n: 1,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
141
175
|
}
|
|
142
176
|
});
|
|
143
177
|
}
|
|
178
|
+
parseJson(response) {
|
|
179
|
+
try {
|
|
180
|
+
const testCardsArray = JSON.parse(response.output_text).test_cards;
|
|
181
|
+
return testCardsArray;
|
|
182
|
+
}
|
|
183
|
+
catch (e) {
|
|
184
|
+
throw new logger_1.ParsingError("Something went wrong in parsing the json", response);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
144
187
|
}
|
|
145
188
|
exports.GenerateCards = GenerateCards;
|
|
146
189
|
//# sourceMappingURL=generate_cards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_cards.js","sourceRoot":"","sources":["../../src/card_gen/generate_cards.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;
|
|
1
|
+
{"version":3,"file":"generate_cards.js","sourceRoot":"","sources":["../../src/card_gen/generate_cards.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;AACvD,iFAAuE;AACvE,sCAAiE;AACjE,sEAAiE;AAKjE,MAAa,aAAa;IAWxB,YACE,aAA4B,EAC5B,OAAe,EACf,QAAwB,EACxB,mBAIC,EACD,0BAAkC;QAElC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;QAC/C,IAAI,CAAC,0BAA0B,GAAG,0BAA0B,CAAC;IAC/D,CAAC;IAEK,cAAc;;YAClB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;YACtC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC;YACzD,OAAO,CAAC,GAA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C,MAAM,IAAI,WAAW,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG;qBACxD,CAAC;oBACF,IAAI,SAAS,GAAG,IAAI,uCAAiB,EAAE,CAAC,KAAK,CAC3C,cAAc,EACd,IAAI,CAAC,QAAQ,EACb,CAAC,CACF,CAAC;oBACF,OAAO,SAAS,CAAC;gBACnB,CAAC;qBAAM,CAAC;oBACN,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;oBACpC,QAAQ,CAAC,QAAQ,CAAC,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC;oBACjD,OAAO,QAAQ,CAAC;gBAClB,CAAC;YACH,CAAC;YAAC,OAAO,CAAM,EAAE,CAAC;gBAChB,MAAM,IAAA,kBAAS,EAAC;oBACd,IAAI,EAAE,mBAAmB;oBACzB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC;oBACvB,SAAS,EAAE,IAAI,IAAI,EAAE;oBACrB,KAAK,EAAE,0BAA0B;oBACjC,KAAK,EAAE,IAAI,CAAC,OAAO;oBACnB,IAAI,EAAE;wBACJ,YAAY,EAAE,OAAO;wBACrB,CAAC,EAAE,CAAC;qBACL;iBACF,CAAC,CAAC;YACL,CAAC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,QAAa;QACrB,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,UAAU,CAAC;YACnE,OAAO,cAAc,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,qBAAY,CACpB,0CAA0C,EAC1C,QAAQ,CACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAjMD,sCAiMC"}
|
package/dist/index.js
CHANGED
|
@@ -9,71 +9,68 @@
|
|
|
9
9
|
// import { OpenAiService } from "./services/open_ai_service";
|
|
10
10
|
// import { GenerateConceptFacts } from "./typology_gen/generate_concept_facts";
|
|
11
11
|
// import { BaseParamType } from "./types/base_param_type";
|
|
12
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
-
});
|
|
20
|
-
};
|
|
21
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
13
|
exports.OnlyEverGenerator = void 0;
|
|
23
14
|
const app_1 = require("./bootstrap/app");
|
|
24
15
|
Object.defineProperty(exports, "OnlyEverGenerator", { enumerable: true, get: function () { return app_1.OnlyEverGenerator; } });
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
16
|
+
// (async () => {
|
|
17
|
+
// const openAIKey =
|
|
18
|
+
// "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";
|
|
19
|
+
// const promptForSummary = {
|
|
20
|
+
// promptId: "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
21
|
+
// version: "13",
|
|
22
|
+
// };
|
|
23
|
+
// const promptForConceptFacts = {
|
|
24
|
+
// promptId: "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
25
|
+
// version: "6",
|
|
26
|
+
// };
|
|
27
|
+
// setUp();
|
|
28
|
+
// const source = await database.collection("_source").findOne({
|
|
29
|
+
// _id: new ObjectId("6753b1ec56e5e922b57ee2df"),
|
|
30
|
+
// });
|
|
31
|
+
// const contentForGen = {
|
|
32
|
+
// prompt: {
|
|
33
|
+
// typology: "",
|
|
34
|
+
// card_generation: "",
|
|
35
|
+
// },
|
|
36
|
+
// content: {
|
|
37
|
+
// source_id: source?._id?.toString() || "",
|
|
38
|
+
// title: source?.title || "",
|
|
39
|
+
// type: source?.source_type || "",
|
|
40
|
+
// headings: source?.headings || [],
|
|
41
|
+
// content: source?.content || [],
|
|
42
|
+
// fields: source?.fields || [],
|
|
43
|
+
// taxonomy: source?.generate_cards
|
|
44
|
+
// ? {
|
|
45
|
+
// generate_cards: source?.generate_cards || {
|
|
46
|
+
// state: false,
|
|
47
|
+
// reason: "",
|
|
48
|
+
// },
|
|
49
|
+
// concepts_facts: source?.concepts_facts || [],
|
|
50
|
+
// fields: source?.fields || [],
|
|
51
|
+
// }
|
|
52
|
+
// : undefined,
|
|
53
|
+
// },
|
|
54
|
+
// };
|
|
55
|
+
// const prompts = await getPrompts("text");
|
|
56
|
+
// const bloomInstructions = prompts.bloom_instructions;
|
|
57
|
+
// const cardInstructions = prompts.card_instructions;
|
|
58
|
+
// const cardExamples = prompts.card_examples;
|
|
59
|
+
// console.log("Initializing OnlyEverGenerator");
|
|
60
|
+
// const onlyEverGenerator = new OnlyEverGenerator(
|
|
61
|
+
// process.env.OPEN_AI_KEY as string,
|
|
62
|
+
// "o4-mini",
|
|
63
|
+
// contentForGen,
|
|
64
|
+
// "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
65
|
+
// "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
66
|
+
// "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6",
|
|
67
|
+
// {
|
|
68
|
+
// bloom_instructions: bloomInstructions,
|
|
69
|
+
// card_instructions: cardInstructions,
|
|
70
|
+
// card_examples: cardExamples,
|
|
71
|
+
// }
|
|
72
|
+
// );
|
|
73
|
+
// const response = await onlyEverGenerator.generate(true, true);
|
|
74
|
+
// console.log(response);
|
|
75
|
+
// })();
|
|
79
76
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,iGAAiG;AACjG,+DAA+D;AAC/D,mGAAmG;AACnG,4FAA4F;AAC5F,yDAAyD;AACzD,uEAAuE;AACvE,8DAA8D;AAC9D,gFAAgF;AAChF,2DAA2D
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,iGAAiG;AACjG,+DAA+D;AAC/D,mGAAmG;AACnG,4FAA4F;AAC5F,yDAAyD;AACzD,uEAAuE;AACvE,8DAA8D;AAC9D,gFAAgF;AAChF,2DAA2D;;;AAE3D,yCAAoD;AAK3C,kGALA,uBAAiB,OAKA;AAE1B,iBAAiB;AACjB,sBAAsB;AACtB,8KAA8K;AAC9K,+BAA+B;AAC/B,yEAAyE;AACzE,qBAAqB;AACrB,OAAO;AACP,oCAAoC;AACpC,yEAAyE;AACzE,oBAAoB;AACpB,OAAO;AAEP,aAAa;AAEb,kEAAkE;AAClE,qDAAqD;AACrD,QAAQ;AAER,4BAA4B;AAC5B,gBAAgB;AAChB,sBAAsB;AACtB,6BAA6B;AAC7B,SAAS;AACT,iBAAiB;AACjB,kDAAkD;AAClD,oCAAoC;AACpC,yCAAyC;AACzC,0CAA0C;AAC1C,wCAAwC;AACxC,sCAAsC;AACtC,yCAAyC;AACzC,cAAc;AACd,0DAA0D;AAC1D,8BAA8B;AAC9B,4BAA4B;AAC5B,iBAAiB;AACjB,4DAA4D;AAC5D,4CAA4C;AAC5C,cAAc;AACd,uBAAuB;AACvB,SAAS;AACT,OAAO;AACP,8CAA8C;AAC9C,0DAA0D;AAC1D,wDAAwD;AACxD,gDAAgD;AAEhD,mDAAmD;AACnD,qDAAqD;AACrD,yCAAyC;AACzC,iBAAiB;AACjB,qBAAqB;AAErB,+DAA+D;AAC/D,+DAA+D;AAC/D,+DAA+D;AAC/D,QAAQ;AACR,+CAA+C;AAC/C,6CAA6C;AAC7C,qCAAqC;AACrC,QAAQ;AACR,OAAO;AACP,mEAAmE;AACnE,2BAA2B;AAC3B,QAAQ"}
|
package/dist/logger.d.ts
CHANGED
|
@@ -1,6 +1,23 @@
|
|
|
1
|
+
type log_type = {
|
|
2
|
+
flow: string;
|
|
3
|
+
data: any;
|
|
4
|
+
error: string;
|
|
5
|
+
timestamp: Date;
|
|
6
|
+
title: string;
|
|
7
|
+
type: {
|
|
8
|
+
request_type: string;
|
|
9
|
+
n: number;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
export declare class ParsingError extends Error {
|
|
13
|
+
response: any;
|
|
14
|
+
constructor(message: string, response: any);
|
|
15
|
+
}
|
|
1
16
|
export declare class ErrorLogger {
|
|
2
17
|
data: any;
|
|
3
18
|
constructor(data: any);
|
|
4
19
|
log(): Promise<import("axios").AxiosResponse<any, any> | undefined>;
|
|
5
20
|
}
|
|
21
|
+
export declare function log_error(error: log_type): Promise<import("mongodb").InsertOneResult<import("bson").Document> | undefined>;
|
|
22
|
+
export {};
|
|
6
23
|
//# sourceMappingURL=logger.d.ts.map
|
package/dist/logger.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAMA,KAAK,QAAQ,GAAG;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,GAAG,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE;QACJ,YAAY,EAAE,MAAM,CAAC;QACrB,CAAC,EAAE,MAAM,CAAC;KACX,CAAC;CACH,CAAC;AAEF,qBAAa,YAAa,SAAQ,KAAK;IAC9B,QAAQ,EAAE,GAAG,CAAC;gBACT,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG;CAM3C;AAED,qBAAa,WAAW;IACtB,IAAI,EAAE,GAAG,CAAC;gBACE,IAAI,EAAE,GAAG;IAIf,GAAG;CAkBV;AACD,wBAAsB,SAAS,CAAC,KAAK,EAAE,QAAQ,mFAS9C"}
|
package/dist/logger.js
CHANGED
|
@@ -14,8 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
14
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.ErrorLogger = void 0;
|
|
17
|
+
exports.ErrorLogger = exports.ParsingError = void 0;
|
|
18
|
+
exports.log_error = log_error;
|
|
18
19
|
const axios_1 = __importDefault(require("axios"));
|
|
20
|
+
const mongo_helper_1 = require("./helper/mongo_helper");
|
|
21
|
+
class ParsingError extends Error {
|
|
22
|
+
constructor(message, response) {
|
|
23
|
+
super(message); // Pass message to the Error constructor
|
|
24
|
+
this.name = "ParsingError"; // Set a custom name
|
|
25
|
+
this.response = response; // Set the response
|
|
26
|
+
Object.setPrototypeOf(this, new.target.prototype); // Fix prototype chain
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.ParsingError = ParsingError;
|
|
19
30
|
class ErrorLogger {
|
|
20
31
|
constructor(data) {
|
|
21
32
|
this.data = data;
|
|
@@ -39,4 +50,17 @@ class ErrorLogger {
|
|
|
39
50
|
}
|
|
40
51
|
}
|
|
41
52
|
exports.ErrorLogger = ErrorLogger;
|
|
53
|
+
function log_error(error) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
55
|
+
try {
|
|
56
|
+
(0, mongo_helper_1.setUp)();
|
|
57
|
+
const db = mongo_helper_1.database.collection("_generation_log");
|
|
58
|
+
const result = yield db.insertOne(error);
|
|
59
|
+
return result;
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
console.log(e);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}
|
|
42
66
|
//# sourceMappingURL=logger.js.map
|
package/dist/logger.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,2FAA2F;AAC3F,oCAAoC;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,2FAA2F;AAC3F,oCAAoC;;;;;;;;;;;;;;;AAoDpC,8BASC;AA3DD,kDAA0B;AAC1B,wDAAwD;AAcxD,MAAa,YAAa,SAAQ,KAAK;IAErC,YAAY,OAAe,EAAE,QA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src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,IAAI,EAAE,MAAM,CAAM;IAClB,uBAAuB,EAAE,MAAM,CAAC;gBAErC,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,EACD,IAAI,EAAE,MAAM,EACZ,uBAAuB,EAAE,MAAM;IAS3B,QAAQ;;;;
|
|
1
|
+
{"version":3,"file":"generate_concept_facts.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,IAAI,EAAE,MAAM,CAAM;IAClB,uBAAuB,EAAE,MAAM,CAAC;gBAErC,aAAa,EAAE,aAAa,EAC5B,OAAO,EAAE;QACP,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,EACD,IAAI,EAAE,MAAM,EACZ,uBAAuB,EAAE,MAAM;IAS3B,QAAQ;;;;IA6Fd,SAAS,CAAC,QAAQ,EAAE,GAAG;CAWxB"}
|
|
@@ -61,11 +61,18 @@ class GenerateConceptFacts {
|
|
|
61
61
|
},
|
|
62
62
|
});
|
|
63
63
|
if (!openAiResponse) {
|
|
64
|
-
yield
|
|
65
|
-
|
|
66
|
-
data: openAiResponse,
|
|
64
|
+
yield (0, logger_1.log_error)({
|
|
65
|
+
flow: "manual_generation",
|
|
66
|
+
data: JSON.stringify(openAiResponse),
|
|
67
|
+
error: "empty_openai_response",
|
|
67
68
|
title: this.content.title,
|
|
68
|
-
|
|
69
|
+
timestamp: new Date(),
|
|
70
|
+
type: {
|
|
71
|
+
request_type: "concept_fact",
|
|
72
|
+
n: 1,
|
|
73
|
+
},
|
|
74
|
+
});
|
|
75
|
+
return;
|
|
69
76
|
}
|
|
70
77
|
openAiResponse.metadata = {
|
|
71
78
|
req_time: (_a = openAiResponse.created) !== null && _a !== void 0 ? _a : new Date(),
|
|
@@ -81,21 +88,38 @@ class GenerateConceptFacts {
|
|
|
81
88
|
model: this.openAiService.model,
|
|
82
89
|
usage: openAiResponse.usage,
|
|
83
90
|
};
|
|
91
|
+
const concepts_facts = this.parseJson(openAiResponse);
|
|
84
92
|
return {
|
|
85
|
-
concepts_facts:
|
|
93
|
+
concepts_facts: concepts_facts,
|
|
86
94
|
metadata: openAiResponse.metadata,
|
|
87
95
|
};
|
|
88
96
|
}
|
|
89
97
|
catch (error) {
|
|
90
98
|
console.log(error);
|
|
91
|
-
yield
|
|
92
|
-
|
|
93
|
-
data: error,
|
|
99
|
+
yield (0, logger_1.log_error)({
|
|
100
|
+
flow: "manual_generation",
|
|
101
|
+
data: JSON.stringify(error),
|
|
102
|
+
timestamp: new Date(),
|
|
103
|
+
error: "error_in_concept_facts_generation",
|
|
94
104
|
title: this.content.title,
|
|
95
|
-
|
|
105
|
+
type: {
|
|
106
|
+
request_type: "concept_fact",
|
|
107
|
+
n: 1,
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
return;
|
|
96
111
|
}
|
|
97
112
|
});
|
|
98
113
|
}
|
|
114
|
+
parseJson(response) {
|
|
115
|
+
try {
|
|
116
|
+
const concepts_facts = JSON.parse(response.output_text).concepts_facts;
|
|
117
|
+
return concepts_facts;
|
|
118
|
+
}
|
|
119
|
+
catch (e) {
|
|
120
|
+
throw new logger_1.ParsingError("Something went wrong in parsing the json", response);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
99
123
|
}
|
|
100
124
|
exports.GenerateConceptFacts = GenerateConceptFacts;
|
|
101
125
|
//# sourceMappingURL=generate_concept_facts.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_concept_facts.js","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mGAA4F;AAC5F,2DAAuD;AAEvD,
|
|
1
|
+
{"version":3,"file":"generate_concept_facts.js","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mGAA4F;AAC5F,2DAAuD;AAEvD,sCAAiE;AAEjE,MAAa,oBAAoB;IAW/B,YACE,aAA4B,EAC5B,OAKC,EACD,IAAY,EACZ,uBAA+B;QAX1B,SAAI,GAAW,EAAE,CAAC;QAavB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,CAAC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AAC;oBACd,IAAI,EAAE,mBAAmB;oBACzB,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;oBAC3B,SAAS,EAAE,IAAI,IAAI,EAAE;oBACrB,KAAK,EAAE,mCAAmC;oBAC1C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;oBACzB,IAAI,EAAE;wBACJ,YAAY,EAAE,cAAc;wBAC5B,CAAC,EAAE,CAAC;qBACL;iBACF,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,QAAa;QACrB,IAAI,CAAC;YACH,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC;YACvE,OAAO,cAAc,CAAC;QACxB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,qBAAY,CACpB,0CAA0C,EAC1C,QAAQ,CACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AArID,oDAqIC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAI5D,qBAAa,gBAAgB;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAM;IAClB,OAAO,EAAE;QACd,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,OAAO,EAAE,GAAG,EAAE,CAAC;KAChB,CAAC;IACK,mBAAmB,EAAE,MAAM,CAAC;IACnC,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBAE5B,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE;QACP,KAAK,EAAE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,18 @@ class GenerateTypology {
|
|
|
60
60
|
});
|
|
61
61
|
console.log(openAiResponse);
|
|
62
62
|
if (!openAiResponse) {
|
|
63
|
-
yield
|
|
64
|
-
|
|
65
|
-
data: openAiResponse,
|
|
63
|
+
yield (0, logger_1.log_error)({
|
|
64
|
+
flow: "manual_generation",
|
|
65
|
+
data: JSON.stringify(openAiResponse),
|
|
66
|
+
error: "empty_openai_response",
|
|
66
67
|
title: this.content.title,
|
|
67
|
-
|
|
68
|
+
timestamp: new Date(),
|
|
69
|
+
type: {
|
|
70
|
+
request_type: "breadth",
|
|
71
|
+
n: 1,
|
|
72
|
+
},
|
|
73
|
+
});
|
|
74
|
+
return;
|
|
68
75
|
}
|
|
69
76
|
openAiResponse["request_type"] = {
|
|
70
77
|
type: "breadth",
|
|
@@ -94,17 +101,23 @@ class GenerateTypology {
|
|
|
94
101
|
}
|
|
95
102
|
catch (e) {
|
|
96
103
|
console.log(e);
|
|
97
|
-
yield
|
|
98
|
-
|
|
99
|
-
data: e
|
|
104
|
+
yield (0, logger_1.log_error)({
|
|
105
|
+
flow: "manual_generation",
|
|
106
|
+
data: JSON.stringify(e),
|
|
107
|
+
timestamp: new Date(),
|
|
108
|
+
error: "error_in_typology_generation",
|
|
100
109
|
title: this.content.title,
|
|
101
|
-
|
|
110
|
+
type: {
|
|
111
|
+
request_type: "breadth",
|
|
112
|
+
n: 1,
|
|
113
|
+
},
|
|
114
|
+
});
|
|
102
115
|
}
|
|
103
116
|
});
|
|
104
117
|
}
|
|
105
118
|
parseTypologyOnSuccess(responseData) {
|
|
106
119
|
responseData.metadata.status = "completed";
|
|
107
|
-
const generatedContent =
|
|
120
|
+
const generatedContent = this.parseJson(responseData);
|
|
108
121
|
return {
|
|
109
122
|
status_code: 200,
|
|
110
123
|
metadata: [responseData.metadata],
|
|
@@ -114,6 +127,15 @@ class GenerateTypology {
|
|
|
114
127
|
// type: responseData.type,
|
|
115
128
|
};
|
|
116
129
|
}
|
|
130
|
+
parseJson(response) {
|
|
131
|
+
try {
|
|
132
|
+
const generatedContent = JSON.parse(response.output_text);
|
|
133
|
+
return generatedContent;
|
|
134
|
+
}
|
|
135
|
+
catch (e) {
|
|
136
|
+
throw new logger_1.ParsingError("Something went wrong in parsing the json", response);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
117
139
|
parseFields(fields) {
|
|
118
140
|
const fieldKeys = ["primary_field", "secondary_field", "tertiary_field"];
|
|
119
141
|
return fields.slice(0, 3).map((item, index) => ({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAkE;AAClE,sCAAiE;AAGjE,6GAAuG;AAEvG,MAAa,gBAAgB;IAW3B,YACE,aAA4B,EAC5B,IAAY,EACZ,OAKC,EACD,eAA8B,EAC9B,mBAA2B;QAnBtB,SAAI,GAAW,EAAE,CAAC;QAqBvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CACzD,IAAI,CAAC,WAAW,EAAE,CACnB,CAAC;QACF,IAAI,CAAC,mBAAmB,GAAG,mBAAmB,CAAC;IACjD,CAAC;IACK,QAAQ;;;YACZ,IAAI,CAAC;gBACH,MAAM,QAAQ,GACZ,IAAI,CAAC,IAAI,IAAI,OAAO;oBAClB,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,SAAS,IAAI,CAAC,EAAE,CAAC;oBAChC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,I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AC,KAAK,CAAC,CAAC,EAAE,IAAI;YACxB,SAAS,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC;SAC7D,CAAC,CAAC,CAAC;IACN,CAAC;IAEK,sBAAsB,CAAC,YAAiB;;YAC5C,YAAY,CAAC,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;YAExC,OAAO;gBACL,WAAW,EAAE,YAAY,CAAC,WAAW;gBACrC,QAAQ,EAAE,YAAY,CAAC,QAAQ;aAChC,CAAC;QACJ,CAAC;KAAA;CACF;AAxKD,4CAwKC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
2
|
import { cardSchema } from "../helper/schema_helper/build_card_schema";
|
|
3
|
-
import { ErrorLogger } from "../logger";
|
|
3
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
4
4
|
import { ParseCardResponse } from "../parse/parse_card_response";
|
|
5
5
|
import { OpenAiService } from "../services/open_ai_service";
|
|
6
6
|
import { GeneratedCardResponseType } from "../types/raw_card_response_types/generated_card_response_type";
|
|
@@ -62,32 +62,58 @@ export class GenerateCards {
|
|
|
62
62
|
},
|
|
63
63
|
],
|
|
64
64
|
store: false,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
65
|
+
text: {
|
|
66
|
+
format: {
|
|
67
|
+
type: "json_schema",
|
|
68
|
+
name: "card_gen_schema",
|
|
69
|
+
strict: true,
|
|
70
|
+
schema: cardSchema,
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
73
|
});
|
|
74
74
|
if (!response) {
|
|
75
|
-
await
|
|
76
|
-
|
|
77
|
-
data: response,
|
|
75
|
+
await log_error({
|
|
76
|
+
flow: "manual_generation",
|
|
77
|
+
data: JSON.stringify(response),
|
|
78
|
+
timestamp: new Date(),
|
|
79
|
+
error: "empty_openai_response",
|
|
78
80
|
title: this.content,
|
|
79
|
-
|
|
81
|
+
type: {
|
|
82
|
+
request_type: "depth",
|
|
83
|
+
n: 1,
|
|
84
|
+
},
|
|
85
|
+
});
|
|
86
|
+
return;
|
|
80
87
|
}
|
|
81
|
-
|
|
82
|
-
console.log(response);
|
|
88
|
+
|
|
83
89
|
return response;
|
|
84
90
|
} catch (error) {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
if (error instanceof ParsingError) {
|
|
92
|
+
await log_error({
|
|
93
|
+
flow: "manual_generation",
|
|
94
|
+
data: JSON.stringify(error.response),
|
|
95
|
+
timestamp: new Date(),
|
|
96
|
+
error: "parsing_error",
|
|
97
|
+
title: this.content,
|
|
98
|
+
type: {
|
|
99
|
+
request_type: "depth",
|
|
100
|
+
n: 1,
|
|
101
|
+
},
|
|
102
|
+
});
|
|
103
|
+
} else {
|
|
104
|
+
console.log(error);
|
|
105
|
+
await log_error({
|
|
106
|
+
flow: "manual_generation",
|
|
107
|
+
data: JSON.stringify(error),
|
|
108
|
+
timestamp: new Date(),
|
|
109
|
+
error: "error_in_card_generation",
|
|
110
|
+
title: this.content,
|
|
111
|
+
type: {
|
|
112
|
+
request_type: "depth",
|
|
113
|
+
n: 1,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
}
|
|
91
117
|
}
|
|
92
118
|
}
|
|
93
119
|
|
|
@@ -117,7 +143,7 @@ export class GenerateCards {
|
|
|
117
143
|
response.metadata.status = "completed";
|
|
118
144
|
/// map response to generated_content
|
|
119
145
|
|
|
120
|
-
const testCardsArray =
|
|
146
|
+
const testCardsArray = this.parseJson(response);
|
|
121
147
|
const generated_data: GeneratedCardResponseType = {
|
|
122
148
|
metadata: response.metadata,
|
|
123
149
|
generated_content: {
|
|
@@ -148,10 +174,29 @@ export class GenerateCards {
|
|
|
148
174
|
return response;
|
|
149
175
|
}
|
|
150
176
|
} catch (e: any) {
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
data: e
|
|
154
|
-
|
|
177
|
+
await log_error({
|
|
178
|
+
flow: "manual_generation",
|
|
179
|
+
data: JSON.stringify(e),
|
|
180
|
+
timestamp: new Date(),
|
|
181
|
+
error: "error_in_card_generation",
|
|
182
|
+
title: this.content,
|
|
183
|
+
type: {
|
|
184
|
+
request_type: "depth",
|
|
185
|
+
n: 1,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
parseJson(response: any) {
|
|
192
|
+
try {
|
|
193
|
+
const testCardsArray = JSON.parse(response.output_text).test_cards;
|
|
194
|
+
return testCardsArray;
|
|
195
|
+
} catch (e) {
|
|
196
|
+
throw new ParsingError(
|
|
197
|
+
"Something went wrong in parsing the json",
|
|
198
|
+
response
|
|
199
|
+
);
|
|
155
200
|
}
|
|
156
201
|
}
|
|
157
202
|
}
|
package/src/index.ts
CHANGED
|
@@ -16,67 +16,68 @@ import { BaseParamType } from "./types/base_param_type";
|
|
|
16
16
|
|
|
17
17
|
export { OnlyEverGenerator };
|
|
18
18
|
|
|
19
|
-
(async () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
19
|
+
// (async () => {
|
|
20
|
+
// const openAIKey =
|
|
21
|
+
// "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";
|
|
22
|
+
// const promptForSummary = {
|
|
23
|
+
// promptId: "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
24
|
+
// version: "13",
|
|
25
|
+
// };
|
|
26
|
+
// const promptForConceptFacts = {
|
|
27
|
+
// promptId: "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
28
|
+
// version: "6",
|
|
29
|
+
// };
|
|
30
30
|
|
|
31
|
-
|
|
31
|
+
// setUp();
|
|
32
32
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
// const source = await database.collection("_source").findOne({
|
|
34
|
+
// _id: new ObjectId("6753b1ec56e5e922b57ee2df"),
|
|
35
|
+
// });
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
37
|
+
// const contentForGen = {
|
|
38
|
+
// prompt: {
|
|
39
|
+
// typology: "",
|
|
40
|
+
// card_generation: "",
|
|
41
|
+
// },
|
|
42
|
+
// content: {
|
|
43
|
+
// source_id: source?._id?.toString() || "",
|
|
44
|
+
// title: source?.title || "",
|
|
45
|
+
// type: source?.source_type || "",
|
|
46
|
+
// headings: source?.headings || [],
|
|
47
|
+
// content: source?.content || [],
|
|
48
|
+
// fields: source?.fields || [],
|
|
49
|
+
// taxonomy: source?.generate_cards
|
|
50
|
+
// ? {
|
|
51
|
+
// generate_cards: source?.generate_cards || {
|
|
52
|
+
// state: false,
|
|
53
|
+
// reason: "",
|
|
54
|
+
// },
|
|
55
|
+
// concepts_facts: source?.concepts_facts || [],
|
|
56
|
+
// fields: source?.fields || [],
|
|
57
|
+
// }
|
|
58
|
+
// : undefined,
|
|
59
|
+
// },
|
|
60
|
+
// };
|
|
61
|
+
// const prompts = await getPrompts("text");
|
|
62
|
+
// const bloomInstructions = prompts.bloom_instructions;
|
|
63
|
+
// const cardInstructions = prompts.card_instructions;
|
|
64
|
+
// const cardExamples = prompts.card_examples;
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
// console.log("Initializing OnlyEverGenerator");
|
|
67
|
+
// const onlyEverGenerator = new OnlyEverGenerator(
|
|
68
|
+
// process.env.OPEN_AI_KEY as string,
|
|
69
|
+
// "o4-mini",
|
|
70
|
+
// contentForGen,
|
|
71
|
+
|
|
72
|
+
// "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
73
|
+
// "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
74
|
+
// "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6",
|
|
75
|
+
// {
|
|
76
|
+
// bloom_instructions: bloomInstructions,
|
|
77
|
+
// card_instructions: cardInstructions,
|
|
78
|
+
// card_examples: cardExamples,
|
|
79
|
+
// }
|
|
80
|
+
// );
|
|
81
|
+
// const response = await onlyEverGenerator.generate(true, true);
|
|
82
|
+
// console.log(response);
|
|
83
|
+
// })();
|
package/src/logger.ts
CHANGED
|
@@ -2,6 +2,29 @@
|
|
|
2
2
|
/// this is only for developmemt use
|
|
3
3
|
|
|
4
4
|
import axios from "axios";
|
|
5
|
+
import { database, setUp } from "./helper/mongo_helper";
|
|
6
|
+
|
|
7
|
+
type log_type = {
|
|
8
|
+
flow: string;
|
|
9
|
+
data: any;
|
|
10
|
+
error: string;
|
|
11
|
+
timestamp: Date;
|
|
12
|
+
title: string;
|
|
13
|
+
type: {
|
|
14
|
+
request_type: string;
|
|
15
|
+
n: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export class ParsingError extends Error {
|
|
20
|
+
public response: any;
|
|
21
|
+
constructor(message: string, response: any) {
|
|
22
|
+
super(message); // Pass message to the Error constructor
|
|
23
|
+
this.name = "ParsingError"; // Set a custom name
|
|
24
|
+
this.response = response; // Set the response
|
|
25
|
+
Object.setPrototypeOf(this, new.target.prototype); // Fix prototype chain
|
|
26
|
+
}
|
|
27
|
+
}
|
|
5
28
|
|
|
6
29
|
export class ErrorLogger {
|
|
7
30
|
data: any;
|
|
@@ -28,3 +51,13 @@ export class ErrorLogger {
|
|
|
28
51
|
}
|
|
29
52
|
}
|
|
30
53
|
}
|
|
54
|
+
export async function log_error(error: log_type) {
|
|
55
|
+
try {
|
|
56
|
+
setUp();
|
|
57
|
+
const db = database.collection("_generation_log");
|
|
58
|
+
const result = await db.insertOne(error);
|
|
59
|
+
return result;
|
|
60
|
+
} catch (e) {
|
|
61
|
+
console.log(e);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_facts_schema";
|
|
2
2
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
3
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
-
import { ErrorLogger } from "../logger";
|
|
4
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
5
5
|
|
|
6
6
|
export class GenerateConceptFacts {
|
|
7
7
|
public openAiService: OpenAiService;
|
|
@@ -75,11 +75,18 @@ export class GenerateConceptFacts {
|
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
77
|
if (!openAiResponse) {
|
|
78
|
-
await
|
|
79
|
-
|
|
80
|
-
data: openAiResponse,
|
|
78
|
+
await log_error({
|
|
79
|
+
flow: "manual_generation",
|
|
80
|
+
data: JSON.stringify(openAiResponse),
|
|
81
|
+
error: "empty_openai_response",
|
|
81
82
|
title: this.content.title,
|
|
82
|
-
|
|
83
|
+
timestamp: new Date(),
|
|
84
|
+
type: {
|
|
85
|
+
request_type: "concept_fact",
|
|
86
|
+
n: 1,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
83
90
|
}
|
|
84
91
|
openAiResponse.metadata = {
|
|
85
92
|
req_time: openAiResponse.created ?? new Date(),
|
|
@@ -95,18 +102,38 @@ export class GenerateConceptFacts {
|
|
|
95
102
|
model: this.openAiService.model,
|
|
96
103
|
usage: openAiResponse.usage,
|
|
97
104
|
};
|
|
105
|
+
const concepts_facts = this.parseJson(openAiResponse);
|
|
98
106
|
|
|
99
107
|
return {
|
|
100
|
-
concepts_facts:
|
|
108
|
+
concepts_facts: concepts_facts,
|
|
101
109
|
metadata: openAiResponse.metadata,
|
|
102
110
|
};
|
|
103
111
|
} catch (error) {
|
|
104
112
|
console.log(error);
|
|
105
|
-
await
|
|
106
|
-
|
|
107
|
-
data: error,
|
|
113
|
+
await log_error({
|
|
114
|
+
flow: "manual_generation",
|
|
115
|
+
data: JSON.stringify(error),
|
|
116
|
+
timestamp: new Date(),
|
|
117
|
+
error: "error_in_concept_facts_generation",
|
|
108
118
|
title: this.content.title,
|
|
109
|
-
|
|
119
|
+
type: {
|
|
120
|
+
request_type: "concept_fact",
|
|
121
|
+
n: 1,
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
parseJson(response: any) {
|
|
129
|
+
try {
|
|
130
|
+
const concepts_facts = JSON.parse(response.output_text).concepts_facts;
|
|
131
|
+
return concepts_facts;
|
|
132
|
+
} catch (e) {
|
|
133
|
+
throw new ParsingError(
|
|
134
|
+
"Something went wrong in parsing the json",
|
|
135
|
+
response
|
|
136
|
+
);
|
|
110
137
|
}
|
|
111
138
|
}
|
|
112
139
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import test from "node:test";
|
|
2
2
|
import { getOpenAI, OpenAIHelper } from "../helper/openai_helper";
|
|
3
|
-
import { ErrorLogger } from "../logger";
|
|
3
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
4
4
|
import { OpenAiService } from "../services/open_ai_service";
|
|
5
5
|
import { text } from "stream/consumers";
|
|
6
6
|
import { buildClassifySummarizeSchema } from "../helper/schema_helper/build_classify_summarize_schema";
|
|
@@ -76,11 +76,18 @@ export class GenerateTypology {
|
|
|
76
76
|
});
|
|
77
77
|
console.log(openAiResponse);
|
|
78
78
|
if (!openAiResponse) {
|
|
79
|
-
await
|
|
80
|
-
|
|
81
|
-
data: openAiResponse,
|
|
79
|
+
await log_error({
|
|
80
|
+
flow: "manual_generation",
|
|
81
|
+
data: JSON.stringify(openAiResponse),
|
|
82
|
+
error: "empty_openai_response",
|
|
82
83
|
title: this.content.title,
|
|
83
|
-
|
|
84
|
+
timestamp: new Date(),
|
|
85
|
+
type: {
|
|
86
|
+
request_type: "breadth",
|
|
87
|
+
n: 1,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
return;
|
|
84
91
|
}
|
|
85
92
|
openAiResponse["request_type"] = {
|
|
86
93
|
type: "breadth",
|
|
@@ -109,17 +116,23 @@ export class GenerateTypology {
|
|
|
109
116
|
}
|
|
110
117
|
} catch (e: any) {
|
|
111
118
|
console.log(e);
|
|
112
|
-
await
|
|
113
|
-
|
|
114
|
-
data: e
|
|
119
|
+
await log_error({
|
|
120
|
+
flow: "manual_generation",
|
|
121
|
+
data: JSON.stringify(e),
|
|
122
|
+
timestamp: new Date(),
|
|
123
|
+
error: "error_in_typology_generation",
|
|
115
124
|
title: this.content.title,
|
|
116
|
-
|
|
125
|
+
type: {
|
|
126
|
+
request_type: "breadth",
|
|
127
|
+
n: 1,
|
|
128
|
+
},
|
|
129
|
+
});
|
|
117
130
|
}
|
|
118
131
|
}
|
|
119
132
|
|
|
120
133
|
parseTypologyOnSuccess(responseData: any) {
|
|
121
134
|
responseData.metadata.status = "completed";
|
|
122
|
-
const generatedContent =
|
|
135
|
+
const generatedContent = this.parseJson(responseData);
|
|
123
136
|
|
|
124
137
|
return {
|
|
125
138
|
status_code: 200,
|
|
@@ -132,6 +145,18 @@ export class GenerateTypology {
|
|
|
132
145
|
};
|
|
133
146
|
}
|
|
134
147
|
|
|
148
|
+
parseJson(response: any) {
|
|
149
|
+
try {
|
|
150
|
+
const generatedContent = JSON.parse(response.output_text);
|
|
151
|
+
return generatedContent;
|
|
152
|
+
} catch (e) {
|
|
153
|
+
throw new ParsingError(
|
|
154
|
+
"Something went wrong in parsing the json",
|
|
155
|
+
response
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
135
160
|
parseFields(fields: Array<string>) {
|
|
136
161
|
const fieldKeys = ["primary_field", "secondary_field", "tertiary_field"];
|
|
137
162
|
return fields.slice(0, 3).map((item, index) => ({
|