only_ever_generator 8.6.2 → 8.6.4
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 +1 -1
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +3 -3
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/constants/default_generation_variables.d.ts +1 -1
- package/dist/constants/default_generation_variables.d.ts.map +1 -1
- package/dist/constants/default_generation_variables.js +100 -4
- package/dist/constants/default_generation_variables.js.map +1 -1
- package/dist/helper/openai_helper.d.ts.map +1 -1
- package/dist/helper/openai_helper.js +1 -0
- package/dist/helper/openai_helper.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +75 -60
- package/dist/index.js.map +1 -1
- package/dist/logger.d.ts +1 -0
- package/dist/logger.d.ts.map +1 -1
- package/dist/logger.js.map +1 -1
- package/dist/services/get_prompts.d.ts +0 -5
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +1 -99
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/types/base_param_type.d.ts +0 -1
- package/dist/types/base_param_type.d.ts.map +1 -1
- package/dist/typology_gen/generate_assessment.d.ts.map +1 -1
- package/dist/typology_gen/generate_assessment.js +17 -3
- package/dist/typology_gen/generate_assessment.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +17 -3
- 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 +17 -3
- 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 +17 -3
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +1 -1
- package/src/bootstrap/app.ts +4 -5
- package/src/constants/default_generation_variables.ts +100 -3
- package/src/helper/openai_helper.ts +1 -0
- package/src/index.ts +74 -62
- package/src/logger.ts +1 -0
- package/src/services/get_prompts.ts +0 -101
- package/src/types/base_param_type.ts +0 -1
- package/src/typology_gen/generate_assessment.ts +17 -3
- package/src/typology_gen/generate_concept_facts.ts +17 -3
- package/src/typology_gen/generate_typology.ts +16 -2
- package/src/typology_gen/summarize.ts +17 -3
package/src/index.ts
CHANGED
|
@@ -1,69 +1,81 @@
|
|
|
1
|
-
|
|
1
|
+
import express from "express";
|
|
2
2
|
import { OnlyEverGenerator } from "./bootstrap/app";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { ObjectId } from "mongodb";
|
|
4
|
+
import { setUpMongoClient } from "./helper/mongo_helper";
|
|
5
|
+
import { GenerationVariablesSchema } from "./types/generation_variables_schema";
|
|
6
|
+
import { testGenerationVariables } from "./constants/default_generation_variables";
|
|
5
7
|
|
|
6
8
|
export { OnlyEverGenerator };
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
const app = express();
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
// const source = new ObjectId("68b114d4c849a25097ec5021");
|
|
12
|
-
// const mongo = await setUpMongoClient();
|
|
13
|
-
// const openAiKey = process.env.OPEN_AI_KEY;
|
|
14
|
-
// const document = await mongo.collection("_source").findOne({ _id: source });
|
|
15
|
-
// if (!document) {
|
|
16
|
-
// return res.status(404).json({ error: "Source not found" });
|
|
17
|
-
// }
|
|
12
|
+
app.get("/generate", async (req, res) => {
|
|
18
13
|
|
|
19
|
-
// const promptIdForClassify =
|
|
20
|
-
// "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594";
|
|
21
|
-
// const promptIdForConceptFacts =
|
|
22
|
-
// "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8";
|
|
23
|
-
// const promptIdForCardGeneration =
|
|
24
|
-
// "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6";
|
|
25
|
-
// const promptIdForMissingConceptsFacts =
|
|
26
|
-
// "pmpt_687ab50298dc8194b214804999d23df10e03b855371691f9";
|
|
27
|
-
// const promptIdForSummarize =
|
|
28
|
-
// "pmpt_6902c30a973481968395935cc6dfa78605f50d2b01d4afbd";
|
|
29
|
-
// // const generationCurriculum = process.env.GENERATION_CURRICULUM;
|
|
30
|
-
// const n = process.env.N;
|
|
31
|
-
// const generationContent = {
|
|
32
|
-
// content: {
|
|
33
|
-
// source_id: document.source_id,
|
|
34
|
-
// title: document.title,
|
|
35
|
-
// headings: document.headings,
|
|
36
|
-
// content: document.content,
|
|
37
|
-
// fields: [],
|
|
38
|
-
// taxonomy: {
|
|
39
|
-
// concepts_facts: document.concepts_facts ?? [],
|
|
40
|
-
// fields: document.fields ?? [],
|
|
41
|
-
// summary_cards: document.summary_cards ?? [],
|
|
42
|
-
// learn_value: document.learn_value,
|
|
43
|
-
// },
|
|
44
|
-
// type: document.type,
|
|
45
|
-
// },
|
|
46
|
-
// };
|
|
47
|
-
// const generationVariablesSchema: GenerationVariablesSchema =
|
|
48
|
-
// defaultGenerationVariables;
|
|
49
|
-
// const generator = new OnlyEverGenerator(
|
|
50
|
-
// openAiKey ?? "",
|
|
51
|
-
// "gpt-4o-mini",
|
|
52
|
-
// generationContent,
|
|
53
|
-
// generationVariablesSchema,
|
|
54
|
-
// false,
|
|
55
|
-
// 1
|
|
56
|
-
// );
|
|
57
|
-
// const response = await generator.generate(true, true, [
|
|
58
|
-
// "cloze",
|
|
59
|
-
// "mcq",
|
|
60
|
-
// "flash",
|
|
61
|
-
// "match",
|
|
62
|
-
// ]);
|
|
63
|
-
// console.log("Close");
|
|
64
|
-
// res.json(response);
|
|
65
|
-
// });
|
|
66
14
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Set up the MongoDB and get the OpenAI key
|
|
17
|
+
*/
|
|
18
|
+
const mongo = await setUpMongoClient();
|
|
19
|
+
const openAiKey = process.env.OPEN_AI_KEY;
|
|
20
|
+
if (!openAiKey) {
|
|
21
|
+
return res.status(500).json({ error: "Missing OpenAI API key" });
|
|
22
|
+
}
|
|
23
|
+
const model = process.env.OPEN_AI_MODEL;
|
|
24
|
+
if (!model) {
|
|
25
|
+
return res.status(500).json({ error: "Missing OpenAI model" });
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Get the source from the database
|
|
30
|
+
*/
|
|
31
|
+
const source = new ObjectId("68b114d4c849a25097ec5021");
|
|
32
|
+
const document = await mongo.collection("_source").findOne({ _id: source });
|
|
33
|
+
if (!document) {
|
|
34
|
+
return res.status(404).json({ error: "Source not found" });
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Set up the generation configuration
|
|
39
|
+
*/
|
|
40
|
+
const generate_typology = true;
|
|
41
|
+
const generate_card = true;
|
|
42
|
+
const generate_assessment = false;
|
|
43
|
+
const card_generation_types = ["cloze", "mcq", "flash", "match"];
|
|
44
|
+
|
|
45
|
+
//ignoring curriculum for now
|
|
46
|
+
const generationCurriculum = false;
|
|
47
|
+
const generationContent = {
|
|
48
|
+
content: {
|
|
49
|
+
source_id: document.source_id,
|
|
50
|
+
title: document.title,
|
|
51
|
+
headings: document.headings,
|
|
52
|
+
content: document.content,
|
|
53
|
+
taxonomy: {
|
|
54
|
+
concepts_facts: document.concepts_facts ?? [],
|
|
55
|
+
fields: document.fields ?? [],
|
|
56
|
+
summary_cards: document.summary_cards ?? [],
|
|
57
|
+
learn_value: document.learn_value,
|
|
58
|
+
},
|
|
59
|
+
type: document.type,
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Set up the generation variables schema
|
|
64
|
+
*/
|
|
65
|
+
const generationVariablesSchema: GenerationVariablesSchema =
|
|
66
|
+
testGenerationVariables;
|
|
67
|
+
const generator = new OnlyEverGenerator(
|
|
68
|
+
openAiKey,
|
|
69
|
+
model,
|
|
70
|
+
generationContent,
|
|
71
|
+
generationVariablesSchema,
|
|
72
|
+
generationCurriculum,
|
|
73
|
+
);
|
|
74
|
+
const response = await generator.generate(generate_typology, generate_card, generate_assessment, card_generation_types);
|
|
75
|
+
console.log("Completed generation");
|
|
76
|
+
res.json(response);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
app.listen(3000, () => {
|
|
80
|
+
console.log("Server is running on port 3000");
|
|
81
|
+
});
|
package/src/logger.ts
CHANGED
|
@@ -9,105 +9,4 @@ export const promptIds = {
|
|
|
9
9
|
assessment: "pmpt_69346ba0e8d88194b4e999d561510f99086d01dad36145c5",
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
const cardGenInstructionsDocs = {
|
|
13
|
-
cloze: "6780d21318f81be17e39f5c1",
|
|
14
|
-
flash: "6780d21318f81be17e39f5d2",
|
|
15
|
-
match: "6780d21318f81be17e39f5d3",
|
|
16
|
-
mcq: "6780d21318f81be17e39f5d4",
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const cardGenExamplesDocs = {
|
|
20
|
-
cloze: "688af4e5299b7c2c08a52fbe",
|
|
21
|
-
flash: "688af4e5299b7c2c08a52fcd",
|
|
22
|
-
match: "688af4e5299b7c2c08a52fce",
|
|
23
|
-
mcq: "688af4e5299b7c2c08a52fde",
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const bloomInstructionsDocs = {
|
|
27
|
-
bloom_1: "6780d21318f81be17e39f5b5",
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export const getPrompts = async (
|
|
31
|
-
sourceType: string,
|
|
32
|
-
cardGenerationType: string[]
|
|
33
|
-
) => {
|
|
34
|
-
// const typologyDocs = JSON.parse(baseConfig.typologyPrompts);
|
|
35
|
-
// const cardGenerationDocs = JSON.parse(baseConfig.cardGenerationPrompts);
|
|
36
|
-
// const videoTypologyDocs = JSON.parse(baseConfig.videoTypologyPrompts);
|
|
37
|
-
// const typologyObjectIds = Object.values(typologyDocs).map((e: any) =>
|
|
38
|
-
// ObjectId.createFromHexString(e.toString())
|
|
39
|
-
// );
|
|
40
|
-
// const cardGenObjectIds = Object.values(cardGenDocs).map((e: any) =>
|
|
41
|
-
// ObjectId.createFromHexString(e)
|
|
42
|
-
// );
|
|
43
|
-
// const typologyVideoObjectIds = Object.values(videoTypologyDocs).map(
|
|
44
|
-
// (e: any) => ObjectId.createFromHexString(e)
|
|
45
|
-
// );
|
|
46
12
|
|
|
47
|
-
// Filter card generation instructions and examples based on cardGenerationType array
|
|
48
|
-
const filteredCardGenInstructions: Record<string, string> = {};
|
|
49
|
-
const filteredCardGenExamples: Record<string, string> = {};
|
|
50
|
-
|
|
51
|
-
cardGenerationType.forEach((type) => {
|
|
52
|
-
if (cardGenInstructionsDocs[type as keyof typeof cardGenInstructionsDocs]) {
|
|
53
|
-
filteredCardGenInstructions[type] =
|
|
54
|
-
cardGenInstructionsDocs[type as keyof typeof cardGenInstructionsDocs];
|
|
55
|
-
}
|
|
56
|
-
if (cardGenExamplesDocs[type as keyof typeof cardGenExamplesDocs]) {
|
|
57
|
-
filteredCardGenExamples[type] =
|
|
58
|
-
cardGenExamplesDocs[type as keyof typeof cardGenExamplesDocs];
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const cardGenInstructionsObjectIds = Object.values(
|
|
63
|
-
filteredCardGenInstructions
|
|
64
|
-
).map((e: any) => ObjectId.createFromHexString(e));
|
|
65
|
-
const cardGenExamplesObjectIds = Object.values(filteredCardGenExamples).map(
|
|
66
|
-
(e: any) => ObjectId.createFromHexString(e)
|
|
67
|
-
);
|
|
68
|
-
const bloomInstructionsObjectIds = Object.values(bloomInstructionsDocs).map(
|
|
69
|
-
(e: any) => ObjectId.createFromHexString(e)
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
const cardInstructions = await getPromptString(cardGenInstructionsObjectIds);
|
|
73
|
-
const cardExamples = await getPromptString(cardGenExamplesObjectIds);
|
|
74
|
-
const bloomInstructions = await getPromptString(bloomInstructionsObjectIds);
|
|
75
|
-
return {
|
|
76
|
-
card_instructions: cardInstructions,
|
|
77
|
-
card_examples: cardExamples,
|
|
78
|
-
bloom_instructions: bloomInstructions,
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
async function getPromptString(promptIds: ObjectId[]) {
|
|
82
|
-
const database = await setUpMongoClient();
|
|
83
|
-
let result = await database
|
|
84
|
-
.collection("_prompts")
|
|
85
|
-
.aggregate([
|
|
86
|
-
{
|
|
87
|
-
$match: {
|
|
88
|
-
_id: { $in: promptIds },
|
|
89
|
-
},
|
|
90
|
-
},
|
|
91
|
-
{
|
|
92
|
-
$group: {
|
|
93
|
-
_id: null,
|
|
94
|
-
allContent: { $push: "$prompt" },
|
|
95
|
-
},
|
|
96
|
-
},
|
|
97
|
-
{
|
|
98
|
-
/// concat each element in above created `allContent temp field`, and update that to "concatenatedContent"(temp field)
|
|
99
|
-
$project: {
|
|
100
|
-
concatenatedContent: {
|
|
101
|
-
$reduce: {
|
|
102
|
-
input: "$allContent",
|
|
103
|
-
initialValue: "",
|
|
104
|
-
in: { $concat: ["$$value", "$$this"] },
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
])
|
|
110
|
-
.toArray();
|
|
111
|
-
return result.length > 0 ? result[0].concatenatedContent : "";
|
|
112
|
-
}
|
|
113
|
-
};
|
|
@@ -139,11 +139,25 @@ export class GenerateAssessment {
|
|
|
139
139
|
assessment_questions: assessment_questions,
|
|
140
140
|
metadata: response.metadata,
|
|
141
141
|
};
|
|
142
|
-
} catch (error) {
|
|
143
|
-
|
|
142
|
+
} catch (error: any) {
|
|
143
|
+
const serializedError = {
|
|
144
|
+
message: error?.message,
|
|
145
|
+
stack: error?.stack,
|
|
146
|
+
code: error?.code,
|
|
147
|
+
status: error?.status,
|
|
148
|
+
cause: error?.cause ? {
|
|
149
|
+
message: error.cause?.message,
|
|
150
|
+
code: error.cause?.code,
|
|
151
|
+
errno: error.cause?.errno,
|
|
152
|
+
syscall: error.cause?.syscall,
|
|
153
|
+
} : undefined,
|
|
154
|
+
name: error?.name,
|
|
155
|
+
}
|
|
156
|
+
console.log(serializedError);
|
|
144
157
|
await log_error({
|
|
145
158
|
flow: "assessment_generation",
|
|
146
|
-
data:
|
|
159
|
+
data: serializedError,
|
|
160
|
+
unserialized_error: error,
|
|
147
161
|
timestamp: new Date(),
|
|
148
162
|
error: "error_in_assessment_generation",
|
|
149
163
|
source_id: this.sourceId,
|
|
@@ -130,13 +130,27 @@ export class GenerateConceptFacts {
|
|
|
130
130
|
concepts_facts: concepts_facts,
|
|
131
131
|
metadata: openAiResponse.metadata,
|
|
132
132
|
};
|
|
133
|
-
} catch (error) {
|
|
134
|
-
|
|
133
|
+
} catch (error: any) {
|
|
134
|
+
const serializedError = {
|
|
135
|
+
message: error?.message,
|
|
136
|
+
stack: error?.stack,
|
|
137
|
+
code: error?.code,
|
|
138
|
+
status: error?.status,
|
|
139
|
+
cause: error?.cause ? {
|
|
140
|
+
message: error.cause?.message,
|
|
141
|
+
code: error.cause?.code,
|
|
142
|
+
errno: error.cause?.errno,
|
|
143
|
+
syscall: error.cause?.syscall,
|
|
144
|
+
} : undefined,
|
|
145
|
+
name: error?.name,
|
|
146
|
+
}
|
|
147
|
+
console.log(serializedError);
|
|
135
148
|
await log_error({
|
|
136
149
|
flow: this.generationCurriculum
|
|
137
150
|
? "curriculum_manual_generation"
|
|
138
151
|
: "manual_generation",
|
|
139
|
-
data:
|
|
152
|
+
data: serializedError,
|
|
153
|
+
unserialized_error: error,
|
|
140
154
|
timestamp: new Date(),
|
|
141
155
|
error: "error_in_concept_facts_generation",
|
|
142
156
|
source_id: this.sourceId,
|
|
@@ -113,12 +113,26 @@ export class GenerateTypology {
|
|
|
113
113
|
return openAiResponse;
|
|
114
114
|
}
|
|
115
115
|
} catch (e: any) {
|
|
116
|
-
|
|
116
|
+
const serializedError = {
|
|
117
|
+
message: e?.message,
|
|
118
|
+
stack: e?.stack,
|
|
119
|
+
code: e?.code,
|
|
120
|
+
status: e?.status,
|
|
121
|
+
cause: e?.cause ? {
|
|
122
|
+
message: e.cause?.message,
|
|
123
|
+
code: e.cause?.code,
|
|
124
|
+
errno: e.cause?.errno,
|
|
125
|
+
syscall: e.cause?.syscall,
|
|
126
|
+
} : undefined,
|
|
127
|
+
name: e?.name,
|
|
128
|
+
}
|
|
129
|
+
console.log(serializedError);
|
|
117
130
|
await log_error({
|
|
118
131
|
flow: this.generationCurriculum
|
|
119
132
|
? "curriculum_manual_generation"
|
|
120
133
|
: "manual_generation",
|
|
121
|
-
data:
|
|
134
|
+
data: serializedError,
|
|
135
|
+
unserialized_error: e,
|
|
122
136
|
timestamp: new Date(),
|
|
123
137
|
error: "error_in_typology_generation",
|
|
124
138
|
source_id: this.sourceId,
|
|
@@ -122,13 +122,27 @@ export class GenerateSummaryCards {
|
|
|
122
122
|
summary_cards: summaryCards,
|
|
123
123
|
metadata: openAiResponse.metadata,
|
|
124
124
|
};
|
|
125
|
-
} catch (error) {
|
|
126
|
-
|
|
125
|
+
} catch (error: any) {
|
|
126
|
+
const serializedError = {
|
|
127
|
+
message: error?.message,
|
|
128
|
+
stack: error?.stack,
|
|
129
|
+
code: error?.code,
|
|
130
|
+
status: error?.status,
|
|
131
|
+
cause: error?.cause ? {
|
|
132
|
+
message: error.cause?.message,
|
|
133
|
+
code: error.cause?.code,
|
|
134
|
+
errno: error.cause?.errno,
|
|
135
|
+
syscall: error.cause?.syscall,
|
|
136
|
+
} : undefined,
|
|
137
|
+
name: error?.name,
|
|
138
|
+
}
|
|
139
|
+
console.log(serializedError);
|
|
127
140
|
await log_error({
|
|
128
141
|
flow: this.generationCurriculum
|
|
129
142
|
? "curriculum_manual_generation"
|
|
130
143
|
: "manual_generation",
|
|
131
|
-
data:
|
|
144
|
+
data: serializedError,
|
|
145
|
+
unserialized_error: error,
|
|
132
146
|
timestamp: new Date(),
|
|
133
147
|
error: "error_in_summary_cards_generation",
|
|
134
148
|
source_id: this.sourceId,
|