only_ever_generator 8.4.6 → 8.4.8
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 +6 -3
- package/dist/bootstrap/app.d.ts.map +1 -1
- package/dist/bootstrap/app.js +11 -17
- package/dist/bootstrap/app.js.map +1 -1
- package/dist/card_gen/generate_cards.d.ts +2 -3
- package/dist/card_gen/generate_cards.d.ts.map +1 -1
- package/dist/card_gen/generate_cards.js +22 -15
- package/dist/card_gen/generate_cards.js.map +1 -1
- package/dist/constants/prompt_data.d.ts +4 -4
- package/dist/constants/prompt_data.js +302 -302
- package/dist/constants/prompts/card_gen_prompt.js +160 -160
- package/dist/constants/prompts/typology_prompt.js +131 -131
- package/dist/constants/source_data.d.ts +171 -171
- package/dist/constants/source_data.js +973 -973
- package/dist/embedding_generation/local_consolidation.js +104 -104
- package/dist/helper/build_concept_facts_schema.d.ts +42 -42
- package/dist/helper/build_concept_facts_schema.js +44 -44
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.d.ts +1 -9
- package/dist/helper/schema_helper/build_card_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_card_schema.js +47 -50
- package/dist/helper/schema_helper/build_card_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_concept_facts_schema.d.ts +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 +20 -5
- package/dist/helper/schema_helper/build_concept_facts_schema.js.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts +1 -1
- package/dist/helper/schema_helper/build_summary_schema.d.ts.map +1 -1
- package/dist/helper/schema_helper/build_summary_schema.js +18 -7
- package/dist/helper/schema_helper/build_summary_schema.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/parse/response_format_card.d.ts +176 -176
- package/dist/parse/response_format_card.js +371 -371
- package/dist/parse/response_format_typology.d.ts +1 -1
- package/dist/parse/response_format_typology.js +46 -46
- package/dist/services/get_prompts.d.ts +8 -7
- package/dist/services/get_prompts.d.ts.map +1 -1
- package/dist/services/get_prompts.js +69 -21
- package/dist/services/get_prompts.js.map +1 -1
- package/dist/typology_gen/generate_concept_facts.d.ts +2 -3
- package/dist/typology_gen/generate_concept_facts.d.ts.map +1 -1
- package/dist/typology_gen/generate_concept_facts.js +25 -15
- package/dist/typology_gen/generate_concept_facts.js.map +1 -1
- package/dist/typology_gen/generate_typology.d.ts +2 -1
- package/dist/typology_gen/generate_typology.d.ts.map +1 -1
- package/dist/typology_gen/generate_typology.js +24 -13
- package/dist/typology_gen/generate_typology.js.map +1 -1
- package/dist/typology_gen/summarize.d.ts +2 -3
- package/dist/typology_gen/summarize.d.ts.map +1 -1
- package/dist/typology_gen/summarize.js +24 -13
- package/dist/typology_gen/summarize.js.map +1 -1
- package/package.json +39 -38
- package/src/bootstrap/app.ts +418 -416
- package/src/card_gen/generate_cards.ts +347 -345
- package/src/config.ts +11 -11
- package/src/constants/api_constants.ts +7 -7
- package/src/constants/prompts/card_gen_prompt.ts +164 -164
- package/src/constants/prompts/typology_prompt.ts +139 -139
- package/src/embedding_generation/consolidation/global_consolidation.ts +96 -96
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -141
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -98
- package/src/embedding_generation/generate_embeddings.ts +42 -42
- package/src/embedding_generation/parse_embedding_response.ts +31 -31
- package/src/enums/card_type_enum.ts +6 -6
- package/src/gap_fill/calculate_gap_fill.ts +50 -50
- package/src/helper/get_id_from_title.ts +33 -33
- package/src/helper/mongo_helper.ts +29 -29
- package/src/helper/openai_helper.ts +20 -20
- package/src/helper/qdrant_db_methods.ts +77 -77
- package/src/helper/schema_helper/build_card_schema.ts +74 -98
- package/src/helper/schema_helper/build_classify_summarize_schema.ts +43 -43
- package/src/helper/schema_helper/build_concept_facts_schema.ts +45 -31
- package/src/helper/schema_helper/build_summary_schema.ts +43 -32
- package/src/index.ts +71 -73
- package/src/logger.ts +65 -65
- package/src/parse/parse_card/parse_cloze_card.ts +146 -146
- package/src/parse/parse_card/parse_flash_cards.ts +42 -42
- package/src/parse/parse_card/parse_match_card.ts +104 -104
- package/src/parse/parse_card/parse_mcq_card.ts +114 -114
- package/src/parse/parse_card_response.ts +197 -197
- package/src/parse/parse_source_content.ts +212 -212
- package/src/services/get_prompts.ts +164 -112
- package/src/services/open_ai_service.ts +89 -89
- package/src/services/qdrant_service.ts +10 -10
- package/src/types/base_param_type.ts +13 -13
- package/src/types/mongo_concept_fact_type.ts +12 -12
- package/src/types/parsed_card_type.ts +39 -39
- package/src/types/raw_card_response_types/generated_card_response_type.ts +59 -59
- package/src/types/source_taxonomy_type.ts +24 -24
- package/src/typology-parsed-response.ts +1932 -1932
- package/src/typology_gen/generate_concept_facts.ts +180 -169
- package/src/typology_gen/generate_typology.ts +203 -189
- package/src/typology_gen/summarize.ts +176 -164
- package/src/utils/distributed_quote_restoration.ts +80 -80
- package/src/utils/generate_args.ts +29 -29
- package/src/utils/parse_openai_response.ts +19 -19
- package/src/utils/sanitize_strings.ts +65 -65
- package/tsconfig.json +16 -16
- package/dist/constants/default_generation_variables.d.ts +0 -3
- package/dist/constants/default_generation_variables.d.ts.map +0 -1
- package/dist/constants/default_generation_variables.js +0 -580
- package/dist/constants/default_generation_variables.js.map +0 -1
- package/dist/services/prompts_test.d.ts +0 -10
- package/dist/services/prompts_test.d.ts.map +0 -1
- package/dist/services/prompts_test.js +0 -227
- package/dist/services/prompts_test.js.map +0 -1
- package/dist/types/generation_variables_schema.d.ts +0 -14
- package/dist/types/generation_variables_schema.d.ts.map +0 -1
- package/dist/types/generation_variables_schema.js +0 -3
- package/dist/types/generation_variables_schema.js.map +0 -1
- package/dist/utils/test.d.ts +0 -2
- package/dist/utils/test.d.ts.map +0 -1
- package/dist/utils/test.js +0 -5
- package/dist/utils/test.js.map +0 -1
- package/src/constants/default_generation_variables.ts +0 -624
- package/src/types/generation_variables_schema.ts +0 -16
|
@@ -1,169 +1,180 @@
|
|
|
1
|
-
import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_facts_schema";
|
|
2
|
-
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
|
-
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
-
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
5
|
-
import {
|
|
6
|
-
restoreQuotesInObject,
|
|
7
|
-
restoreQuotesInString,
|
|
8
|
-
} from "../utils/sanitize_strings";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
public
|
|
14
|
-
public
|
|
15
|
-
public
|
|
16
|
-
public
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
generationCurriculum: boolean
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
this.
|
|
39
|
-
this.
|
|
40
|
-
this.
|
|
41
|
-
this.type = type;
|
|
42
|
-
this.sourceId = sourceId;
|
|
43
|
-
this.generationCurriculum = generationCurriculum;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
//
|
|
107
|
-
//
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
try {
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
1
|
+
import { buildConceptFactSchema } from "../helper/schema_helper/build_concept_facts_schema";
|
|
2
|
+
import { OpenAIHelper } from "../helper/openai_helper";
|
|
3
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
+
import { ErrorLogger, log_error, ParsingError } from "../logger";
|
|
5
|
+
import {
|
|
6
|
+
restoreQuotesInObject,
|
|
7
|
+
restoreQuotesInString,
|
|
8
|
+
} from "../utils/sanitize_strings";
|
|
9
|
+
import { jsonrepair } from "jsonrepair";
|
|
10
|
+
|
|
11
|
+
export class GenerateConceptFacts {
|
|
12
|
+
public openAiService: OpenAiService;
|
|
13
|
+
public openAIHelper: OpenAIHelper;
|
|
14
|
+
public sourceId: string;
|
|
15
|
+
public generationCurriculum: boolean;
|
|
16
|
+
public content: {
|
|
17
|
+
title: string;
|
|
18
|
+
h1_headings?: string[];
|
|
19
|
+
timecodes?: string[];
|
|
20
|
+
content: any[];
|
|
21
|
+
};
|
|
22
|
+
public type: string = "";
|
|
23
|
+
public promptIdForConceptFacts: string;
|
|
24
|
+
constructor(
|
|
25
|
+
openAiService: OpenAiService,
|
|
26
|
+
sourceId: string,
|
|
27
|
+
content: {
|
|
28
|
+
title: string;
|
|
29
|
+
h1_headings?: string[];
|
|
30
|
+
timecodes?: string[];
|
|
31
|
+
content: any[];
|
|
32
|
+
},
|
|
33
|
+
type: string,
|
|
34
|
+
promptIdForConceptFacts: string,
|
|
35
|
+
generationCurriculum: boolean
|
|
36
|
+
) {
|
|
37
|
+
this.openAiService = openAiService;
|
|
38
|
+
this.openAIHelper = new OpenAIHelper(this.openAiService.api_key);
|
|
39
|
+
this.content = content;
|
|
40
|
+
this.promptIdForConceptFacts = promptIdForConceptFacts;
|
|
41
|
+
this.type = type;
|
|
42
|
+
this.sourceId = sourceId;
|
|
43
|
+
this.generationCurriculum = generationCurriculum;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async generate() {
|
|
47
|
+
try {
|
|
48
|
+
const headings =
|
|
49
|
+
this.type === "text"
|
|
50
|
+
? this.content.h1_headings || [""]
|
|
51
|
+
: this.content.timecodes || [""];
|
|
52
|
+
const schema = await buildConceptFactSchema(
|
|
53
|
+
headings.length > 0 ? headings : [""],
|
|
54
|
+
"concept_fact_gen_schema",
|
|
55
|
+
true
|
|
56
|
+
);
|
|
57
|
+
const openAiResponse: any =
|
|
58
|
+
await this.openAIHelper.openAI.responses.create({
|
|
59
|
+
prompt: {
|
|
60
|
+
id: this.promptIdForConceptFacts,
|
|
61
|
+
version: "200",
|
|
62
|
+
variables: {
|
|
63
|
+
heading_type: this.type == "video" ? "timecode" : "h1 heading",
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
max_output_tokens: 30000,
|
|
67
|
+
input: [
|
|
68
|
+
{
|
|
69
|
+
role: "user",
|
|
70
|
+
content: [
|
|
71
|
+
{
|
|
72
|
+
type: "input_text",
|
|
73
|
+
text: JSON.stringify(this.content),
|
|
74
|
+
},
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
// input: JSON.stringify(this.content),
|
|
79
|
+
store: true,
|
|
80
|
+
text: {
|
|
81
|
+
format: {
|
|
82
|
+
type: "json_schema",
|
|
83
|
+
name: schema.name,
|
|
84
|
+
strict: schema.strict,
|
|
85
|
+
schema: schema.schema,
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
});
|
|
89
|
+
if (!openAiResponse) {
|
|
90
|
+
await log_error({
|
|
91
|
+
flow: "manual_generation",
|
|
92
|
+
data: openAiResponse,
|
|
93
|
+
error: "empty_openai_response",
|
|
94
|
+
timestamp: new Date(),
|
|
95
|
+
source_id: this.sourceId,
|
|
96
|
+
type: {
|
|
97
|
+
request_type: "concept_fact",
|
|
98
|
+
n: 1,
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// // Restore quotes in the response (works without original mapping)
|
|
105
|
+
// if (openAiResponse.output) {
|
|
106
|
+
// openAiResponse.output = restoreQuotesInObject(openAiResponse.output);
|
|
107
|
+
// }
|
|
108
|
+
|
|
109
|
+
openAiResponse.metadata = {
|
|
110
|
+
req_time: openAiResponse.created ?? new Date(),
|
|
111
|
+
req_type: {
|
|
112
|
+
type: "breadth",
|
|
113
|
+
sub_type: "concept_fact",
|
|
114
|
+
n: 1,
|
|
115
|
+
},
|
|
116
|
+
req_tokens: openAiResponse.usage?.input_tokens ?? 0,
|
|
117
|
+
res_tokens: openAiResponse.usage?.output_tokens ?? 0,
|
|
118
|
+
prompt: openAiResponse.prompt,
|
|
119
|
+
// prompt_tokens_details: openAiResponse.usage?.,
|
|
120
|
+
model: this.openAiService.model,
|
|
121
|
+
usage: openAiResponse.usage,
|
|
122
|
+
status: "completed",
|
|
123
|
+
};
|
|
124
|
+
const concepts_facts = this.parseJson(openAiResponse);
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
concepts_facts: concepts_facts,
|
|
128
|
+
metadata: openAiResponse.metadata,
|
|
129
|
+
};
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.log(error);
|
|
132
|
+
await log_error({
|
|
133
|
+
flow: this.generationCurriculum
|
|
134
|
+
? "curriculum_manual_generation"
|
|
135
|
+
: "manual_generation",
|
|
136
|
+
data: error,
|
|
137
|
+
timestamp: new Date(),
|
|
138
|
+
error: "error_in_concept_facts_generation",
|
|
139
|
+
source_id: this.sourceId,
|
|
140
|
+
type: {
|
|
141
|
+
request_type: "concept_fact",
|
|
142
|
+
n: 1,
|
|
143
|
+
},
|
|
144
|
+
});
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
parseJson(response: any) {
|
|
150
|
+
let parsedJson: any;
|
|
151
|
+
|
|
152
|
+
try {
|
|
153
|
+
parsedJson = JSON.parse(response.output_text);
|
|
154
|
+
} catch (e) {
|
|
155
|
+
// If original JSON parse fails, attempt to repair and parse
|
|
156
|
+
try {
|
|
157
|
+
const repairedJson = jsonrepair(response.output_text);
|
|
158
|
+
parsedJson = JSON.parse(repairedJson);
|
|
159
|
+
} catch (repairError) {
|
|
160
|
+
// If repair also fails, throw exception
|
|
161
|
+
throw new ParsingError(
|
|
162
|
+
"Something went wrong in repairing the json",
|
|
163
|
+
response
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// Process the parsed content (same flow for both original and repaired JSON)
|
|
169
|
+
const concepts_facts = parsedJson.concepts_facts;
|
|
170
|
+
if (concepts_facts) {
|
|
171
|
+
return concepts_facts.map((item: any) => {
|
|
172
|
+
return {
|
|
173
|
+
...item,
|
|
174
|
+
reference: restoreQuotesInString(item.reference),
|
|
175
|
+
};
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
180
|
+
}
|