only_ever_generator 8.0.0 → 8.0.2
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/MODULAR_REFACTORING_SUMMARY.md +217 -0
- package/README.md +608 -0
- package/dist/card_gen/generate_cards.d.ts +1 -1
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +3 -4
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/configs/card_generator_config.d.ts +41 -0
- package/dist/configs/card_generator_config.d.ts.map +1 -0
- package/dist/configs/card_generator_config.js +17 -0
- package/dist/configs/card_generator_config.js.map +1 -0
- package/dist/configs/concept_facts_generator_config.d.ts +28 -0
- package/dist/configs/concept_facts_generator_config.d.ts.map +1 -0
- package/dist/configs/concept_facts_generator_config.js +12 -0
- package/dist/configs/concept_facts_generator_config.js.map +1 -0
- package/dist/configs/consolidator_config.d.ts +20 -0
- package/dist/configs/consolidator_config.d.ts.map +1 -0
- package/dist/configs/consolidator_config.js +14 -0
- package/dist/configs/consolidator_config.js.map +1 -0
- package/dist/configs/embedding_generator_config.d.ts +13 -0
- package/dist/configs/embedding_generator_config.d.ts.map +1 -0
- package/dist/configs/embedding_generator_config.js +11 -0
- package/dist/configs/embedding_generator_config.js.map +1 -0
- package/dist/configs/parser_config.d.ts +31 -0
- package/dist/configs/parser_config.d.ts.map +1 -0
- package/dist/configs/parser_config.js +26 -0
- package/dist/configs/parser_config.js.map +1 -0
- package/dist/configs/typology_generator_config.d.ts +26 -0
- package/dist/configs/typology_generator_config.d.ts.map +1 -0
- package/dist/configs/typology_generator_config.js +12 -0
- package/dist/configs/typology_generator_config.js.map +1 -0
- package/dist/consolidation/global_consolidator.d.ts +47 -0
- package/dist/consolidation/global_consolidator.d.ts.map +1 -0
- package/dist/consolidation/global_consolidator.js +94 -0
- package/dist/consolidation/global_consolidator.js.map +1 -0
- package/dist/consolidation/local_consolidator.d.ts +52 -0
- package/dist/consolidation/local_consolidator.d.ts.map +1 -0
- package/dist/consolidation/local_consolidator.js +118 -0
- package/dist/consolidation/local_consolidator.js.map +1 -0
- package/dist/embeddings/embedding_generator.d.ts +30 -0
- package/dist/embeddings/embedding_generator.d.ts.map +1 -0
- package/dist/embeddings/embedding_generator.js +71 -0
- package/dist/embeddings/embedding_generator.js.map +1 -0
- package/dist/generators/card_generator.d.ts +20 -0
- package/dist/generators/card_generator.d.ts.map +1 -0
- package/dist/generators/card_generator.js +239 -0
- package/dist/generators/card_generator.js.map +1 -0
- package/dist/generators/concept_facts_generator.d.ts +18 -0
- package/dist/generators/concept_facts_generator.d.ts.map +1 -0
- package/dist/generators/concept_facts_generator.js +153 -0
- package/dist/generators/concept_facts_generator.js.map +1 -0
- package/dist/generators/typology_generator.d.ts +20 -0
- package/dist/generators/typology_generator.d.ts.map +1 -0
- package/dist/generators/typology_generator.js +184 -0
- package/dist/generators/typology_generator.js.map +1 -0
- package/dist/index.d.ts +27 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -83
- package/dist/index.js.map +1 -1
- package/dist/parsers/card_response_parser.d.ts +16 -0
- package/dist/parsers/card_response_parser.d.ts.map +1 -0
- package/dist/parsers/card_response_parser.js +59 -0
- package/dist/parsers/card_response_parser.js.map +1 -0
- package/dist/parsers/content_parser.d.ts +27 -0
- package/dist/parsers/content_parser.d.ts.map +1 -0
- package/dist/parsers/content_parser.js +66 -0
- package/dist/parsers/content_parser.js.map +1 -0
- package/dist/utils/validation.d.ts +68 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +203 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +1 -1
- package/src/card_gen/generate_cards.ts +2 -3
- package/src/configs/card_generator_config.ts +58 -0
- package/src/configs/concept_facts_generator_config.ts +40 -0
- package/src/configs/consolidator_config.ts +33 -0
- package/src/configs/embedding_generator_config.ts +20 -0
- package/src/configs/parser_config.ts +57 -0
- package/src/configs/typology_generator_config.ts +38 -0
- package/src/consolidation/global_consolidator.ts +158 -0
- package/src/consolidation/local_consolidator.ts +173 -0
- package/src/embeddings/embedding_generator.ts +92 -0
- package/src/generators/card_generator.ts +258 -0
- package/src/generators/concept_facts_generator.ts +175 -0
- package/src/generators/typology_generator.ts +208 -0
- package/src/index.ts +60 -95
- package/src/parsers/card_response_parser.ts +63 -0
- package/src/parsers/content_parser.ts +90 -0
- package/src/utils/validation.ts +298 -0
- package/src/bootstrap/app.ts +0 -312
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone ConceptFactsGenerator module
|
|
3
|
+
* Extracts concepts and facts from content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_facts_schema";
|
|
7
|
+
import { OpenAIHelper } from "../helper/openai_helper";
|
|
8
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
9
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
10
|
+
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
11
|
+
import {
|
|
12
|
+
ConceptFactsGeneratorConfig,
|
|
13
|
+
DEFAULT_CONCEPT_FACTS_GENERATOR_CONFIG,
|
|
14
|
+
} from "../configs/concept_facts_generator_config";
|
|
15
|
+
import {
|
|
16
|
+
validateOpenAIKey,
|
|
17
|
+
validateOpenAIModel,
|
|
18
|
+
validatePromptId,
|
|
19
|
+
validateContentType,
|
|
20
|
+
} from "../utils/validation";
|
|
21
|
+
|
|
22
|
+
export class ConceptFactsGenerator {
|
|
23
|
+
private config: ConceptFactsGeneratorConfig;
|
|
24
|
+
private openAiService: OpenAiService;
|
|
25
|
+
private openAIHelper: OpenAIHelper;
|
|
26
|
+
|
|
27
|
+
constructor(config: ConceptFactsGeneratorConfig) {
|
|
28
|
+
this.validateConfig(config);
|
|
29
|
+
this.config = { ...DEFAULT_CONCEPT_FACTS_GENERATOR_CONFIG, ...config };
|
|
30
|
+
this.openAiService = new OpenAiService(
|
|
31
|
+
this.config.apiKey,
|
|
32
|
+
this.config.model
|
|
33
|
+
);
|
|
34
|
+
this.openAIHelper = new OpenAIHelper(this.config.apiKey);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generate concepts and facts from the configured content
|
|
39
|
+
*/
|
|
40
|
+
async generate(): Promise<any> {
|
|
41
|
+
try {
|
|
42
|
+
const headings =
|
|
43
|
+
this.config.type === "text"
|
|
44
|
+
? this.config.content.h1_headings || [""]
|
|
45
|
+
: this.config.content.timecodes || [""];
|
|
46
|
+
|
|
47
|
+
const schema = await buildConceptFactSchema(
|
|
48
|
+
headings.length > 0 ? headings : [""],
|
|
49
|
+
"concept_fact_gen_schema",
|
|
50
|
+
true
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const openAiResponse: any =
|
|
54
|
+
await this.openAIHelper.openAI.responses.create({
|
|
55
|
+
prompt: {
|
|
56
|
+
id: this.config.promptId,
|
|
57
|
+
variables: {
|
|
58
|
+
heading_type:
|
|
59
|
+
this.config.type == "video" ? "timecode" : "h1 heading",
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
max_output_tokens: 30000,
|
|
63
|
+
input: [
|
|
64
|
+
{
|
|
65
|
+
role: "user",
|
|
66
|
+
content: [
|
|
67
|
+
{
|
|
68
|
+
type: "input_text",
|
|
69
|
+
text: JSON.stringify(this.config.content),
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
},
|
|
73
|
+
],
|
|
74
|
+
store: true,
|
|
75
|
+
text: {
|
|
76
|
+
format: {
|
|
77
|
+
type: "json_schema",
|
|
78
|
+
name: schema.name,
|
|
79
|
+
strict: schema.strict,
|
|
80
|
+
schema: schema.schema,
|
|
81
|
+
},
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
if (!openAiResponse) {
|
|
86
|
+
await log_error({
|
|
87
|
+
flow: this.config.generationCurriculum
|
|
88
|
+
? "curriculum_manual_generation"
|
|
89
|
+
: "manual_generation",
|
|
90
|
+
data: openAiResponse,
|
|
91
|
+
error: "empty_openai_response",
|
|
92
|
+
timestamp: new Date(),
|
|
93
|
+
source_id: this.config.sourceId || "unknown",
|
|
94
|
+
type: {
|
|
95
|
+
request_type: "concept_fact",
|
|
96
|
+
n: 1,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
openAiResponse.metadata = {
|
|
103
|
+
req_time: openAiResponse.created ?? new Date(),
|
|
104
|
+
req_type: {
|
|
105
|
+
type: "breadth",
|
|
106
|
+
sub_type: "concept_fact",
|
|
107
|
+
n: 1,
|
|
108
|
+
},
|
|
109
|
+
req_tokens: openAiResponse.usage?.input_tokens ?? 0,
|
|
110
|
+
res_tokens: openAiResponse.usage?.output_tokens ?? 0,
|
|
111
|
+
prompt: openAiResponse.prompt,
|
|
112
|
+
model: this.config.model,
|
|
113
|
+
usage: openAiResponse.usage,
|
|
114
|
+
status: "completed",
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
const concepts_facts = this.parseJson(openAiResponse);
|
|
118
|
+
|
|
119
|
+
return {
|
|
120
|
+
concepts_facts: concepts_facts,
|
|
121
|
+
metadata: openAiResponse.metadata,
|
|
122
|
+
};
|
|
123
|
+
} catch (error) {
|
|
124
|
+
console.log(error);
|
|
125
|
+
await log_error({
|
|
126
|
+
flow: this.config.generationCurriculum
|
|
127
|
+
? "curriculum_manual_generation"
|
|
128
|
+
: "manual_generation",
|
|
129
|
+
data: error,
|
|
130
|
+
timestamp: new Date(),
|
|
131
|
+
error: "error_in_concept_facts_generation",
|
|
132
|
+
source_id: this.config.sourceId || "unknown",
|
|
133
|
+
type: {
|
|
134
|
+
request_type: "concept_fact",
|
|
135
|
+
n: 1,
|
|
136
|
+
},
|
|
137
|
+
});
|
|
138
|
+
throw error;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
private parseJson(response: any) {
|
|
143
|
+
try {
|
|
144
|
+
const concepts_facts = JSON.parse(response.output_text).concepts_facts;
|
|
145
|
+
if (concepts_facts) {
|
|
146
|
+
return concepts_facts.map((item: any) => {
|
|
147
|
+
return {
|
|
148
|
+
...item,
|
|
149
|
+
reference: restoreQuotesInString(item.reference),
|
|
150
|
+
};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
} catch (e) {
|
|
154
|
+
throw new ParsingError(
|
|
155
|
+
"Something went wrong in parsing the json",
|
|
156
|
+
response
|
|
157
|
+
);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
private validateConfig(config: ConceptFactsGeneratorConfig): void {
|
|
162
|
+
validateOpenAIKey(config.apiKey);
|
|
163
|
+
validateOpenAIModel(config.model);
|
|
164
|
+
validatePromptId(config.promptId, "prompt ID");
|
|
165
|
+
validateContentType(config.type);
|
|
166
|
+
|
|
167
|
+
if (!config.content) {
|
|
168
|
+
throw new Error("Content is required");
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (!config.content.title) {
|
|
172
|
+
throw new Error("Content title is required");
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone TypologyGenerator module
|
|
3
|
+
* Analyzes content and determines learning value and classification
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { getOpenAI, OpenAIHelper } from "../helper/openai_helper";
|
|
7
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
8
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
9
|
+
import { buildClassifySummarizeSchema } from "../helper/schema_helper/build_classify_summarize_schema";
|
|
10
|
+
import { restoreQuotesInString } from "../utils/sanitize_strings";
|
|
11
|
+
import {
|
|
12
|
+
TypologyGeneratorConfig,
|
|
13
|
+
DEFAULT_TYPOLOGY_GENERATOR_CONFIG,
|
|
14
|
+
} from "../configs/typology_generator_config";
|
|
15
|
+
import {
|
|
16
|
+
validateOpenAIKey,
|
|
17
|
+
validateOpenAIModel,
|
|
18
|
+
validatePromptId,
|
|
19
|
+
validateStringArray,
|
|
20
|
+
} from "../utils/validation";
|
|
21
|
+
|
|
22
|
+
export class TypologyGenerator {
|
|
23
|
+
private config: TypologyGeneratorConfig;
|
|
24
|
+
private openAiService: OpenAiService;
|
|
25
|
+
private openAIHelper: OpenAIHelper;
|
|
26
|
+
|
|
27
|
+
constructor(config: TypologyGeneratorConfig) {
|
|
28
|
+
this.validateConfig(config);
|
|
29
|
+
this.config = { ...DEFAULT_TYPOLOGY_GENERATOR_CONFIG, ...config };
|
|
30
|
+
this.openAiService = new OpenAiService(
|
|
31
|
+
this.config.apiKey,
|
|
32
|
+
this.config.model
|
|
33
|
+
);
|
|
34
|
+
this.openAIHelper = new OpenAIHelper(this.config.apiKey);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generate typology analysis for the configured content
|
|
39
|
+
*/
|
|
40
|
+
async generate(): Promise<any> {
|
|
41
|
+
try {
|
|
42
|
+
const headings = this.config.content.h1_headings ||
|
|
43
|
+
this.config.content.timecodes || [""];
|
|
44
|
+
|
|
45
|
+
// Use OpenAI Responses API
|
|
46
|
+
const classifySummarizeSchema = await buildClassifySummarizeSchema(
|
|
47
|
+
headings.length > 0 ? headings : [""]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const openAiResponse: any =
|
|
51
|
+
await this.openAIHelper.openAI.responses.create({
|
|
52
|
+
prompt: {
|
|
53
|
+
id: this.config.promptId,
|
|
54
|
+
variables: {
|
|
55
|
+
heading_type: this.config.content.timecodes
|
|
56
|
+
? "timecode"
|
|
57
|
+
: "h1 heading",
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
max_output_tokens: 30000,
|
|
61
|
+
input: [
|
|
62
|
+
{
|
|
63
|
+
role: "user",
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: "input_text",
|
|
67
|
+
text: JSON.stringify(this.config.content),
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
store: true,
|
|
73
|
+
text: {
|
|
74
|
+
format: {
|
|
75
|
+
type: "json_schema",
|
|
76
|
+
name: classifySummarizeSchema.name,
|
|
77
|
+
strict: true,
|
|
78
|
+
schema: classifySummarizeSchema.schema,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
console.log(openAiResponse);
|
|
84
|
+
|
|
85
|
+
if (!openAiResponse) {
|
|
86
|
+
await log_error({
|
|
87
|
+
flow: this.config.generationCurriculum
|
|
88
|
+
? "curriculum_manual_generation"
|
|
89
|
+
: "manual_generation",
|
|
90
|
+
data: openAiResponse,
|
|
91
|
+
error: "empty_openai_response",
|
|
92
|
+
timestamp: new Date(),
|
|
93
|
+
source_id: this.config.sourceId || "unknown",
|
|
94
|
+
type: {
|
|
95
|
+
request_type: "breadth",
|
|
96
|
+
n: 1,
|
|
97
|
+
},
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
openAiResponse["request_type"] = {
|
|
103
|
+
type: "breadth",
|
|
104
|
+
n: 1,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
openAiResponse.metadata = {
|
|
108
|
+
req_time: openAiResponse.created ?? new Date(),
|
|
109
|
+
req_type: {
|
|
110
|
+
type: "breadth",
|
|
111
|
+
n: 1,
|
|
112
|
+
},
|
|
113
|
+
req_tokens: openAiResponse.usage?.input_tokens ?? 0,
|
|
114
|
+
res_tokens: openAiResponse.usage?.output_tokens ?? 0,
|
|
115
|
+
prompt: openAiResponse.prompt,
|
|
116
|
+
model: openAiResponse.model,
|
|
117
|
+
usage: openAiResponse.usage,
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
if (openAiResponse.status == "completed") {
|
|
121
|
+
console.log("Completed");
|
|
122
|
+
return this.parseTypologyOnSuccess(openAiResponse);
|
|
123
|
+
} else {
|
|
124
|
+
openAiResponse.metadata.err_message = openAiResponse.message;
|
|
125
|
+
return openAiResponse;
|
|
126
|
+
}
|
|
127
|
+
} catch (e: any) {
|
|
128
|
+
console.log(e);
|
|
129
|
+
await log_error({
|
|
130
|
+
flow: this.config.generationCurriculum
|
|
131
|
+
? "curriculum_manual_generation"
|
|
132
|
+
: "manual_generation",
|
|
133
|
+
data: e,
|
|
134
|
+
timestamp: new Date(),
|
|
135
|
+
error: "error_in_typology_generation",
|
|
136
|
+
source_id: this.config.sourceId || "unknown",
|
|
137
|
+
type: {
|
|
138
|
+
request_type: "breadth",
|
|
139
|
+
n: 1,
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
throw e;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
private parseTypologyOnSuccess(responseData: any) {
|
|
147
|
+
responseData.metadata.status = "completed";
|
|
148
|
+
const generatedContent = this.parseJson(responseData);
|
|
149
|
+
console.log(generatedContent.learn_value);
|
|
150
|
+
|
|
151
|
+
return {
|
|
152
|
+
status_code: 200,
|
|
153
|
+
metadata: [responseData.metadata],
|
|
154
|
+
field: this.parseFields(generatedContent.field),
|
|
155
|
+
generate_cards: generatedContent.learn_value,
|
|
156
|
+
summary_cards: generatedContent.summary_cards,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private parseJson(response: any) {
|
|
161
|
+
try {
|
|
162
|
+
const generatedContent = JSON.parse(response.output_text);
|
|
163
|
+
const summaryCards = generatedContent?.summary_cards ?? [];
|
|
164
|
+
|
|
165
|
+
if (summaryCards) {
|
|
166
|
+
const remappedSummaryCards = summaryCards.map((item: any) => {
|
|
167
|
+
return {
|
|
168
|
+
...item,
|
|
169
|
+
reference: restoreQuotesInString(item.reference),
|
|
170
|
+
};
|
|
171
|
+
});
|
|
172
|
+
return {
|
|
173
|
+
...generatedContent,
|
|
174
|
+
summary_cards: remappedSummaryCards,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
return generatedContent;
|
|
178
|
+
} catch (e) {
|
|
179
|
+
throw new ParsingError(
|
|
180
|
+
"Something went wrong in parsing the json",
|
|
181
|
+
response
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
private parseFields(fields: Array<string>) {
|
|
187
|
+
const fieldKeys = ["primary_field", "secondary_field", "tertiary_field"];
|
|
188
|
+
return fields.slice(0, 3).map((item, index) => ({
|
|
189
|
+
[fieldKeys[index]]: item,
|
|
190
|
+
reconcile: !this.config.expectedFields.includes(item.toLowerCase()),
|
|
191
|
+
}));
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
private validateConfig(config: TypologyGeneratorConfig): void {
|
|
195
|
+
validateOpenAIKey(config.apiKey);
|
|
196
|
+
validateOpenAIModel(config.model);
|
|
197
|
+
validatePromptId(config.promptId, "prompt ID");
|
|
198
|
+
validateStringArray(config.expectedFields, "expected fields", true);
|
|
199
|
+
|
|
200
|
+
if (!config.content) {
|
|
201
|
+
throw new Error("Content is required");
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if (!config.content.title) {
|
|
205
|
+
throw new Error("Content title is required");
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,95 +1,60 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
//
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
// fields: source?.fields || [],
|
|
62
|
-
// learn_value: source?.learn_value || {
|
|
63
|
-
// value: 0,
|
|
64
|
-
// reason: "",
|
|
65
|
-
// bloom_levels: [],
|
|
66
|
-
// bloom_levels_reason: "",
|
|
67
|
-
// },
|
|
68
|
-
// }
|
|
69
|
-
// : undefined,
|
|
70
|
-
// },
|
|
71
|
-
// };
|
|
72
|
-
// const prompts = await getPrompts("text");
|
|
73
|
-
// const bloomInstructions = prompts.bloom_instructions;
|
|
74
|
-
// const cardInstructions = prompts.card_instructions;
|
|
75
|
-
// const cardExamples = prompts.card_examples;
|
|
76
|
-
|
|
77
|
-
// console.log("Initializing OnlyEverGenerator");
|
|
78
|
-
// const onlyEverGenerator = new OnlyEverGenerator(
|
|
79
|
-
// process.env.OPEN_AI_KEY as string,
|
|
80
|
-
// "o4-mini",
|
|
81
|
-
// contentForGen,
|
|
82
|
-
|
|
83
|
-
// "pmpt_687a8872d1c8819088a9cdc97dcb688b0893663621695594",
|
|
84
|
-
// "pmpt_687aa547f99c8193b99467ca53630c2607f5a8caf451e7e8",
|
|
85
|
-
// "pmpt_688118a923e4819098176a13a2f401920d2ea17d881cc6c6",
|
|
86
|
-
// {
|
|
87
|
-
// bloom_instructions: bloomInstructions,
|
|
88
|
-
// card_instructions: cardInstructions,
|
|
89
|
-
// card_examples: cardExamples,
|
|
90
|
-
// },
|
|
91
|
-
// false
|
|
92
|
-
// );
|
|
93
|
-
// const response = await onlyEverGenerator.generate(true, false);
|
|
94
|
-
// console.log(response);
|
|
95
|
-
// })();
|
|
1
|
+
// Core Generation Modules
|
|
2
|
+
export { CardGenerator } from "./generators/card_generator";
|
|
3
|
+
export { TypologyGenerator } from "./generators/typology_generator";
|
|
4
|
+
export { ConceptFactsGenerator } from "./generators/concept_facts_generator";
|
|
5
|
+
|
|
6
|
+
// Embedding & Consolidation Modules
|
|
7
|
+
export { EmbeddingGenerator } from "./embeddings/embedding_generator";
|
|
8
|
+
export { LocalConsolidator } from "./consolidation/local_consolidator";
|
|
9
|
+
export { GlobalConsolidator } from "./consolidation/global_consolidator";
|
|
10
|
+
|
|
11
|
+
// Parser Modules
|
|
12
|
+
export { ContentParser } from "./parsers/content_parser";
|
|
13
|
+
export { CardResponseParser } from "./parsers/card_response_parser";
|
|
14
|
+
|
|
15
|
+
// Configuration Types
|
|
16
|
+
export type { CardGeneratorConfig } from "./configs/card_generator_config";
|
|
17
|
+
export type { TypologyGeneratorConfig } from "./configs/typology_generator_config";
|
|
18
|
+
export type { ConceptFactsGeneratorConfig } from "./configs/concept_facts_generator_config";
|
|
19
|
+
export type { EmbeddingGeneratorConfig } from "./configs/embedding_generator_config";
|
|
20
|
+
export type {
|
|
21
|
+
LocalConsolidatorConfig,
|
|
22
|
+
GlobalConsolidatorConfig,
|
|
23
|
+
} from "./configs/consolidator_config";
|
|
24
|
+
export type {
|
|
25
|
+
ContentParserConfig,
|
|
26
|
+
CardResponseParserConfig,
|
|
27
|
+
} from "./configs/parser_config";
|
|
28
|
+
|
|
29
|
+
// Default Configurations
|
|
30
|
+
export { DEFAULT_CARD_GENERATOR_CONFIG } from "./configs/card_generator_config";
|
|
31
|
+
export { DEFAULT_TYPOLOGY_GENERATOR_CONFIG } from "./configs/typology_generator_config";
|
|
32
|
+
export { DEFAULT_CONCEPT_FACTS_GENERATOR_CONFIG } from "./configs/concept_facts_generator_config";
|
|
33
|
+
export { DEFAULT_EMBEDDING_GENERATOR_CONFIG } from "./configs/embedding_generator_config";
|
|
34
|
+
export {
|
|
35
|
+
DEFAULT_LOCAL_CONSOLIDATOR_CONFIG,
|
|
36
|
+
DEFAULT_GLOBAL_CONSOLIDATOR_CONFIG,
|
|
37
|
+
} from "./configs/consolidator_config";
|
|
38
|
+
export {
|
|
39
|
+
DEFAULT_CONTENT_PARSER_CONFIG,
|
|
40
|
+
DEFAULT_CARD_RESPONSE_PARSER_CONFIG,
|
|
41
|
+
} from "./configs/parser_config";
|
|
42
|
+
|
|
43
|
+
// Types
|
|
44
|
+
export type {
|
|
45
|
+
ConceptFact,
|
|
46
|
+
ConceptWithEmbedding,
|
|
47
|
+
} from "./embeddings/embedding_generator";
|
|
48
|
+
export type {
|
|
49
|
+
ConceptWithId,
|
|
50
|
+
ConsolidationResult,
|
|
51
|
+
} from "./consolidation/local_consolidator";
|
|
52
|
+
export type { GlobalConsolidationResult } from "./consolidation/global_consolidator";
|
|
53
|
+
export type { ParsedContent } from "./parsers/content_parser";
|
|
54
|
+
|
|
55
|
+
// Services (keep existing)
|
|
56
|
+
export { OpenAiService } from "./services/open_ai_service";
|
|
57
|
+
export { default as qdrantClient } from "./services/qdrant_service";
|
|
58
|
+
|
|
59
|
+
// Utilities
|
|
60
|
+
export { ValidationError } from "./utils/validation";
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone CardResponseParser module
|
|
3
|
+
* Parses and validates generated cards
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ParseCardResponse } from "../parse/parse_card_response";
|
|
7
|
+
import {
|
|
8
|
+
CardResponseParserConfig,
|
|
9
|
+
DEFAULT_CARD_RESPONSE_PARSER_CONFIG,
|
|
10
|
+
} from "../configs/parser_config";
|
|
11
|
+
import { GeneratedCardResponseType } from "../types/raw_card_response_types/generated_card_response_type";
|
|
12
|
+
import { SourceTaxonomy } from "../types/source_taxonomy_type";
|
|
13
|
+
|
|
14
|
+
export class CardResponseParser {
|
|
15
|
+
private config: CardResponseParserConfig;
|
|
16
|
+
|
|
17
|
+
constructor(config: CardResponseParserConfig) {
|
|
18
|
+
this.validateConfig(config);
|
|
19
|
+
this.config = { ...DEFAULT_CARD_RESPONSE_PARSER_CONFIG, ...config };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Parse and validate generated card response
|
|
24
|
+
*/
|
|
25
|
+
async parse(generatedData: GeneratedCardResponseType): Promise<any> {
|
|
26
|
+
const parser = new ParseCardResponse();
|
|
27
|
+
|
|
28
|
+
// Create source taxonomy from config
|
|
29
|
+
const sourceTaxonomy: SourceTaxonomy = {
|
|
30
|
+
concepts_facts: this.config.sourceTaxonomy.concepts_facts.map(
|
|
31
|
+
(concept) => ({
|
|
32
|
+
text: concept.text,
|
|
33
|
+
type: concept.type,
|
|
34
|
+
reference: concept.reference,
|
|
35
|
+
id: concept.id,
|
|
36
|
+
})
|
|
37
|
+
),
|
|
38
|
+
fields: [],
|
|
39
|
+
learn_value: {
|
|
40
|
+
value: 50,
|
|
41
|
+
reason: "Generated for card parsing",
|
|
42
|
+
bloom_levels: [],
|
|
43
|
+
bloom_levels_reason: "",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
return await parser.parse(
|
|
48
|
+
generatedData,
|
|
49
|
+
sourceTaxonomy,
|
|
50
|
+
this.config.bloomLevel!
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
private validateConfig(config: CardResponseParserConfig): void {
|
|
55
|
+
if (!config.sourceTaxonomy) {
|
|
56
|
+
throw new Error("Source taxonomy is required");
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (!config.sourceTaxonomy.concepts_facts) {
|
|
60
|
+
throw new Error("Concepts facts are required in source taxonomy");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Standalone ContentParser module
|
|
3
|
+
* Parses and sanitizes source content
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ParseSourceContent } from "../parse/parse_source_content";
|
|
7
|
+
import {
|
|
8
|
+
ContentParserConfig,
|
|
9
|
+
DEFAULT_CONTENT_PARSER_CONFIG,
|
|
10
|
+
} from "../configs/parser_config";
|
|
11
|
+
import { validateContentType } from "../utils/validation";
|
|
12
|
+
|
|
13
|
+
export interface ParsedContent {
|
|
14
|
+
source_id: string;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
content: any[];
|
|
18
|
+
headings: string[];
|
|
19
|
+
taxonomy?: any;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export class ContentParser {
|
|
23
|
+
private config: ContentParserConfig;
|
|
24
|
+
|
|
25
|
+
constructor(config: ContentParserConfig) {
|
|
26
|
+
this.validateConfig(config);
|
|
27
|
+
this.config = { ...DEFAULT_CONTENT_PARSER_CONFIG, ...config };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Parse raw content into structured format
|
|
32
|
+
*/
|
|
33
|
+
parse(rawContent: any): ParsedContent {
|
|
34
|
+
// Create a custom ParseSourceContent instance with our config
|
|
35
|
+
const parser = new ParseSourceContent(rawContent);
|
|
36
|
+
|
|
37
|
+
// Override the default titles and block types if provided
|
|
38
|
+
if (this.config.titlesToRemove) {
|
|
39
|
+
parser.titles_to_remove = this.config.titlesToRemove;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (this.config.blockTypesToRemove) {
|
|
43
|
+
parser.block_types_toremove = this.config.blockTypesToRemove;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const parsedData = parser.parseData();
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
source_id: parsedData.source_id,
|
|
50
|
+
type: parsedData.type,
|
|
51
|
+
title: parsedData.title,
|
|
52
|
+
content: parsedData.content,
|
|
53
|
+
headings: parsedData.headings,
|
|
54
|
+
taxonomy: parsedData.taxonomy,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Parse video content with timecode collapsing
|
|
60
|
+
*/
|
|
61
|
+
parseVideoContent(rawContent: any): ParsedContent {
|
|
62
|
+
const parser = new ParseSourceContent(rawContent);
|
|
63
|
+
|
|
64
|
+
// Override the collapse timecodes method if max duration is specified
|
|
65
|
+
if (this.config.maxTimecodeDuration) {
|
|
66
|
+
const originalCollapseTimeCodes = parser.collapseTimeCodes.bind(parser);
|
|
67
|
+
parser.collapseTimeCodes = (
|
|
68
|
+
data: any[],
|
|
69
|
+
maxDuration = this.config.maxTimecodeDuration
|
|
70
|
+
) => {
|
|
71
|
+
return originalCollapseTimeCodes(data, maxDuration);
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const parsedData = parser.parseData();
|
|
76
|
+
|
|
77
|
+
return {
|
|
78
|
+
source_id: parsedData.source_id,
|
|
79
|
+
type: parsedData.type,
|
|
80
|
+
title: parsedData.title,
|
|
81
|
+
content: parsedData.content,
|
|
82
|
+
headings: parsedData.headings,
|
|
83
|
+
taxonomy: parsedData.taxonomy,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
private validateConfig(config: ContentParserConfig): void {
|
|
88
|
+
validateContentType(config.type);
|
|
89
|
+
}
|
|
90
|
+
}
|