only_ever_generator 8.1.4 → 8.1.6
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/helper/get_id_from_title.d.ts +5 -0
- package/dist/helper/get_id_from_title.d.ts.map +1 -0
- package/dist/helper/get_id_from_title.js +45 -0
- package/dist/helper/get_id_from_title.js.map +1 -0
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +13 -29
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +14 -19
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +1 -1
- package/src/helper/get_id_from_title.ts +32 -0
- package/src/typology_gen/generate_typology.ts +16 -39
- package/src/typology_gen/summarize.ts +16 -25
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_id_from_title.d.ts","sourceRoot":"","sources":["../../src/helper/get_id_from_title.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,eAAe,GAAU,QAAQ,MAAM,EAAE;;;IA6BrD,CAAC"}
|
|
@@ -0,0 +1,45 @@
|
|
|
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.getIdsForTitles = void 0;
|
|
13
|
+
const mongo_helper_1 = require("./mongo_helper");
|
|
14
|
+
const getIdsForTitles = (titles) => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
try {
|
|
16
|
+
const collection = mongo_helper_1.database.collection("_source");
|
|
17
|
+
const rows = yield collection
|
|
18
|
+
.find({
|
|
19
|
+
$or: [{ title: { $in: titles } }, { slug: { $in: titles } }],
|
|
20
|
+
})
|
|
21
|
+
.project({ _id: 1, title: 1, slug: 1 })
|
|
22
|
+
.toArray();
|
|
23
|
+
// Create a map of matched titles/slugs to their _ids
|
|
24
|
+
const matchedMap = new Map();
|
|
25
|
+
rows.forEach((row) => {
|
|
26
|
+
if (row.title)
|
|
27
|
+
matchedMap.set(row.title, row._id);
|
|
28
|
+
if (row.slug)
|
|
29
|
+
matchedMap.set(row.slug, row._id);
|
|
30
|
+
});
|
|
31
|
+
// Return result for every title in the input array
|
|
32
|
+
return titles.map((title) => {
|
|
33
|
+
const id = matchedMap.get(title);
|
|
34
|
+
return {
|
|
35
|
+
title,
|
|
36
|
+
id: id ? id.toString() : null,
|
|
37
|
+
};
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
return [];
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
exports.getIdsForTitles = getIdsForTitles;
|
|
45
|
+
//# sourceMappingURL=get_id_from_title.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get_id_from_title.js","sourceRoot":"","sources":["../../src/helper/get_id_from_title.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,iDAA0C;AAEnC,MAAM,eAAe,GAAG,CAAO,MAAgB,EAAE,EAAE;IACxD,IAAI,CAAC;QACH,MAAM,UAAU,GAAG,uBAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;QAClD,MAAM,IAAI,GAAG,MAAM,UAAU;aAC1B,IAAI,CAAC;YACJ,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,CAAC;SAC7D,CAAC;aACD,OAAO,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;aACtC,OAAO,EAAE,CAAC;QAEb,qDAAqD;QACrD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,CAAC,CAAC,GAAQ,EAAE,EAAE;YACxB,IAAI,GAAG,CAAC,KAAK;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;YAClD,IAAI,GAAG,CAAC,IAAI;gBAAE,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;QAEH,mDAAmD;QAEnD,OAAO,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE;YAC1B,MAAM,EAAE,GAAG,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;YACjC,OAAO;gBACL,KAAK;gBACL,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,IAAI;aAC9B,CAAC;QACJ,CAAC,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAA,CAAC;AA7BW,QAAA,eAAe,mBA6B1B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAG5D,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;IA2Fd,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;;;;;;;IAgBxC,SAAS,CAAC,QAAQ,EAAE,GAAG;IAyBvB,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;;;;IAQ3B,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;CAQ/C"}
|
|
@@ -28,44 +28,25 @@ class GenerateTypology {
|
|
|
28
28
|
return __awaiter(this, void 0, void 0, function* () {
|
|
29
29
|
var _a, _b, _c, _d, _e;
|
|
30
30
|
try {
|
|
31
|
-
// const headings =
|
|
32
|
-
// this.type == "video"
|
|
33
|
-
// ? this.content.timecodes || [""]
|
|
34
|
-
// : this.content.h1_headings || [""];
|
|
35
|
-
// Use OpenAI Responses API
|
|
36
|
-
// const classifySummarizeSchema = await buildClassifySummarizeSchema(
|
|
37
|
-
// headings.length > 0 ? headings : [""]
|
|
38
|
-
// );
|
|
39
31
|
const openAIHelper = new openai_helper_1.OpenAIHelper(this.openAiService.api_key);
|
|
40
32
|
const openAiResponse = yield openAIHelper.openAI.responses.create({
|
|
41
33
|
prompt: {
|
|
42
34
|
id: this.promptIdForTypology,
|
|
43
35
|
variables: {
|
|
44
36
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
45
|
-
source_title: this.content.title,
|
|
46
|
-
source_content: JSON.stringify(this.content.content),
|
|
47
|
-
source_headings: JSON.stringify(this.content.h1_headings || []),
|
|
48
37
|
},
|
|
49
|
-
version: "
|
|
38
|
+
version: "66",
|
|
50
39
|
},
|
|
51
40
|
max_output_tokens: 30000,
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
41
|
+
input: [
|
|
42
|
+
{
|
|
43
|
+
role: "user",
|
|
44
|
+
content: [
|
|
45
|
+
{ type: "input_text", text: JSON.stringify(this.content) },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
],
|
|
60
49
|
store: true,
|
|
61
|
-
// text: {
|
|
62
|
-
// format: {
|
|
63
|
-
// type: "json_schema",
|
|
64
|
-
// name: classifySummarizeSchema.name,
|
|
65
|
-
// strict: true,
|
|
66
|
-
// schema: classifySummarizeSchema.schema,
|
|
67
|
-
// },
|
|
68
|
-
// },
|
|
69
50
|
});
|
|
70
51
|
console.log(openAiResponse);
|
|
71
52
|
if (!openAiResponse) {
|
|
@@ -100,7 +81,10 @@ class GenerateTypology {
|
|
|
100
81
|
},
|
|
101
82
|
req_tokens: (_c = (_b = openAiResponse.usage) === null || _b === void 0 ? void 0 : _b.input_tokens) !== null && _c !== void 0 ? _c : 0,
|
|
102
83
|
res_tokens: (_e = (_d = openAiResponse.usage) === null || _d === void 0 ? void 0 : _d.output_tokens) !== null && _e !== void 0 ? _e : 0,
|
|
103
|
-
prompt:
|
|
84
|
+
prompt: {
|
|
85
|
+
id: openAiResponse.prompt.id,
|
|
86
|
+
version: openAiResponse.prompt.version,
|
|
87
|
+
},
|
|
104
88
|
// prompt_tokens_details: openAiResponse.usage?.,
|
|
105
89
|
model: openAiResponse.model,
|
|
106
90
|
usage: openAiResponse.usage,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;AACvD,sCAAoD;AAEpD,gEAAkE;AAElE,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,QAAQ,EAAE,CAAC,WAAW,EAAE,CAC9B,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,YAAY,GAAG,IAAI,4BAAY,CAAC,IAAI,CAA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,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;AAzLD,4CAyLC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"summarize.d.ts","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAK5D,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;;;;IAmGd,SAAS,CAAC,QAAQ,EAAE,GAAG;CAkBxB"}
|
|
@@ -36,27 +36,22 @@ class GenerateSummaryCards {
|
|
|
36
36
|
const openAiResponse = yield this.openAIHelper.openAI.responses.create({
|
|
37
37
|
prompt: {
|
|
38
38
|
id: this.promptIdForSummaryCards,
|
|
39
|
-
// version: "35",
|
|
40
39
|
variables: {
|
|
41
40
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
42
|
-
source_title: this.content.title,
|
|
43
|
-
source_content: JSON.stringify(this.content.content),
|
|
44
|
-
source_headings: JSON.stringify(this.content.h1_headings || []),
|
|
45
41
|
},
|
|
46
42
|
},
|
|
47
43
|
max_output_tokens: 30000,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// input: JSON.stringify(this.content),
|
|
44
|
+
input: [
|
|
45
|
+
{
|
|
46
|
+
role: "user",
|
|
47
|
+
content: [
|
|
48
|
+
{
|
|
49
|
+
type: "input_text",
|
|
50
|
+
text: JSON.stringify(this.content),
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
],
|
|
60
55
|
store: true,
|
|
61
56
|
text: {
|
|
62
57
|
format: {
|
|
@@ -75,7 +70,7 @@ class GenerateSummaryCards {
|
|
|
75
70
|
timestamp: new Date(),
|
|
76
71
|
source_id: this.sourceId,
|
|
77
72
|
type: {
|
|
78
|
-
request_type: "
|
|
73
|
+
request_type: "summary_cards",
|
|
79
74
|
n: 1,
|
|
80
75
|
},
|
|
81
76
|
});
|
|
@@ -113,10 +108,10 @@ class GenerateSummaryCards {
|
|
|
113
108
|
: "manual_generation",
|
|
114
109
|
data: error,
|
|
115
110
|
timestamp: new Date(),
|
|
116
|
-
error: "
|
|
111
|
+
error: "error_in_summary_cards_generation",
|
|
117
112
|
source_id: this.sourceId,
|
|
118
113
|
type: {
|
|
119
|
-
request_type: "
|
|
114
|
+
request_type: "summary_cards",
|
|
120
115
|
n: 1,
|
|
121
116
|
},
|
|
122
117
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"summarize.js","sourceRoot":"","sources":["../../src/typology_gen/summarize.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,2DAAuD;AAEvD,sCAAoD;AACpD,gEAAkE;AAClE,uFAAkF;AAElF,MAAa,oBAAoB;IAa/B,YACE,aAA4B,EAC5B,QAAgB,EAChB,OAKC,EACD,IAAY,EACZ,uBAA+B,EAC/B,oBAA6B;QAbxB,SAAI,GAAW,EAAE,CAAC;QAevB,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,uBAAuB,GAAG,uBAAuB,CAAC;QACvD,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACz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,IAAI,CAAC,oBAAoB;wBAC7B,CAAC,CAAC,8BAA8B;wBAChC,CAAC,CAAC,mBAAmB;oBACvB,IAAI,EAAE,KAAK;oBACX,SAAS,EAAE,IAAI,IAAI,EAAE;oBACrB,KAAK,EAAE,mCAAmC;oBAC1C,SAAS,EAAE,IAAI,CAAC,QAAQ;oBACxB,IAAI,EAAE;wBACJ,YAAY,EAAE,eAAe;wBAC7B,CAAC,EAAE,CAAC;qBACL;iBACF,CAAC,CAAC;gBACH,OAAO;YACT,CAAC;QACH,CAAC;KAAA;IAED,SAAS,CAAC,QAAa;QACrB,IAAI,CAAC;YACH,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC;YACpE,IAAI,YAAY,EAAE,CAAC;gBACjB,OAAO,YAAY,CAAC,GAAG,CAAC,CAAC,IAAS,EAAE,EAAE;oBACpC,uCACK,IAAI,KACP,SAAS,EAAE,IAAA,wCAAqB,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;AAxJD,oDAwJC"}
|
package/package.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { database } from "./mongo_helper";
|
|
2
|
+
|
|
3
|
+
export const getIdsForTitles = async (titles: string[]) => {
|
|
4
|
+
try {
|
|
5
|
+
const collection = database.collection("_source");
|
|
6
|
+
const rows = await collection
|
|
7
|
+
.find({
|
|
8
|
+
$or: [{ title: { $in: titles } }, { slug: { $in: titles } }],
|
|
9
|
+
})
|
|
10
|
+
.project({ _id: 1, title: 1, slug: 1 })
|
|
11
|
+
.toArray();
|
|
12
|
+
|
|
13
|
+
// Create a map of matched titles/slugs to their _ids
|
|
14
|
+
const matchedMap = new Map();
|
|
15
|
+
rows.forEach((row: any) => {
|
|
16
|
+
if (row.title) matchedMap.set(row.title, row._id);
|
|
17
|
+
if (row.slug) matchedMap.set(row.slug, row._id);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Return result for every title in the input array
|
|
21
|
+
|
|
22
|
+
return titles.map((title) => {
|
|
23
|
+
const id = matchedMap.get(title);
|
|
24
|
+
return {
|
|
25
|
+
title,
|
|
26
|
+
id: id ? id.toString() : null,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
} catch (error) {
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
1
|
+
import { OpenAIHelper } from "../helper/openai_helper";
|
|
2
|
+
import { log_error, ParsingError } from "../logger";
|
|
4
3
|
import { OpenAiService } from "../services/open_ai_service";
|
|
5
|
-
import {
|
|
6
|
-
import { buildClassifySummarizeSchema } from "../helper/schema_helper/build_classify_summarize_schema";
|
|
7
|
-
import {
|
|
8
|
-
restoreQuotesInObject,
|
|
9
|
-
restoreQuotesInString,
|
|
10
|
-
} from "../utils/sanitize_strings";
|
|
4
|
+
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
11
5
|
|
|
12
6
|
export class GenerateTypology {
|
|
13
7
|
public openAiService: OpenAiService;
|
|
@@ -48,45 +42,25 @@ export class GenerateTypology {
|
|
|
48
42
|
}
|
|
49
43
|
async generate() {
|
|
50
44
|
try {
|
|
51
|
-
// const headings =
|
|
52
|
-
// this.type == "video"
|
|
53
|
-
// ? this.content.timecodes || [""]
|
|
54
|
-
// : this.content.h1_headings || [""];
|
|
55
|
-
// Use OpenAI Responses API
|
|
56
|
-
// const classifySummarizeSchema = await buildClassifySummarizeSchema(
|
|
57
|
-
// headings.length > 0 ? headings : [""]
|
|
58
|
-
// );
|
|
59
45
|
const openAIHelper = new OpenAIHelper(this.openAiService.api_key);
|
|
60
|
-
|
|
61
46
|
const openAiResponse: any = await openAIHelper.openAI.responses.create({
|
|
62
47
|
prompt: {
|
|
63
48
|
id: this.promptIdForTypology,
|
|
64
49
|
variables: {
|
|
65
50
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
66
|
-
source_title: this.content.title,
|
|
67
|
-
source_content: JSON.stringify(this.content.content),
|
|
68
|
-
source_headings: JSON.stringify(this.content.h1_headings || []),
|
|
69
51
|
},
|
|
70
|
-
version: "
|
|
52
|
+
version: "66",
|
|
71
53
|
},
|
|
72
54
|
max_output_tokens: 30000,
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
55
|
+
input: [
|
|
56
|
+
{
|
|
57
|
+
role: "user",
|
|
58
|
+
content: [
|
|
59
|
+
{ type: "input_text", text: JSON.stringify(this.content) },
|
|
60
|
+
],
|
|
61
|
+
},
|
|
62
|
+
],
|
|
81
63
|
store: true,
|
|
82
|
-
// text: {
|
|
83
|
-
// format: {
|
|
84
|
-
// type: "json_schema",
|
|
85
|
-
// name: classifySummarizeSchema.name,
|
|
86
|
-
// strict: true,
|
|
87
|
-
// schema: classifySummarizeSchema.schema,
|
|
88
|
-
// },
|
|
89
|
-
// },
|
|
90
64
|
});
|
|
91
65
|
console.log(openAiResponse);
|
|
92
66
|
if (!openAiResponse) {
|
|
@@ -123,7 +97,10 @@ export class GenerateTypology {
|
|
|
123
97
|
},
|
|
124
98
|
req_tokens: openAiResponse.usage?.input_tokens ?? 0,
|
|
125
99
|
res_tokens: openAiResponse.usage?.output_tokens ?? 0,
|
|
126
|
-
prompt:
|
|
100
|
+
prompt: {
|
|
101
|
+
id: openAiResponse.prompt.id,
|
|
102
|
+
version: openAiResponse.prompt.version,
|
|
103
|
+
},
|
|
127
104
|
// prompt_tokens_details: openAiResponse.usage?.,
|
|
128
105
|
model: openAiResponse.model,
|
|
129
106
|
usage: openAiResponse.usage,
|
|
@@ -1,11 +1,7 @@
|
|
|
1
|
-
import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_facts_schema";
|
|
2
1
|
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
2
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
restoreQuotesInObject,
|
|
7
|
-
restoreQuotesInString,
|
|
8
|
-
} from "../utils/sanitize_strings";
|
|
3
|
+
import { log_error, ParsingError } from "../logger";
|
|
4
|
+
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
9
5
|
import { buildSummarySchema } from "../helper/schema_helper/build_summary_schema";
|
|
10
6
|
|
|
11
7
|
export class GenerateSummaryCards {
|
|
@@ -58,27 +54,22 @@ export class GenerateSummaryCards {
|
|
|
58
54
|
await this.openAIHelper.openAI.responses.create({
|
|
59
55
|
prompt: {
|
|
60
56
|
id: this.promptIdForSummaryCards,
|
|
61
|
-
// version: "35",
|
|
62
57
|
variables: {
|
|
63
58
|
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
64
|
-
source_title: this.content.title,
|
|
65
|
-
source_content: JSON.stringify(this.content.content),
|
|
66
|
-
source_headings: JSON.stringify(this.content.h1_headings || []),
|
|
67
59
|
},
|
|
68
60
|
},
|
|
69
61
|
max_output_tokens: 30000,
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
// input: JSON.stringify(this.content),
|
|
62
|
+
input: [
|
|
63
|
+
{
|
|
64
|
+
role: "user",
|
|
65
|
+
content: [
|
|
66
|
+
{
|
|
67
|
+
type: "input_text",
|
|
68
|
+
text: JSON.stringify(this.content),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
},
|
|
72
|
+
],
|
|
82
73
|
store: true,
|
|
83
74
|
text: {
|
|
84
75
|
format: {
|
|
@@ -97,7 +88,7 @@ export class GenerateSummaryCards {
|
|
|
97
88
|
timestamp: new Date(),
|
|
98
89
|
source_id: this.sourceId,
|
|
99
90
|
type: {
|
|
100
|
-
request_type: "
|
|
91
|
+
request_type: "summary_cards",
|
|
101
92
|
n: 1,
|
|
102
93
|
},
|
|
103
94
|
});
|
|
@@ -136,10 +127,10 @@ export class GenerateSummaryCards {
|
|
|
136
127
|
: "manual_generation",
|
|
137
128
|
data: error,
|
|
138
129
|
timestamp: new Date(),
|
|
139
|
-
error: "
|
|
130
|
+
error: "error_in_summary_cards_generation",
|
|
140
131
|
source_id: this.sourceId,
|
|
141
132
|
type: {
|
|
142
|
-
request_type: "
|
|
133
|
+
request_type: "summary_cards",
|
|
143
134
|
n: 1,
|
|
144
135
|
},
|
|
145
136
|
});
|