only_ever_generator 6.0.2 → 6.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +0 -5
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/helper/schema_helper/build_classify_summarize_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_classify_summarize_schema.js +4 -1
- package/dist/helper/schema_helper/build_classify_summarize_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.js +4 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +10 -1
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +13 -0
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/utils/distributed_quote_restoration.d.ts +31 -0
- package/dist/utils/distributed_quote_restoration.d.ts.map +1 -0
- package/dist/utils/distributed_quote_restoration.js +69 -0
- package/dist/utils/distributed_quote_restoration.js.map +1 -0
- package/dist/utils/sanitize_strings.d.ts +32 -0
- package/dist/utils/sanitize_strings.d.ts.map +1 -0
- package/dist/utils/sanitize_strings.js +61 -0
- package/dist/utils/sanitize_strings.js.map +1 -0
- package/package.json +1 -1
- package/src/bootstrap/app.ts +0 -5
- package/src/helper/schema_helper/build_classify_summarize_schema.ts +5 -1
- package/src/helper/schema_helper/build_concept_facts_schema.ts +5 -1
- package/src/index.ts +1 -1
- package/src/typology_gen/generate_concept_facts.ts +18 -1
- package/src/typology_gen/generate_typology.ts +23 -0
- package/src/utils/distributed_quote_restoration.ts +80 -0
- package/src/utils/sanitize_strings.ts +65 -0
|
@@ -1 +1 @@
|
|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d,KAAK,EAAE,MAAM,EACb,iBAAiB,EAAE,aAAa,EAChC,mBAAmB,EAAE,MAAM,EAC3B,uBAAuB,EAAE,MAAM,EAC/B,0BAA0B,EAAE,MAAM,EAClC,mBAAmB,EAAE;QACnB,kBAAkB,EAAE,MAAM,CAAC;QAC3B,iBAAiB,EAAE,MAAM,CAAC;QAC1B,aAAa,EAAE,MAAM,CAAC;KACvB,EACD,oBAAoB,EAAE,OAAO;IA+BzB,QAAQ,CACZ,iBAAiB,GAAE,OAAe,EAClC,aAAa,GAAE,OAAe,GAC7B,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAmFtB,6CAA6C;IAQvC,YAAY,CAAC,CAAC,GAAE,MAAU;IAkB1B,gBAAgB;IAyBhB,oBAAoB,CAAC,gBAAgB,EAAE,GAAG;;;;IAuB1C,kBAAkB,CAAC,gBAAgB,EAAE,GAAG;;;;;;;;;;;;;;;;;;IASxC,kBAAkB,CACtB,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,EAAE,EACH,QAAQ,EAAE,MAAM;;;;;;;;;;;;;;;;;;;IASZ,mBAAmB,CACvB,cAAc,EAAE;QACd,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,EAAE,EACH,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;CAUpB"}
|
package/dist/bootstrap/app.js
CHANGED
|
@@ -61,10 +61,6 @@ class OnlyEverGenerator {
|
|
|
61
61
|
return __awaiter(this, arguments, void 0, function* (generate_typology = false, generate_card = false) {
|
|
62
62
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
63
63
|
try {
|
|
64
|
-
console.log(this.promptIdForTypology);
|
|
65
|
-
console.log(this.promptIdForConceptFacts);
|
|
66
|
-
console.log(this.promptIdForCardsGeneration);
|
|
67
|
-
console.log(this.openAiService.api_key);
|
|
68
64
|
let args = new generate_args_1.GenerateArgs(generate_card, generate_typology, false);
|
|
69
65
|
const responseToReturn = [];
|
|
70
66
|
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
@@ -73,7 +69,6 @@ class OnlyEverGenerator {
|
|
|
73
69
|
console.log("Generating typology");
|
|
74
70
|
this.typologyResponse = yield this.generateTypology();
|
|
75
71
|
console.log("Typology generated");
|
|
76
|
-
console.log(this.typologyResponse);
|
|
77
72
|
if (((_a = this.typologyResponse) === null || _a === void 0 ? void 0 : _a.status_code) == 200 ||
|
|
78
73
|
((_d = (_c = (_b = this.typologyResponse) === null || _b === void 0 ? void 0 : _b.generate_cards) === null || _c === void 0 ? void 0 : _c.state) !== null && _d !== void 0 ? _d : false) == true) {
|
|
79
74
|
console.log("Concept facts generating");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../../src/bootstrap/app.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,+DAA2D;AAC3D,wEAAmE;AACnE,iEAA4D;AAC5D,yEAAqE;AACrE,0DAAsD;AACtD,qFAAiF;AACjF,mGAA+F;AAC/F,qGAAiG;AAMjG,mFAA8E;AAE9E,MAAa,iBAAiB;IAiC5B,YACE,MAAc,EACd,KAAa,EACb,iBAAgC,EAChC,mBAA2B,EAC3B,uBAA+B,EAC/B,0BAAkC,EAClC,mBAIC,EACD,oBAA6B;QA5CxB,YAAO,GAAW,EAAE,CAAC;QAG5B,yDAAyD;QACzD,kBAAa,GAOT,SAAS,CAAC;QACd,sBAAiB,GAAW,EAAE,CAAC;QAC/B,qBAAgB,GAAW,EAAE,CAAC;QACvB,yBAAoB,GAAY,KAAK,CA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EACH,QAAgB,EAChB,SAAiB;;YAEjB,MAAM,UAAU,GAAG,MAAM,IAAI,0CAAmB,EAAE,CAAC,WAAW,CAC5D,cAAc,EACd,QAAQ,EACR,SAAS,aAAT,SAAS,cAAT,SAAS,GAAI,GAAG,CACjB,CAAC;YAEF,OAAO,UAAU,CAAC;QACpB,CAAC;KAAA;CACF;AAxRD,8CAwRC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build_classify_summarize_schema.d.ts","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_classify_summarize_schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build_classify_summarize_schema.d.ts","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_classify_summarize_schema.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,4BAA4B,GAAU,UAAU,MAAM,EAAE,iBA6BpE,CAAC"}
|
|
@@ -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.buildClassifySummarizeSchema = void 0;
|
|
13
13
|
const mongo_helper_1 = require("../mongo_helper");
|
|
14
|
+
const sanitize_strings_1 = require("../../utils/sanitize_strings");
|
|
14
15
|
// Function to populate enums in a parsed schema
|
|
15
16
|
const buildClassifySummarizeSchema = (headings) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
17
|
var _a, _b, _c, _d, _e, _f;
|
|
@@ -28,10 +29,12 @@ const buildClassifySummarizeSchema = (headings) => __awaiter(void 0, void 0, voi
|
|
|
28
29
|
}
|
|
29
30
|
// Deep clone to avoid mutating the original
|
|
30
31
|
const populatedSchema = JSON.parse(schema);
|
|
32
|
+
// Sanitize headings to remove quotes for OpenAI structured outputs
|
|
33
|
+
const sanitizedStrings = (0, sanitize_strings_1.sanitizeStringsForSchema)(headings);
|
|
31
34
|
// Type-safe enum population for reference field in summary_cards
|
|
32
35
|
if ((_f = (_e = (_d = (_c = (_b = (_a = populatedSchema.schema) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.summary_cards) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.properties) === null || _e === void 0 ? void 0 : _e.reference) === null || _f === void 0 ? void 0 : _f.enum) {
|
|
33
36
|
populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
|
|
34
|
-
|
|
37
|
+
sanitizedStrings;
|
|
35
38
|
}
|
|
36
39
|
return populatedSchema;
|
|
37
40
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build_classify_summarize_schema.js","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_classify_summarize_schema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;
|
|
1
|
+
{"version":3,"file":"build_classify_summarize_schema.js","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_classify_summarize_schema.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,kDAA4D;AAC5D,mEAAwE;AAExE,gDAAgD;AACzC,MAAM,4BAA4B,GAAG,CAAO,QAAkB,EAAE,EAAE;;IACvE,IAAA,oBAAK,GAAE,CAAC;IACR,MAAM,QAAQ,GAAG,IAAI,uBAAQ,CAAC,0BAA0B,CAAC,CAAC;IAC1D,MAAM,SAAS,GAAG,MAAM,uBAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;QAC9D,GAAG,EAAE,QAAQ;KACd,CAAC,CAAC;IACH,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;IAChC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;IACtC,CAAC;IACD,4CAA4C;IAC5C,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAE3C,mEAAmE;IACnE,MAAM,gBAAgB,GAAG,IAAA,2CAAwB,EAAC,QAAQ,CAAC,CAAC;IAE5D,iEAAiE;IACjE,IACE,MAAA,MAAA,MAAA,MAAA,MAAA,MAAA,eAAe,CAAC,MAAM,0CAAE,UAAU,0CAAE,aAAa,0CAAE,KAAK,0CAAE,UAAU,0CAChE,SAAS,0CAAE,IAAI,EACnB,CAAC;QACD,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI;YAC7E,gBAAgB,CAAC;IACrB,CAAC;IAED,OAAO,eAAe,CAAC;AACzB,CAAC,CAAA,CAAC;AA7BW,QAAA,4BAA4B,gCA6BvC;AAEF,wEAAwE;AACxE,4EAA4E;AAC5E,+CAA+C;AAC/C,uEAAuE;AACvE,qCAAqC;AAErC,mBAAmB;AACnB,KAAK"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build_concept_facts_schema.d.ts","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_concept_facts_schema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build_concept_facts_schema.d.ts","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_concept_facts_schema.ts"],"names":[],"mappings":"AAKA,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,MAAM,EAAE,EAClB,IAAI,GAAE,MAAkC,EACxC,MAAM,GAAE,OAAc,gBAoCvB"}
|
|
@@ -12,6 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
12
12
|
exports.buildConceptFactSchema = buildConceptFactSchema;
|
|
13
13
|
const mongodb_1 = require("mongodb");
|
|
14
14
|
const mongo_helper_1 = require("../mongo_helper");
|
|
15
|
+
const sanitize_strings_1 = require("../../utils/sanitize_strings");
|
|
15
16
|
// Function to populate enums in a parsed schema
|
|
16
17
|
function buildConceptFactSchema(headings_1) {
|
|
17
18
|
return __awaiter(this, arguments, void 0, function* (headings, name = "concept_fact_gen_schema", strict = true) {
|
|
@@ -34,10 +35,12 @@ function buildConceptFactSchema(headings_1) {
|
|
|
34
35
|
populatedSchema.name = name;
|
|
35
36
|
populatedSchema.strict = strict;
|
|
36
37
|
const allowedRefs = [...headings, ""];
|
|
38
|
+
// Sanitize headings to remove quotes for OpenAI structured outputs
|
|
39
|
+
const sanitizedStrings = (0, sanitize_strings_1.sanitizeStringsForSchema)(allowedRefs);
|
|
37
40
|
// Type-safe enum population for reference field
|
|
38
41
|
if ((_f = (_e = (_d = (_c = (_b = (_a = populatedSchema.schema) === null || _a === void 0 ? void 0 : _a.properties) === null || _b === void 0 ? void 0 : _b.concepts_facts) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.properties) === null || _e === void 0 ? void 0 : _e.reference) === null || _f === void 0 ? void 0 : _f.enum) {
|
|
39
42
|
populatedSchema.schema.properties.concepts_facts.items.properties.reference.enum =
|
|
40
|
-
|
|
43
|
+
sanitizedStrings;
|
|
41
44
|
}
|
|
42
45
|
return populatedSchema;
|
|
43
46
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build_concept_facts_schema.js","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_concept_facts_schema.ts"],"names":[],"mappings":";;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"build_concept_facts_schema.js","sourceRoot":"","sources":["../../../src/helper/schema_helper/build_concept_facts_schema.ts"],"names":[],"mappings":";;;;;;;;;;;AAKA,wDAuCC;AA5CD,qCAAmC;AACnC,kDAAkD;AAClD,mEAAwE;AAExE,gDAAgD;AAChD,SAAsB,sBAAsB;yDAC1C,QAAkB,EAClB,OAAe,yBAAyB,EACxC,SAAkB,IAAI;;QAEtB,IAAA,oBAAK,GAAE,CAAC;QACR,MAAM,QAAQ,GAAG,IAAI,kBAAQ,CAAC,0BAA0B,CAAC,CAAC;QAC1D,MAAM,SAAS,GAAG,MAAM,uBAAQ,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC;YAC9D,GAAG,EAAE,QAAQ;SACd,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QACD,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC;QAChC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QACD,4CAA4C;QAC5C,MAAM,eAAe,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QAE3C,8BAA8B;QAC9B,eAAe,CAAC,IAAI,GAAG,IAAI,CAAC;QAC5B,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC;QAEhC,MAAM,WAAW,GAAG,CAAC,GAAG,QAAQ,EAAE,EAAE,CAAC,CAAC;QAEtC,mEAAmE;QACnE,MAAM,gBAAgB,GAAG,IAAA,2CAAwB,EAAC,WAAW,CAAC,CAAC;QAE/D,gDAAgD;QAChD,IACE,MAAA,MAAA,MAAA,MAAA,MAAA,MAAA,eAAe,CAAC,MAAM,0CAAE,UAAU,0CAAE,cAAc,0CAAE,KAAK,0CAAE,UAAU,0CACjE,SAAS,0CAAE,IAAI,EACnB,CAAC;YACD,eAAe,CAAC,MAAM,CAAC,UAAU,CAAC,cAAc,CAAC,KAAK,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI;gBAC9E,gBAAgB,CAAC;QACrB,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -37,7 +37,7 @@ const get_prompts_1 = require("./services/get_prompts");
|
|
|
37
37
|
};
|
|
38
38
|
(0, mongo_helper_1.setUp)();
|
|
39
39
|
const source = yield mongo_helper_1.database.collection("_source").findOne({
|
|
40
|
-
_id: new mongo_helper_1.ObjectId("
|
|
40
|
+
_id: new mongo_helper_1.ObjectId("6753b1968b647549b03cc3fe"),
|
|
41
41
|
});
|
|
42
42
|
const contentForGen = {
|
|
43
43
|
prompt: {
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAO5D,qBAAa,oBAAoB;IACxB,aAAa,EAAE,aAAa,CAAC;IAC7B,YAAY,EAAE,YAAY,CAAC;IAC3B,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,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,QAAQ,EAAE,MAAM,EAChB,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,EAC/B,oBAAoB,EAAE,OAAO;IAWzB,QAAQ;;;;IAqGd,SAAS,CAAC,QAAQ,EAAE,GAAG;CAkBxB"}
|
|
@@ -13,6 +13,7 @@ exports.GenerateConceptFacts = void 0;
|
|
|
13
13
|
const build_concept_facts_schema_1 = require("../helper/schema_helper/build_concept_facts_schema");
|
|
14
14
|
const openai_helper_1 = require("../helper/openai_helper");
|
|
15
15
|
const logger_1 = require("../logger");
|
|
16
|
+
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
16
17
|
class GenerateConceptFacts {
|
|
17
18
|
constructor(openAiService, sourceId, content, type, promptIdForConceptFacts, generationCurriculum) {
|
|
18
19
|
this.type = "";
|
|
@@ -76,6 +77,10 @@ class GenerateConceptFacts {
|
|
|
76
77
|
});
|
|
77
78
|
return;
|
|
78
79
|
}
|
|
80
|
+
// // Restore quotes in the response (works without original mapping)
|
|
81
|
+
// if (openAiResponse.output) {
|
|
82
|
+
// openAiResponse.output = restoreQuotesInObject(openAiResponse.output);
|
|
83
|
+
// }
|
|
79
84
|
openAiResponse.metadata = {
|
|
80
85
|
req_time: (_a = openAiResponse.created) !== null && _a !== void 0 ? _a : new Date(),
|
|
81
86
|
req_type: {
|
|
@@ -118,7 +123,11 @@ class GenerateConceptFacts {
|
|
|
118
123
|
parseJson(response) {
|
|
119
124
|
try {
|
|
120
125
|
const concepts_facts = JSON.parse(response.output_text).concepts_facts;
|
|
121
|
-
|
|
126
|
+
if (concepts_facts) {
|
|
127
|
+
return concepts_facts.map((item) => {
|
|
128
|
+
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
129
|
+
});
|
|
130
|
+
}
|
|
122
131
|
}
|
|
123
132
|
catch (e) {
|
|
124
133
|
throw new logger_1.ParsingError("Something went wrong in parsing the json", response);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_concept_facts.js","sourceRoot":"","sources":["../../src/typology_gen/generate_concept_facts.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mGAA4F;AAC5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qB,EAAC,IAAI,CAAC,SAAS,CAAC,IAChD;gBACJ,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,qBAAY,CACpB,0CAA0C,EAC1C,QAAQ,CACT,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA1JD,oDA0JC"}
|
|
@@ -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;
|
|
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;AAQ5D,qBAAa,gBAAgB;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAM;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,oBAAoB,EAAE,OAAO,CAAC;IAC9B,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,QAAQ,EAAE,MAAM,EAChB,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,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,EAC9B,mBAAmB,EAAE,MAAM,EAC3B,oBAAoB,EAAE,OAAO;IAYzB,QAAQ;IAwGd,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;;;;;;;IAexC,SAAS,CAAC,QAAQ,EAAE,GAAG;IAyBvB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;;;;IAQ3B,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;CAQ/C"}
|
|
@@ -13,6 +13,7 @@ exports.GenerateTypology = void 0;
|
|
|
13
13
|
const openai_helper_1 = require("../helper/openai_helper");
|
|
14
14
|
const logger_1 = require("../logger");
|
|
15
15
|
const build_classify_summarize_schema_1 = require("../helper/schema_helper/build_classify_summarize_schema");
|
|
16
|
+
const sanitize_strings_1 = require("../utils/sanitize_strings");
|
|
16
17
|
class GenerateTypology {
|
|
17
18
|
constructor(openAiService, type, sourceId, content, expected_fields, promptIdForTypology, generationCurriculum) {
|
|
18
19
|
this.type = "";
|
|
@@ -77,6 +78,10 @@ class GenerateTypology {
|
|
|
77
78
|
});
|
|
78
79
|
return;
|
|
79
80
|
}
|
|
81
|
+
// Restore quotes in the response (works without original mapping)
|
|
82
|
+
// if (openAiResponse.output) {
|
|
83
|
+
// openAiResponse.output = restoreQuotesInObject(openAiResponse.output);
|
|
84
|
+
// }
|
|
80
85
|
openAiResponse["request_type"] = {
|
|
81
86
|
type: "breadth",
|
|
82
87
|
n: 1,
|
|
@@ -134,8 +139,16 @@ class GenerateTypology {
|
|
|
134
139
|
};
|
|
135
140
|
}
|
|
136
141
|
parseJson(response) {
|
|
142
|
+
var _a;
|
|
137
143
|
try {
|
|
138
144
|
const generatedContent = JSON.parse(response.output_text);
|
|
145
|
+
const summaryCards = (_a = generatedContent === null || generatedContent === void 0 ? void 0 : generatedContent.summary_cards) !== null && _a !== void 0 ? _a : [];
|
|
146
|
+
if (summaryCards) {
|
|
147
|
+
const remappedSummaryCards = summaryCards.map((item) => {
|
|
148
|
+
return Object.assign(Object.assign({}, item), { reference: (0, sanitize_strings_1.restoreQuotesInString)(item.reference) });
|
|
149
|
+
});
|
|
150
|
+
return Object.assign(Object.assign({}, generatedContent), { summary_cards: remappedSummaryCards });
|
|
151
|
+
}
|
|
139
152
|
return generatedContent;
|
|
140
153
|
}
|
|
141
154
|
catch (e) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAkE;AAClE,sCAAiE;AAGjE,6GAAuG;
|
|
1
|
+
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AACA,2DAAkE;AAClE,sCAAiE;AAGjE,6GAAuG;AACvG,gEAGmC;AAEnC,MAAa,gBAAgB;IAa3B,YACE,aAA4B,EAC5B,IAAY,EACZ,QAAgB,EAChB,OAKC,EACD,eAA8B,EAC9B,mBAA2B,EAC3B,oBAA6B;QAvBxB,SAAI,GAAW,EAAE,CAAC;QAyBvB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,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;QAC/C,IAAI,CAAC,oBAAoB,GAAG,oBAAoB,CAAC;IACnD,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;oBACh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AAE,IAAA,wCAAqB,EAAC,IAAI,CAAC,SAAS,CAAC,IAChD;gBACJ,CAAC,CAAC,CAAC;gBACH,uCACK,gBAAgB,KACnB,aAAa,EAAE,oBAAoB,IACnC;YACJ,CAAC;YACD,OAAO,gBAAgB,CAAC;QAC1B,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,IAAI,qBAAY,CACpB,0CAA0C,EAC1C,QAAQ,CACT,CAAC;QACJ,CAAC;IACH,CAAC;IAED,WAAW,CAAC,MAAqB;QAC/B,MAAM,SAAS,GAAG,CAAC,eAAe,EAAE,iBAAiB,EAAE,gBAAgB,CAAC,CAAC;QACzE,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;YAC9C,CAAC,SAAS,CAAC,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;AArMD,4CAqMC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for restoring quotes in OpenAI responses across distributed Lambda functions
|
|
3
|
+
* This works without requiring original context from the API call Lambda
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Restores quotes in any OpenAI response structure
|
|
7
|
+
* Can be used in a parsing Lambda that receives the response from an API call Lambda
|
|
8
|
+
* @param openAiResponse - The complete OpenAI response object
|
|
9
|
+
* @returns Response with quotes restored in all string fields
|
|
10
|
+
*/
|
|
11
|
+
export declare function restoreQuotesInOpenAiResponse(openAiResponse: any): any;
|
|
12
|
+
/**
|
|
13
|
+
* Restores quotes in a parsed response object (after JSON parsing)
|
|
14
|
+
* Use this when you have already parsed the OpenAI response JSON
|
|
15
|
+
* @param parsedResponse - The parsed response object
|
|
16
|
+
* @returns Response with quotes restored
|
|
17
|
+
*/
|
|
18
|
+
export declare function restoreQuotesInParsedResponse(parsedResponse: any): any;
|
|
19
|
+
/**
|
|
20
|
+
* Example usage in a parsing Lambda function:
|
|
21
|
+
*
|
|
22
|
+
* // Receiving response from API call Lambda
|
|
23
|
+
* const openAiResponse = event.openAiResponse;
|
|
24
|
+
*
|
|
25
|
+
* // Restore quotes without needing original mapping
|
|
26
|
+
* const restoredResponse = restoreQuotesInOpenAiResponse(openAiResponse);
|
|
27
|
+
*
|
|
28
|
+
* // Now process the response with original quotes restored
|
|
29
|
+
* const processedData = processResponse(restoredResponse);
|
|
30
|
+
*/
|
|
31
|
+
//# sourceMappingURL=distributed_quote_restoration.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributed_quote_restoration.d.ts","sourceRoot":"","sources":["../../src/utils/distributed_quote_restoration.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,GAAG,GAAG,GAAG,CA2CtE;AAED;;;;;GAKG;AACH,wBAAgB,6BAA6B,CAAC,cAAc,EAAE,GAAG,GAAG,GAAG,CAEtE;AAED;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility for restoring quotes in OpenAI responses across distributed Lambda functions
|
|
4
|
+
* This works without requiring original context from the API call Lambda
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.restoreQuotesInOpenAiResponse = restoreQuotesInOpenAiResponse;
|
|
8
|
+
exports.restoreQuotesInParsedResponse = restoreQuotesInParsedResponse;
|
|
9
|
+
const sanitize_strings_1 = require("./sanitize_strings");
|
|
10
|
+
/**
|
|
11
|
+
* Restores quotes in any OpenAI response structure
|
|
12
|
+
* Can be used in a parsing Lambda that receives the response from an API call Lambda
|
|
13
|
+
* @param openAiResponse - The complete OpenAI response object
|
|
14
|
+
* @returns Response with quotes restored in all string fields
|
|
15
|
+
*/
|
|
16
|
+
function restoreQuotesInOpenAiResponse(openAiResponse) {
|
|
17
|
+
var _a, _b;
|
|
18
|
+
if (!openAiResponse) {
|
|
19
|
+
return openAiResponse;
|
|
20
|
+
}
|
|
21
|
+
// Create a deep copy to avoid mutating the original
|
|
22
|
+
const restoredResponse = JSON.parse(JSON.stringify(openAiResponse));
|
|
23
|
+
// Restore quotes in the main output/content
|
|
24
|
+
if (restoredResponse.output) {
|
|
25
|
+
restoredResponse.output = (0, sanitize_strings_1.restoreQuotesInObject)(restoredResponse.output);
|
|
26
|
+
}
|
|
27
|
+
// Handle different response formats
|
|
28
|
+
if (restoredResponse.choices &&
|
|
29
|
+
((_b = (_a = restoredResponse.choices[0]) === null || _a === void 0 ? void 0 : _a.message) === null || _b === void 0 ? void 0 : _b.content)) {
|
|
30
|
+
try {
|
|
31
|
+
const content = JSON.parse(restoredResponse.choices[0].message.content);
|
|
32
|
+
restoredResponse.choices[0].message.content = JSON.stringify((0, sanitize_strings_1.restoreQuotesInObject)(content));
|
|
33
|
+
}
|
|
34
|
+
catch (error) {
|
|
35
|
+
// If content is not JSON, restore quotes directly
|
|
36
|
+
restoredResponse.choices[0].message.content = (0, sanitize_strings_1.restoreQuotesInObject)(restoredResponse.choices[0].message.content);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
// Handle any other potential content fields
|
|
40
|
+
if (restoredResponse.content) {
|
|
41
|
+
restoredResponse.content = (0, sanitize_strings_1.restoreQuotesInObject)(restoredResponse.content);
|
|
42
|
+
}
|
|
43
|
+
if (restoredResponse.generated_content) {
|
|
44
|
+
restoredResponse.generated_content = (0, sanitize_strings_1.restoreQuotesInObject)(restoredResponse.generated_content);
|
|
45
|
+
}
|
|
46
|
+
return restoredResponse;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Restores quotes in a parsed response object (after JSON parsing)
|
|
50
|
+
* Use this when you have already parsed the OpenAI response JSON
|
|
51
|
+
* @param parsedResponse - The parsed response object
|
|
52
|
+
* @returns Response with quotes restored
|
|
53
|
+
*/
|
|
54
|
+
function restoreQuotesInParsedResponse(parsedResponse) {
|
|
55
|
+
return (0, sanitize_strings_1.restoreQuotesInObject)(parsedResponse);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Example usage in a parsing Lambda function:
|
|
59
|
+
*
|
|
60
|
+
* // Receiving response from API call Lambda
|
|
61
|
+
* const openAiResponse = event.openAiResponse;
|
|
62
|
+
*
|
|
63
|
+
* // Restore quotes without needing original mapping
|
|
64
|
+
* const restoredResponse = restoreQuotesInOpenAiResponse(openAiResponse);
|
|
65
|
+
*
|
|
66
|
+
* // Now process the response with original quotes restored
|
|
67
|
+
* const processedData = processResponse(restoredResponse);
|
|
68
|
+
*/
|
|
69
|
+
//# sourceMappingURL=distributed_quote_restoration.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"distributed_quote_restoration.js","sourceRoot":"","sources":["../../src/utils/distributed_quote_restoration.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAUH,sEA2CC;AAQD,sEAEC;AA7DD,yDAA2D;AAE3D;;;;;GAKG;AACH,SAAgB,6BAA6B,CAAC,cAAmB;;IAC/D,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,OAAO,cAAc,CAAC;IACxB,CAAC;IAED,oDAAoD;IACpD,MAAM,gBAAgB,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC;IAEpE,4CAA4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AO,IAAA,wCAAqB,EAAC,cAAc,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;;;;;GAWG"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for sanitizing strings for OpenAI structured outputs
|
|
3
|
+
* and restoring them back to their original form without requiring original mapping
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Sanitizes an array of strings by replacing quotes with a safe placeholder
|
|
7
|
+
* This approach is stateless and doesn't require storing mappings
|
|
8
|
+
* @param strings - Array of strings to sanitize
|
|
9
|
+
* @returns Array of sanitized strings
|
|
10
|
+
*/
|
|
11
|
+
export declare function sanitizeStringsForSchema(strings: string[]): string[];
|
|
12
|
+
/**
|
|
13
|
+
* Restores quotes in a string by replacing placeholders with actual quotes
|
|
14
|
+
* This works without needing the original mapping
|
|
15
|
+
* @param sanitizedString - String with quote placeholders
|
|
16
|
+
* @returns Original string with quotes restored
|
|
17
|
+
*/
|
|
18
|
+
export declare function restoreQuotesInString(sanitizedString: string): string;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively restores quotes in an object's string values
|
|
21
|
+
* This works across Lambda functions without requiring original context
|
|
22
|
+
* @param obj - Object to process
|
|
23
|
+
* @returns Object with quotes restored
|
|
24
|
+
*/
|
|
25
|
+
export declare function restoreQuotesInObject(obj: any): any;
|
|
26
|
+
/**
|
|
27
|
+
* Legacy function signature for backward compatibility
|
|
28
|
+
* Now ignores the originalMapping parameter since it's not needed
|
|
29
|
+
* @deprecated Use restoreQuotesInObject(obj) instead
|
|
30
|
+
*/
|
|
31
|
+
export declare function restoreQuotesInObjectLegacy(obj: any, originalMapping?: Map<string, string>): any;
|
|
32
|
+
//# sourceMappingURL=sanitize_strings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize_strings.d.ts","sourceRoot":"","sources":["../../src/utils/sanitize_strings.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAEpE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,eAAe,EAAE,MAAM,GAAG,MAAM,CAErE;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,CAkBnD;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE,GAAG,EACR,eAAe,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,GAAG,CAEL"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Utility functions for sanitizing strings for OpenAI structured outputs
|
|
4
|
+
* and restoring them back to their original form without requiring original mapping
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.sanitizeStringsForSchema = sanitizeStringsForSchema;
|
|
8
|
+
exports.restoreQuotesInString = restoreQuotesInString;
|
|
9
|
+
exports.restoreQuotesInObject = restoreQuotesInObject;
|
|
10
|
+
exports.restoreQuotesInObjectLegacy = restoreQuotesInObjectLegacy;
|
|
11
|
+
// Use a unique, reversible encoding for quotes
|
|
12
|
+
const QUOTE_PLACEHOLDER = "___QUOTE___";
|
|
13
|
+
/**
|
|
14
|
+
* Sanitizes an array of strings by replacing quotes with a safe placeholder
|
|
15
|
+
* This approach is stateless and doesn't require storing mappings
|
|
16
|
+
* @param strings - Array of strings to sanitize
|
|
17
|
+
* @returns Array of sanitized strings
|
|
18
|
+
*/
|
|
19
|
+
function sanitizeStringsForSchema(strings) {
|
|
20
|
+
return strings.map((str) => str.replace(/"/g, QUOTE_PLACEHOLDER));
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Restores quotes in a string by replacing placeholders with actual quotes
|
|
24
|
+
* This works without needing the original mapping
|
|
25
|
+
* @param sanitizedString - String with quote placeholders
|
|
26
|
+
* @returns Original string with quotes restored
|
|
27
|
+
*/
|
|
28
|
+
function restoreQuotesInString(sanitizedString) {
|
|
29
|
+
return sanitizedString.replace(new RegExp(QUOTE_PLACEHOLDER, "g"), '"');
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Recursively restores quotes in an object's string values
|
|
33
|
+
* This works across Lambda functions without requiring original context
|
|
34
|
+
* @param obj - Object to process
|
|
35
|
+
* @returns Object with quotes restored
|
|
36
|
+
*/
|
|
37
|
+
function restoreQuotesInObject(obj) {
|
|
38
|
+
if (typeof obj === "string") {
|
|
39
|
+
return restoreQuotesInString(obj);
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(obj)) {
|
|
42
|
+
return obj.map((item) => restoreQuotesInObject(item));
|
|
43
|
+
}
|
|
44
|
+
if (obj && typeof obj === "object") {
|
|
45
|
+
const result = {};
|
|
46
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
47
|
+
result[key] = restoreQuotesInObject(value);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
return obj;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Legacy function signature for backward compatibility
|
|
55
|
+
* Now ignores the originalMapping parameter since it's not needed
|
|
56
|
+
* @deprecated Use restoreQuotesInObject(obj) instead
|
|
57
|
+
*/
|
|
58
|
+
function restoreQuotesInObjectLegacy(obj, originalMapping) {
|
|
59
|
+
return restoreQuotesInObject(obj);
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=sanitize_strings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitize_strings.js","sourceRoot":"","sources":["../../src/utils/sanitize_strings.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAWH,4DAEC;AAQD,sDAEC;AAQD,sDAkBC;AAOD,kEAKC;AA3DD,+CAA+C;AAC/C,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAExC;;;;;GAKG;AAC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94
94
|
generate_card: boolean = false
|
|
95
95
|
): Promise<Array<any>> {
|
|
96
96
|
try {
|
|
97
|
-
console.log(this.promptIdForTypology);
|
|
98
|
-
console.log(this.promptIdForConceptFacts);
|
|
99
|
-
console.log(this.promptIdForCardsGeneration);
|
|
100
|
-
console.log(this.openAiService.api_key);
|
|
101
97
|
let args = new GenerateArgs(generate_card, generate_typology, false);
|
|
102
98
|
const responseToReturn = [];
|
|
103
99
|
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
@@ -106,7 +102,6 @@ export class OnlyEverGenerator {
|
|
|
106
102
|
console.log("Generating typology");
|
|
107
103
|
this.typologyResponse = await this.generateTypology();
|
|
108
104
|
console.log("Typology generated");
|
|
109
|
-
console.log(this.typologyResponse);
|
|
110
105
|
|
|
111
106
|
if (
|
|
112
107
|
this.typologyResponse?.status_code == 200 ||
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { database, ObjectId, setUp } from "../mongo_helper";
|
|
2
|
+
import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
|
|
2
3
|
|
|
3
4
|
// Function to populate enums in a parsed schema
|
|
4
5
|
export const buildClassifySummarizeSchema = async (headings: string[]) => {
|
|
@@ -17,13 +18,16 @@ export const buildClassifySummarizeSchema = async (headings: string[]) => {
|
|
|
17
18
|
// Deep clone to avoid mutating the original
|
|
18
19
|
const populatedSchema = JSON.parse(schema);
|
|
19
20
|
|
|
21
|
+
// Sanitize headings to remove quotes for OpenAI structured outputs
|
|
22
|
+
const sanitizedStrings = sanitizeStringsForSchema(headings);
|
|
23
|
+
|
|
20
24
|
// Type-safe enum population for reference field in summary_cards
|
|
21
25
|
if (
|
|
22
26
|
populatedSchema.schema?.properties?.summary_cards?.items?.properties
|
|
23
27
|
?.reference?.enum
|
|
24
28
|
) {
|
|
25
29
|
populatedSchema.schema.properties.summary_cards.items.properties.reference.enum =
|
|
26
|
-
|
|
30
|
+
sanitizedStrings;
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
return populatedSchema;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { ObjectId } from "mongodb";
|
|
2
2
|
import { database, setUp } from "../mongo_helper";
|
|
3
|
+
import { sanitizeStringsForSchema } from "../../utils/sanitize_strings";
|
|
3
4
|
|
|
4
5
|
// Function to populate enums in a parsed schema
|
|
5
6
|
export async function buildConceptFactSchema(
|
|
@@ -28,13 +29,16 @@ export async function buildConceptFactSchema(
|
|
|
28
29
|
|
|
29
30
|
const allowedRefs = [...headings, ""];
|
|
30
31
|
|
|
32
|
+
// Sanitize headings to remove quotes for OpenAI structured outputs
|
|
33
|
+
const sanitizedStrings = sanitizeStringsForSchema(allowedRefs);
|
|
34
|
+
|
|
31
35
|
// Type-safe enum population for reference field
|
|
32
36
|
if (
|
|
33
37
|
populatedSchema.schema?.properties?.concepts_facts?.items?.properties
|
|
34
38
|
?.reference?.enum
|
|
35
39
|
) {
|
|
36
40
|
populatedSchema.schema.properties.concepts_facts.items.properties.reference.enum =
|
|
37
|
-
|
|
41
|
+
sanitizedStrings;
|
|
38
42
|
}
|
|
39
43
|
|
|
40
44
|
return populatedSchema;
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,10 @@ import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_fa
|
|
|
2
2
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
3
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
4
|
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
5
|
+
import {
|
|
6
|
+
restoreQuotesInObject,
|
|
7
|
+
restoreQuotesInString,
|
|
8
|
+
} from "../utils/sanitize_strings";
|
|
5
9
|
|
|
6
10
|
export class GenerateConceptFacts {
|
|
7
11
|
public openAiService: OpenAiService;
|
|
@@ -94,6 +98,12 @@ export class GenerateConceptFacts {
|
|
|
94
98
|
});
|
|
95
99
|
return;
|
|
96
100
|
}
|
|
101
|
+
|
|
102
|
+
// // Restore quotes in the response (works without original mapping)
|
|
103
|
+
// if (openAiResponse.output) {
|
|
104
|
+
// openAiResponse.output = restoreQuotesInObject(openAiResponse.output);
|
|
105
|
+
// }
|
|
106
|
+
|
|
97
107
|
openAiResponse.metadata = {
|
|
98
108
|
req_time: openAiResponse.created ?? new Date(),
|
|
99
109
|
req_type: {
|
|
@@ -136,7 +146,14 @@ export class GenerateConceptFacts {
|
|
|
136
146
|
parseJson(response: any) {
|
|
137
147
|
try {
|
|
138
148
|
const concepts_facts = JSON.parse(response.output_text).concepts_facts;
|
|
139
|
-
|
|
149
|
+
if (concepts_facts) {
|
|
150
|
+
return concepts_facts.map((item: any) => {
|
|
151
|
+
return {
|
|
152
|
+
...item,
|
|
153
|
+
reference: restoreQuotesInString(item.reference),
|
|
154
|
+
};
|
|
155
|
+
});
|
|
156
|
+
}
|
|
140
157
|
} catch (e) {
|
|
141
158
|
throw new ParsingError(
|
|
142
159
|
"Something went wrong in parsing the json",
|
|
@@ -4,6 +4,10 @@ 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";
|
|
7
|
+
import {
|
|
8
|
+
restoreQuotesInObject,
|
|
9
|
+
restoreQuotesInString,
|
|
10
|
+
} from "../utils/sanitize_strings";
|
|
7
11
|
|
|
8
12
|
export class GenerateTypology {
|
|
9
13
|
public openAiService: OpenAiService;
|
|
@@ -97,6 +101,12 @@ export class GenerateTypology {
|
|
|
97
101
|
});
|
|
98
102
|
return;
|
|
99
103
|
}
|
|
104
|
+
|
|
105
|
+
// Restore quotes in the response (works without original mapping)
|
|
106
|
+
// if (openAiResponse.output) {
|
|
107
|
+
// openAiResponse.output = restoreQuotesInObject(openAiResponse.output);
|
|
108
|
+
// }
|
|
109
|
+
|
|
100
110
|
openAiResponse["request_type"] = {
|
|
101
111
|
type: "breadth",
|
|
102
112
|
n: 1,
|
|
@@ -158,6 +168,19 @@ export class GenerateTypology {
|
|
|
158
168
|
parseJson(response: any) {
|
|
159
169
|
try {
|
|
160
170
|
const generatedContent = JSON.parse(response.output_text);
|
|
171
|
+
const summaryCards = generatedContent?.summary_cards ?? [];
|
|
172
|
+
if (summaryCards) {
|
|
173
|
+
const remappedSummaryCards = summaryCards.map((item: any) => {
|
|
174
|
+
return {
|
|
175
|
+
...item,
|
|
176
|
+
reference: restoreQuotesInString(item.reference),
|
|
177
|
+
};
|
|
178
|
+
});
|
|
179
|
+
return {
|
|
180
|
+
...generatedContent,
|
|
181
|
+
summary_cards: remappedSummaryCards,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
161
184
|
return generatedContent;
|
|
162
185
|
} catch (e) {
|
|
163
186
|
throw new ParsingError(
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility for restoring quotes in OpenAI responses across distributed Lambda functions
|
|
3
|
+
* This works without requiring original context from the API call Lambda
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { restoreQuotesInObject } from "./sanitize_strings";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Restores quotes in any OpenAI response structure
|
|
10
|
+
* Can be used in a parsing Lambda that receives the response from an API call Lambda
|
|
11
|
+
* @param openAiResponse - The complete OpenAI response object
|
|
12
|
+
* @returns Response with quotes restored in all string fields
|
|
13
|
+
*/
|
|
14
|
+
export function restoreQuotesInOpenAiResponse(openAiResponse: any): any {
|
|
15
|
+
if (!openAiResponse) {
|
|
16
|
+
return openAiResponse;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Create a deep copy to avoid mutating the original
|
|
20
|
+
const restoredResponse = JSON.parse(JSON.stringify(openAiResponse));
|
|
21
|
+
|
|
22
|
+
// Restore quotes in the main output/content
|
|
23
|
+
if (restoredResponse.output) {
|
|
24
|
+
restoredResponse.output = restoreQuotesInObject(restoredResponse.output);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Handle different response formats
|
|
28
|
+
if (
|
|
29
|
+
restoredResponse.choices &&
|
|
30
|
+
restoredResponse.choices[0]?.message?.content
|
|
31
|
+
) {
|
|
32
|
+
try {
|
|
33
|
+
const content = JSON.parse(restoredResponse.choices[0].message.content);
|
|
34
|
+
restoredResponse.choices[0].message.content = JSON.stringify(
|
|
35
|
+
restoreQuotesInObject(content)
|
|
36
|
+
);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
// If content is not JSON, restore quotes directly
|
|
39
|
+
restoredResponse.choices[0].message.content = restoreQuotesInObject(
|
|
40
|
+
restoredResponse.choices[0].message.content
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Handle any other potential content fields
|
|
46
|
+
if (restoredResponse.content) {
|
|
47
|
+
restoredResponse.content = restoreQuotesInObject(restoredResponse.content);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (restoredResponse.generated_content) {
|
|
51
|
+
restoredResponse.generated_content = restoreQuotesInObject(
|
|
52
|
+
restoredResponse.generated_content
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return restoredResponse;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Restores quotes in a parsed response object (after JSON parsing)
|
|
61
|
+
* Use this when you have already parsed the OpenAI response JSON
|
|
62
|
+
* @param parsedResponse - The parsed response object
|
|
63
|
+
* @returns Response with quotes restored
|
|
64
|
+
*/
|
|
65
|
+
export function restoreQuotesInParsedResponse(parsedResponse: any): any {
|
|
66
|
+
return restoreQuotesInObject(parsedResponse);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Example usage in a parsing Lambda function:
|
|
71
|
+
*
|
|
72
|
+
* // Receiving response from API call Lambda
|
|
73
|
+
* const openAiResponse = event.openAiResponse;
|
|
74
|
+
*
|
|
75
|
+
* // Restore quotes without needing original mapping
|
|
76
|
+
* const restoredResponse = restoreQuotesInOpenAiResponse(openAiResponse);
|
|
77
|
+
*
|
|
78
|
+
* // Now process the response with original quotes restored
|
|
79
|
+
* const processedData = processResponse(restoredResponse);
|
|
80
|
+
*/
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for sanitizing strings for OpenAI structured outputs
|
|
3
|
+
* and restoring them back to their original form without requiring original mapping
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Use a unique, reversible encoding for quotes
|
|
7
|
+
const QUOTE_PLACEHOLDER = "___QUOTE___";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Sanitizes an array of strings by replacing quotes with a safe placeholder
|
|
11
|
+
* This approach is stateless and doesn't require storing mappings
|
|
12
|
+
* @param strings - Array of strings to sanitize
|
|
13
|
+
* @returns Array of sanitized strings
|
|
14
|
+
*/
|
|
15
|
+
export function sanitizeStringsForSchema(strings: string[]): string[] {
|
|
16
|
+
return strings.map((str) => str.replace(/"/g, QUOTE_PLACEHOLDER));
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Restores quotes in a string by replacing placeholders with actual quotes
|
|
21
|
+
* This works without needing the original mapping
|
|
22
|
+
* @param sanitizedString - String with quote placeholders
|
|
23
|
+
* @returns Original string with quotes restored
|
|
24
|
+
*/
|
|
25
|
+
export function restoreQuotesInString(sanitizedString: string): string {
|
|
26
|
+
return sanitizedString.replace(new RegExp(QUOTE_PLACEHOLDER, "g"), '"');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Recursively restores quotes in an object's string values
|
|
31
|
+
* This works across Lambda functions without requiring original context
|
|
32
|
+
* @param obj - Object to process
|
|
33
|
+
* @returns Object with quotes restored
|
|
34
|
+
*/
|
|
35
|
+
export function restoreQuotesInObject(obj: any): any {
|
|
36
|
+
if (typeof obj === "string") {
|
|
37
|
+
return restoreQuotesInString(obj);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (Array.isArray(obj)) {
|
|
41
|
+
return obj.map((item) => restoreQuotesInObject(item));
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (obj && typeof obj === "object") {
|
|
45
|
+
const result: any = {};
|
|
46
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
47
|
+
result[key] = restoreQuotesInObject(value);
|
|
48
|
+
}
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return obj;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Legacy function signature for backward compatibility
|
|
57
|
+
* Now ignores the originalMapping parameter since it's not needed
|
|
58
|
+
* @deprecated Use restoreQuotesInObject(obj) instead
|
|
59
|
+
*/
|
|
60
|
+
export function restoreQuotesInObjectLegacy(
|
|
61
|
+
obj: any,
|
|
62
|
+
originalMapping?: Map<string, string>
|
|
63
|
+
): any {
|
|
64
|
+
return restoreQuotesInObject(obj);
|
|
65
|
+
}
|