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.
Files changed (89) hide show
  1. package/MODULAR_REFACTORING_SUMMARY.md +217 -0
  2. package/README.md +608 -0
  3. package/dist/card_gen/generate_cards.d.ts +1 -1
  4. package/dist/card_gen/generate_cards.d.ts.map +1 -1
  5. package/dist/card_gen/generate_cards.js +3 -4
  6. package/dist/card_gen/generate_cards.js.map +1 -1
  7. package/dist/configs/card_generator_config.d.ts +41 -0
  8. package/dist/configs/card_generator_config.d.ts.map +1 -0
  9. package/dist/configs/card_generator_config.js +17 -0
  10. package/dist/configs/card_generator_config.js.map +1 -0
  11. package/dist/configs/concept_facts_generator_config.d.ts +28 -0
  12. package/dist/configs/concept_facts_generator_config.d.ts.map +1 -0
  13. package/dist/configs/concept_facts_generator_config.js +12 -0
  14. package/dist/configs/concept_facts_generator_config.js.map +1 -0
  15. package/dist/configs/consolidator_config.d.ts +20 -0
  16. package/dist/configs/consolidator_config.d.ts.map +1 -0
  17. package/dist/configs/consolidator_config.js +14 -0
  18. package/dist/configs/consolidator_config.js.map +1 -0
  19. package/dist/configs/embedding_generator_config.d.ts +13 -0
  20. package/dist/configs/embedding_generator_config.d.ts.map +1 -0
  21. package/dist/configs/embedding_generator_config.js +11 -0
  22. package/dist/configs/embedding_generator_config.js.map +1 -0
  23. package/dist/configs/parser_config.d.ts +31 -0
  24. package/dist/configs/parser_config.d.ts.map +1 -0
  25. package/dist/configs/parser_config.js +26 -0
  26. package/dist/configs/parser_config.js.map +1 -0
  27. package/dist/configs/typology_generator_config.d.ts +26 -0
  28. package/dist/configs/typology_generator_config.d.ts.map +1 -0
  29. package/dist/configs/typology_generator_config.js +12 -0
  30. package/dist/configs/typology_generator_config.js.map +1 -0
  31. package/dist/consolidation/global_consolidator.d.ts +47 -0
  32. package/dist/consolidation/global_consolidator.d.ts.map +1 -0
  33. package/dist/consolidation/global_consolidator.js +94 -0
  34. package/dist/consolidation/global_consolidator.js.map +1 -0
  35. package/dist/consolidation/local_consolidator.d.ts +52 -0
  36. package/dist/consolidation/local_consolidator.d.ts.map +1 -0
  37. package/dist/consolidation/local_consolidator.js +118 -0
  38. package/dist/consolidation/local_consolidator.js.map +1 -0
  39. package/dist/embeddings/embedding_generator.d.ts +30 -0
  40. package/dist/embeddings/embedding_generator.d.ts.map +1 -0
  41. package/dist/embeddings/embedding_generator.js +71 -0
  42. package/dist/embeddings/embedding_generator.js.map +1 -0
  43. package/dist/generators/card_generator.d.ts +20 -0
  44. package/dist/generators/card_generator.d.ts.map +1 -0
  45. package/dist/generators/card_generator.js +239 -0
  46. package/dist/generators/card_generator.js.map +1 -0
  47. package/dist/generators/concept_facts_generator.d.ts +18 -0
  48. package/dist/generators/concept_facts_generator.d.ts.map +1 -0
  49. package/dist/generators/concept_facts_generator.js +153 -0
  50. package/dist/generators/concept_facts_generator.js.map +1 -0
  51. package/dist/generators/typology_generator.d.ts +20 -0
  52. package/dist/generators/typology_generator.d.ts.map +1 -0
  53. package/dist/generators/typology_generator.js +184 -0
  54. package/dist/generators/typology_generator.js.map +1 -0
  55. package/dist/index.d.ts +27 -2
  56. package/dist/index.d.ts.map +1 -1
  57. package/dist/index.js +46 -83
  58. package/dist/index.js.map +1 -1
  59. package/dist/parsers/card_response_parser.d.ts +16 -0
  60. package/dist/parsers/card_response_parser.d.ts.map +1 -0
  61. package/dist/parsers/card_response_parser.js +59 -0
  62. package/dist/parsers/card_response_parser.js.map +1 -0
  63. package/dist/parsers/content_parser.d.ts +27 -0
  64. package/dist/parsers/content_parser.d.ts.map +1 -0
  65. package/dist/parsers/content_parser.js +66 -0
  66. package/dist/parsers/content_parser.js.map +1 -0
  67. package/dist/utils/validation.d.ts +68 -0
  68. package/dist/utils/validation.d.ts.map +1 -0
  69. package/dist/utils/validation.js +203 -0
  70. package/dist/utils/validation.js.map +1 -0
  71. package/package.json +1 -1
  72. package/src/card_gen/generate_cards.ts +2 -3
  73. package/src/configs/card_generator_config.ts +58 -0
  74. package/src/configs/concept_facts_generator_config.ts +40 -0
  75. package/src/configs/consolidator_config.ts +33 -0
  76. package/src/configs/embedding_generator_config.ts +20 -0
  77. package/src/configs/parser_config.ts +57 -0
  78. package/src/configs/typology_generator_config.ts +38 -0
  79. package/src/consolidation/global_consolidator.ts +158 -0
  80. package/src/consolidation/local_consolidator.ts +173 -0
  81. package/src/embeddings/embedding_generator.ts +92 -0
  82. package/src/generators/card_generator.ts +258 -0
  83. package/src/generators/concept_facts_generator.ts +175 -0
  84. package/src/generators/typology_generator.ts +208 -0
  85. package/src/index.ts +60 -95
  86. package/src/parsers/card_response_parser.ts +63 -0
  87. package/src/parsers/content_parser.ts +90 -0
  88. package/src/utils/validation.ts +298 -0
  89. package/src/bootstrap/app.ts +0 -312
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Input validation utilities for OnlyEver Generator
3
+ */
4
+
5
+ export class ValidationError extends Error {
6
+ constructor(message: string, public field?: string) {
7
+ super(message);
8
+ this.name = "ValidationError";
9
+ }
10
+ }
11
+
12
+ /**
13
+ * Validates that a value is not null or undefined
14
+ */
15
+ export function validateRequired<T>(
16
+ value: T | null | undefined,
17
+ fieldName: string
18
+ ): T {
19
+ if (value === null || value === undefined) {
20
+ throw new ValidationError(`${fieldName} is required`, fieldName);
21
+ }
22
+ return value;
23
+ }
24
+
25
+ /**
26
+ * Validates that a string is not empty
27
+ */
28
+ export function validateNonEmptyString(
29
+ value: string | null | undefined,
30
+ fieldName: string
31
+ ): string {
32
+ const validated = validateRequired(value, fieldName);
33
+ if (typeof validated !== "string" || validated.trim().length === 0) {
34
+ throw new ValidationError(
35
+ `${fieldName} must be a non-empty string`,
36
+ fieldName
37
+ );
38
+ }
39
+ return validated;
40
+ }
41
+
42
+ /**
43
+ * Validates that a value is a positive number
44
+ */
45
+ export function validatePositiveNumber(
46
+ value: number | null | undefined,
47
+ fieldName: string
48
+ ): number {
49
+ const validated = validateRequired(value, fieldName);
50
+ if (typeof validated !== "number" || validated <= 0) {
51
+ throw new ValidationError(
52
+ `${fieldName} must be a positive number`,
53
+ fieldName
54
+ );
55
+ }
56
+ return validated;
57
+ }
58
+
59
+ /**
60
+ * Validates that a number is within a range
61
+ */
62
+ export function validateNumberRange(
63
+ value: number | null | undefined,
64
+ fieldName: string,
65
+ min: number,
66
+ max: number
67
+ ): number {
68
+ const validated = validateRequired(value, fieldName);
69
+ if (typeof validated !== "number" || validated < min || validated > max) {
70
+ throw new ValidationError(
71
+ `${fieldName} must be between ${min} and ${max}`,
72
+ fieldName
73
+ );
74
+ }
75
+ return validated;
76
+ }
77
+
78
+ /**
79
+ * Validates that a value is one of the allowed values
80
+ */
81
+ export function validateEnum<T extends string>(
82
+ value: T | null | undefined,
83
+ fieldName: string,
84
+ allowedValues: readonly T[]
85
+ ): T {
86
+ const validated = validateRequired(value, fieldName);
87
+ if (!allowedValues.includes(validated)) {
88
+ throw new ValidationError(
89
+ `${fieldName} must be one of: ${allowedValues.join(", ")}`,
90
+ fieldName
91
+ );
92
+ }
93
+ return validated;
94
+ }
95
+
96
+ /**
97
+ * Validates that a value is an array with at least one element
98
+ */
99
+ export function validateNonEmptyArray<T>(
100
+ value: T[] | null | undefined,
101
+ fieldName: string
102
+ ): T[] {
103
+ const validated = validateRequired(value, fieldName);
104
+ if (!Array.isArray(validated) || validated.length === 0) {
105
+ throw new ValidationError(
106
+ `${fieldName} must be a non-empty array`,
107
+ fieldName
108
+ );
109
+ }
110
+ return validated;
111
+ }
112
+
113
+ /**
114
+ * Validates OpenAI API key format
115
+ */
116
+ export function validateOpenAIKey(apiKey: string | null | undefined): string {
117
+ const validated = validateNonEmptyString(apiKey, "OpenAI API key");
118
+
119
+ // Basic format validation for OpenAI API keys
120
+ if (!validated.startsWith("sk-")) {
121
+ throw new ValidationError('OpenAI API key must start with "sk-"', "apiKey");
122
+ }
123
+
124
+ if (validated.length < 20) {
125
+ throw new ValidationError(
126
+ "OpenAI API key appears to be too short",
127
+ "apiKey"
128
+ );
129
+ }
130
+
131
+ return validated;
132
+ }
133
+
134
+ /**
135
+ * Validates OpenAI model name
136
+ */
137
+ export function validateOpenAIModel(model: string | null | undefined): string {
138
+ const validated = validateNonEmptyString(model, "OpenAI model");
139
+
140
+ // Common OpenAI model patterns
141
+ const validModels = [
142
+ "gpt-4o",
143
+ "gpt-4o-mini",
144
+ "gpt-4",
145
+ "gpt-4-turbo",
146
+ "gpt-3.5-turbo",
147
+ "gpt-3.5-turbo-16k",
148
+ ];
149
+
150
+ if (!validModels.some((validModel) => validated.startsWith(validModel))) {
151
+ console.warn(
152
+ `Model "${validated}" may not be a valid OpenAI model. Valid models include: ${validModels.join(
153
+ ", "
154
+ )}`
155
+ );
156
+ }
157
+
158
+ return validated;
159
+ }
160
+
161
+ /**
162
+ * Validates prompt ID format
163
+ */
164
+ export function validatePromptId(
165
+ promptId: string | null | undefined,
166
+ fieldName: string
167
+ ): string {
168
+ const validated = validateNonEmptyString(promptId, fieldName);
169
+
170
+ // Basic format validation for prompt IDs
171
+ if (!validated.startsWith("pmpt_")) {
172
+ throw new ValidationError(
173
+ `${fieldName} must start with "pmpt_"`,
174
+ fieldName
175
+ );
176
+ }
177
+
178
+ if (validated.length < 10) {
179
+ throw new ValidationError(
180
+ `${fieldName} appears to be too short`,
181
+ fieldName
182
+ );
183
+ }
184
+
185
+ return validated;
186
+ }
187
+
188
+ /**
189
+ * Validates content type
190
+ */
191
+ export function validateContentType(type: string | null | undefined): string {
192
+ return validateEnum(type, "content type", ["text", "video"] as const);
193
+ }
194
+
195
+ /**
196
+ * Validates source ID format
197
+ */
198
+ export function validateSourceId(sourceId: string | null | undefined): string {
199
+ const validated = validateNonEmptyString(sourceId, "source ID");
200
+
201
+ // Basic validation - should be a reasonable length
202
+ if (validated.length < 3) {
203
+ throw new ValidationError(
204
+ "Source ID must be at least 3 characters long",
205
+ "sourceId"
206
+ );
207
+ }
208
+
209
+ return validated;
210
+ }
211
+
212
+ /**
213
+ * Validates similarity threshold
214
+ */
215
+ export function validateSimilarityThreshold(
216
+ threshold: number | null | undefined,
217
+ fieldName: string
218
+ ): number {
219
+ return validateNumberRange(threshold, fieldName, 0, 1);
220
+ }
221
+
222
+ /**
223
+ * Validates embedding dimensions
224
+ */
225
+ export function validateEmbeddingDimensions(
226
+ dimensions: number | null | undefined
227
+ ): number {
228
+ const validated = validateRequired(dimensions, "embedding dimensions");
229
+
230
+ // Common embedding dimensions
231
+ const validDimensions = [128, 256, 512, 768, 1024, 1536, 2048];
232
+
233
+ if (!validDimensions.includes(validated)) {
234
+ console.warn(
235
+ `Embedding dimensions ${validated} may not be standard. Common values: ${validDimensions.join(
236
+ ", "
237
+ )}`
238
+ );
239
+ }
240
+
241
+ return validated;
242
+ }
243
+
244
+ /**
245
+ * Validates that an object has required properties
246
+ */
247
+ export function validateObjectProperties<T extends Record<string, any>>(
248
+ obj: T | null | undefined,
249
+ fieldName: string,
250
+ requiredProperties: (keyof T)[]
251
+ ): T {
252
+ const validated = validateRequired(obj, fieldName);
253
+
254
+ for (const prop of requiredProperties) {
255
+ if (
256
+ !(prop in validated) ||
257
+ validated[prop] === null ||
258
+ validated[prop] === undefined
259
+ ) {
260
+ throw new ValidationError(
261
+ `${fieldName} must have property "${String(prop)}"`,
262
+ fieldName
263
+ );
264
+ }
265
+ }
266
+
267
+ return validated;
268
+ }
269
+
270
+ /**
271
+ * Validates array of strings
272
+ */
273
+ export function validateStringArray(
274
+ value: string[] | null | undefined,
275
+ fieldName: string,
276
+ allowEmpty: boolean = true
277
+ ): string[] {
278
+ const validated = validateRequired(value, fieldName);
279
+
280
+ if (!Array.isArray(validated)) {
281
+ throw new ValidationError(`${fieldName} must be an array`, fieldName);
282
+ }
283
+
284
+ if (!allowEmpty && validated.length === 0) {
285
+ throw new ValidationError(`${fieldName} must not be empty`, fieldName);
286
+ }
287
+
288
+ for (let i = 0; i < validated.length; i++) {
289
+ if (typeof validated[i] !== "string") {
290
+ throw new ValidationError(
291
+ `${fieldName}[${i}] must be a string`,
292
+ fieldName
293
+ );
294
+ }
295
+ }
296
+
297
+ return validated;
298
+ }
@@ -1,312 +0,0 @@
1
- import { GenerateCards } from "../card_gen/generate_cards";
2
- import { ParseSourceContent } from "../parse/parse_source_content";
3
- import { OpenAiService } from "../services/open_ai_service";
4
- import { GenerateTypology } from "../typology_gen/generate_typology";
5
- import { GenerateArgs } from "../utils/generate_args";
6
- import { GenerateEmbeddings } from "../embedding_generation/generate_embeddings";
7
- import { LocalConsolidation } from "../embedding_generation/consolidation/local_consolidation";
8
- import { GlobalConsolidation } from "../embedding_generation/consolidation/global_consolidation";
9
- import { WriteConsolidatedData } from "../embedding_generation/consolidation/write_consolidated_data";
10
- import { BaseParamType } from "../types/base_param_type";
11
- import { SourceTaxonomy } from "../types/source_taxonomy_type";
12
- import { MongoConceptFactSource } from "../types/mongo_concept_fact_type";
13
- import { OpenAIHelper } from "../helper/openai_helper";
14
- import { GenerateConceptFacts } from "../typology_gen/generate_concept_facts";
15
-
16
- export class OnlyEverGenerator {
17
- public api_key: string = "";
18
- public openAiService: OpenAiService;
19
-
20
- /// these fields will be populated inside the constructor
21
- parsedContent?: {
22
- title: string;
23
- headings: string[];
24
- content: any[];
25
- taxonomy: SourceTaxonomy;
26
- source_id: string;
27
- type: string;
28
- } = undefined;
29
- promptForTypology: string = "";
30
- promptForCardGen: string = "";
31
- public generationCurriculum: boolean = false;
32
- public promptIdForTypology: string;
33
- public promptIdForConceptFacts: string;
34
- public promptIdForCardsGeneration: string;
35
- public n: number = 0;
36
- generationVariables: {
37
- bloom_instructions: string;
38
- card_instructions: string;
39
- card_examples: string;
40
- } = {
41
- bloom_instructions: "",
42
- card_instructions: "",
43
- card_examples: "",
44
- };
45
- expectedFields: Array<string> = [];
46
- typologyResponse?: any = undefined;
47
- cardgenResponse: any = undefined;
48
- summarizeResponse = {};
49
-
50
- constructor(
51
- apiKey: string,
52
- model: string,
53
- generationContent: BaseParamType,
54
- promptIdForTypology: string,
55
- promptIdForConceptFacts: string,
56
- promptIdForCardsGeneration: string,
57
- generationVariables: {
58
- bloom_instructions: string;
59
- card_instructions: string;
60
- card_examples: string;
61
- },
62
- generationCurriculum: boolean,
63
- n: number | undefined
64
- ) {
65
- this.promptIdForTypology = promptIdForTypology;
66
- this.promptIdForConceptFacts = promptIdForConceptFacts;
67
- this.promptIdForCardsGeneration = promptIdForCardsGeneration;
68
- this.api_key = apiKey;
69
- this.generationVariables = generationVariables;
70
- this.generationCurriculum = generationCurriculum;
71
- this.n = n ?? 1;
72
- this.openAiService = new OpenAiService(
73
- apiKey,
74
- model ?? "gpt-3.5-turbo-1106"
75
- );
76
-
77
- const parsedData = new ParseSourceContent(
78
- generationContent.content
79
- ).parseData();
80
- (this.parsedContent = {
81
- title: parsedData.title,
82
- headings: parsedData.headings,
83
- content: parsedData.content,
84
- taxonomy: parsedData.taxonomy,
85
- source_id: parsedData.source_id,
86
- type: parsedData.type,
87
- }),
88
- (this.typologyResponse = generationContent.content.taxonomy);
89
-
90
- this.expectedFields = generationContent.content.fields; //returnFields();
91
- this.promptForTypology = generationContent.prompt.typology;
92
- this.promptForCardGen = generationContent.prompt.card_generation;
93
- }
94
-
95
- async generate(
96
- generate_typology: boolean = false,
97
- generate_card: boolean = false
98
- ): Promise<Array<any>> {
99
- try {
100
- let args = new GenerateArgs(generate_card, generate_typology, false);
101
- const responseToReturn = [];
102
- const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
103
- for (let elem of whatNeedsToBeGenerated)
104
- if (elem == "generate_tyopology") {
105
- console.log("Generating typology");
106
- this.typologyResponse = await this.generateTypology();
107
- console.log("Typology generated");
108
- console.log(this.typologyResponse?.generate_cards?.value);
109
- console.log(
110
- JSON.stringify(this.typologyResponse?.generate_cards?.value > 30)
111
- );
112
-
113
- if (
114
- this.typologyResponse?.status_code == 200 &&
115
- (this.typologyResponse?.generate_cards?.value ?? 30) > 30
116
- ) {
117
- console.log("Concept facts generating");
118
- const response = await this.generateConceptFacts(
119
- this.typologyResponse
120
- );
121
- this.typologyResponse.concepts_facts =
122
- response?.concepts_facts ?? [];
123
- this.typologyResponse.metadata?.push(response?.metadata ?? {});
124
- console.log("Concept facts generated");
125
- console.log(this.typologyResponse);
126
- const embeddings = await this.generateEmbeddings(
127
- this.typologyResponse
128
- );
129
- console.log("Embedding generated");
130
- const localConsolidation = await this.localConsolidation(
131
- embeddings.concepts_facts,
132
- this.parsedContent!.title
133
- );
134
- console.log("Local consolidation done");
135
- this.typologyResponse!.concepts_facts =
136
- localConsolidation.sourceTaxonomyOps;
137
- const globalConsolidation = await this.globalConsolidation(
138
- localConsolidation.sourceTaxonomyOps,
139
- this.parsedContent!.source_id,
140
- 0.8
141
- );
142
- console.log("Global consolidation done");
143
- this.typologyResponse!.concepts_facts =
144
- globalConsolidation.source_taxonomy;
145
- this.typologyResponse!.metadata?.push(embeddings.metadata);
146
- responseToReturn.push({
147
- type: "typology",
148
- data: this.typologyResponse,
149
- qdrantOps: {
150
- update: globalConsolidation.global_updates,
151
- inserts: globalConsolidation.global_inserts,
152
- },
153
- });
154
- } else {
155
- responseToReturn.push({
156
- type: "typology",
157
- data: this.typologyResponse,
158
- });
159
- }
160
- } else if (elem == "generate_card") {
161
- if (this.shouldTheCardBeGeneratedAfterTypologyResponse()) {
162
- console.log("Generating card");
163
- this.parsedContent!.taxonomy = {
164
- concepts_facts: this.typologyResponse?.concepts_facts ?? [],
165
- fields: this.expectedFields,
166
- learn_value: this.typologyResponse?.learn_value ?? {
167
- value: 0,
168
- reason: "",
169
- bloom_levels: [],
170
- bloom_levels_reason: "",
171
- },
172
- };
173
- this.cardgenResponse = await this.generateCard(this.n);
174
- responseToReturn.push({
175
- type: "card_gen",
176
- data: this.cardgenResponse,
177
- });
178
- }
179
- }
180
- return responseToReturn;
181
- } catch (error) {
182
- console.log(error);
183
- return [];
184
- }
185
- }
186
-
187
- shouldTheCardBeGeneratedAfterTypologyResponse() {
188
- if (this.typologyResponse) {
189
- return (
190
- (this.typologyResponse?.generate_cards?.value ??
191
- this.typologyResponse?.learn_value?.value ??
192
- 30) > 30
193
- );
194
- } else {
195
- return false;
196
- }
197
- }
198
-
199
- async generateCard(n: number) {
200
- const content = {
201
- title: this.parsedContent?.title,
202
- concepts_facts: this.typologyResponse?.concepts_facts,
203
- content: this.parsedContent?.content,
204
- };
205
- let generateCardsResp = await new GenerateCards(
206
- this.openAiService,
207
- this.parsedContent?.source_id ?? "",
208
- JSON.stringify(content),
209
- this.parsedContent!.taxonomy,
210
- this.generationVariables,
211
- this.promptIdForCardsGeneration,
212
- this.generationCurriculum
213
- ).generateCards(n);
214
- return generateCardsResp;
215
- }
216
-
217
- async generateTypology() {
218
- const type = this.parsedContent?.type ?? "text";
219
- const content = {
220
- title: this.parsedContent?.title ?? "",
221
- ...(type === "text"
222
- ? { h1_headings: this.parsedContent?.headings ?? [""] }
223
- : { timecodes: this.parsedContent?.headings ?? [""] }),
224
- content: this.parsedContent?.content ?? [],
225
- };
226
- try {
227
- let response = await new GenerateTypology(
228
- this.openAiService,
229
- type,
230
- this.parsedContent?.source_id ?? "",
231
- content,
232
- this.expectedFields,
233
- this.promptIdForTypology,
234
- this.generationCurriculum
235
- ).generate();
236
- return response;
237
- } catch (error) {
238
- console.log(error);
239
- }
240
- }
241
-
242
- async generateConceptFacts(typologyResponse: any) {
243
- const type = this.parsedContent?.type ?? "text";
244
- const content = {
245
- title: this.parsedContent?.title ?? "",
246
- ...(type === "text"
247
- ? { h1_headings: this.parsedContent?.headings ?? [""] }
248
- : { timecodes: this.parsedContent?.headings ?? [""] }),
249
- key_takeaways: typologyResponse?.summary_cards ?? [],
250
- content: this.parsedContent?.content ?? [],
251
- ...(typologyResponse && typeof typologyResponse === "object"
252
- ? {
253
- fields: typologyResponse.field ?? [],
254
- }
255
- : {}),
256
- };
257
- let response = await new GenerateConceptFacts(
258
- this.openAiService,
259
- this.parsedContent?.source_id ?? "",
260
- content,
261
- type,
262
- this.promptIdForConceptFacts,
263
- this.generationCurriculum
264
- ).generate();
265
- return response;
266
- }
267
-
268
- async generateEmbeddings(typologyResponse: any) {
269
- const concepts_facts = typologyResponse.concepts_facts;
270
- const texts = concepts_facts.map((e: MongoConceptFactSource) => e.text);
271
- const embeddings = await new GenerateEmbeddings(
272
- this.openAiService
273
- ).generateEmbeddings(concepts_facts);
274
- return embeddings;
275
- }
276
-
277
- async localConsolidation(
278
- concepts_facts: {
279
- text: string;
280
- type: string;
281
- reference: string;
282
- embedding: number[];
283
- }[],
284
- sourceId: string
285
- ) {
286
- const embeddings = new LocalConsolidation().consolidate(
287
- concepts_facts,
288
- sourceId
289
- );
290
- return embeddings;
291
- }
292
-
293
- async globalConsolidation(
294
- concepts_facts: {
295
- id: string;
296
- text: string;
297
- type: string;
298
- reference: string;
299
- embedding: number[];
300
- }[],
301
- sourceId: string,
302
- threshold: number
303
- ) {
304
- const embeddings = await new GlobalConsolidation().consolidate(
305
- concepts_facts,
306
- sourceId,
307
- threshold ?? 0.8
308
- );
309
-
310
- return embeddings;
311
- }
312
- }