only_ever_generator 0.7.8 → 0.8.0
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 +97 -0
- package/dist/bootstrap/app.d.ts.map +1 -0
- package/dist/bootstrap/app.js +42 -48
- package/dist/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.d.ts +8 -0
- package/dist/card_gen/generate_cards.d.ts.map +1 -0
- package/dist/card_gen/generate_cards.js +32 -24
- package/dist/card_gen/generate_cards.js.map +1 -0
- package/dist/config.d.ts +8 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -0
- package/dist/constants/api_constants.d.ts +3 -0
- package/dist/constants/api_constants.d.ts.map +1 -0
- package/dist/constants/api_constants.js +5 -0
- package/dist/constants/api_constants.js.map +1 -0
- package/dist/constants/prompt_data.d.ts +4 -0
- package/dist/constants/prompt_data.js +1 -0
- package/dist/constants/prompt_data.js.map +1 -0
- package/dist/constants/prompts/card_gen_prompt.d.ts +2 -0
- package/dist/constants/prompts/card_gen_prompt.d.ts.map +1 -0
- package/dist/constants/prompts/card_gen_prompt.js +1 -0
- package/dist/constants/prompts/card_gen_prompt.js.map +1 -0
- package/dist/constants/prompts/typology_prompt.d.ts +2 -0
- package/dist/constants/prompts/typology_prompt.d.ts.map +1 -0
- package/dist/constants/prompts/typology_prompt.js +1 -0
- package/dist/constants/prompts/typology_prompt.js.map +1 -0
- package/dist/constants/source_data.d.ts +171 -0
- package/dist/constants/source_data.js +2 -1
- package/dist/constants/source_data.js.map +1 -0
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts +33 -0
- package/dist/embedding_generation/consolidation/global_consolidation.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/global_consolidation.js +76 -0
- package/dist/embedding_generation/consolidation/global_consolidation.js.map +1 -0
- package/dist/embedding_generation/consolidation/local_consolidation.d.ts +39 -0
- package/dist/embedding_generation/consolidation/local_consolidation.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/local_consolidation.js +105 -0
- package/dist/embedding_generation/consolidation/local_consolidation.js.map +1 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.d.ts +46 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.d.ts.map +1 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.js +69 -0
- package/dist/embedding_generation/consolidation/write_consolidated_data.js.map +1 -0
- package/dist/embedding_generation/generate_embeddings.d.ts +28 -0
- package/dist/embedding_generation/generate_embeddings.d.ts.map +1 -0
- package/dist/embedding_generation/generate_embeddings.js +54 -0
- package/dist/embedding_generation/generate_embeddings.js.map +1 -0
- package/dist/embedding_generation/parse_embedding_response.d.ts +26 -0
- package/dist/embedding_generation/parse_embedding_response.d.ts.map +1 -0
- package/dist/embedding_generation/parse_embedding_response.js +29 -0
- package/dist/embedding_generation/parse_embedding_response.js.map +1 -0
- package/dist/enums/card_type_enum.d.ts +7 -0
- package/dist/enums/card_type_enum.d.ts.map +1 -0
- package/dist/enums/card_type_enum.js +11 -0
- package/dist/enums/card_type_enum.js.map +1 -0
- package/dist/gap_fill/calculate_gap_fill.d.ts +5 -0
- package/dist/gap_fill/calculate_gap_fill.d.ts.map +1 -0
- package/dist/gap_fill/calculate_gap_fill.js +3 -5
- package/dist/gap_fill/calculate_gap_fill.js.map +1 -0
- package/dist/helper/qdrant_db_methods.d.ts +40 -0
- package/dist/helper/qdrant_db_methods.d.ts.map +1 -0
- package/dist/helper/qdrant_db_methods.js +63 -0
- package/dist/helper/qdrant_db_methods.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +88 -49
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +6 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +1 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts +17 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.js +3 -2
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts +26 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.js +4 -3
- package/dist/parse/parse_card/parse_flash_cards.js.map +1 -0
- package/dist/parse/parse_card/parse_match_card.d.ts +23 -0
- package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_match_card.js +3 -3
- package/dist/parse/parse_card/parse_match_card.js.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts +31 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.js +3 -2
- package/dist/parse/parse_card/parse_mcq_card.js.map +1 -0
- package/dist/parse/parse_card_response.d.ts +20 -0
- package/dist/parse/parse_card_response.d.ts.map +1 -0
- package/dist/parse/parse_card_response.js +62 -28
- package/dist/parse/parse_card_response.js.map +1 -0
- package/dist/parse/parse_source_content.d.ts +26 -0
- package/dist/parse/parse_source_content.d.ts.map +1 -0
- package/dist/parse/parse_source_content.js +1 -0
- package/dist/parse/parse_source_content.js.map +1 -0
- package/dist/parse/response_format_card.d.ts +176 -0
- package/dist/parse/response_format_card.js +1 -0
- package/dist/parse/response_format_card.js.map +1 -0
- package/dist/parse/response_format_typology.d.ts +1 -0
- package/dist/parse/response_format_typology.js +1 -0
- package/dist/parse/response_format_typology.js.map +1 -0
- package/dist/services/open_ai_service.d.ts +16 -0
- package/dist/services/open_ai_service.d.ts.map +1 -0
- package/dist/services/open_ai_service.js +29 -0
- package/dist/services/open_ai_service.js.map +1 -0
- package/dist/services/qdrant_service.d.ts +4 -0
- package/dist/services/qdrant_service.d.ts.map +1 -0
- package/dist/services/qdrant_service.js +14 -0
- package/dist/services/qdrant_service.js.map +1 -0
- package/dist/types/base_param_type.d.ts +16 -0
- package/dist/types/base_param_type.d.ts.map +1 -0
- package/dist/types/base_param_type.js +3 -0
- package/dist/types/base_param_type.js.map +1 -0
- package/dist/types/mongo_concept_fact_type.d.ts +12 -0
- package/dist/types/mongo_concept_fact_type.d.ts.map +1 -0
- package/dist/types/mongo_concept_fact_type.js +3 -0
- package/dist/types/mongo_concept_fact_type.js.map +1 -0
- package/dist/types/parsed_card_type.d.ts +12 -0
- package/dist/types/parsed_card_type.d.ts.map +1 -0
- package/dist/types/parsed_card_type.js +30 -0
- package/dist/types/parsed_card_type.js.map +1 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.d.ts +40 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.d.ts.map +1 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.js +8 -0
- package/dist/types/raw_card_response_types/generated_card_response_type.js.map +1 -0
- package/dist/types/source_taxonomy_type.d.ts +15 -0
- package/dist/types/source_taxonomy_type.d.ts.map +1 -0
- package/dist/types/source_taxonomy_type.js +3 -0
- package/dist/types/source_taxonomy_type.js.map +1 -0
- package/dist/typology_gen/generate_typology.d.ts +29 -0
- package/dist/typology_gen/generate_typology.d.ts.map +1 -0
- package/dist/typology_gen/generate_typology.js +12 -11
- package/dist/typology_gen/generate_typology.js.map +1 -0
- package/dist/utils/generate_args.d.ts +8 -0
- package/dist/utils/generate_args.d.ts.map +1 -0
- package/dist/utils/generate_args.js +1 -0
- package/dist/utils/generate_args.js.map +1 -0
- package/dist/utils/parse_openai_response.d.ts +11 -0
- package/dist/utils/parse_openai_response.d.ts.map +1 -0
- package/dist/utils/parse_openai_response.js +1 -0
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +18 -14
- package/src/bootstrap/app.ts +84 -71
- package/src/card_gen/generate_cards.ts +40 -29
- package/src/config.ts +2 -0
- package/src/constants/api_constants.ts +4 -0
- package/src/constants/prompts/card_gen_prompt.ts +1 -1
- package/src/embedding_generation/consolidation/global_consolidation.ts +94 -0
- package/src/embedding_generation/consolidation/local_consolidation.ts +141 -0
- package/src/embedding_generation/consolidation/write_consolidated_data.ts +98 -0
- package/src/embedding_generation/generate_embeddings.ts +41 -0
- package/src/embedding_generation/parse_embedding_response.ts +31 -0
- package/src/enums/card_type_enum.ts +6 -0
- package/src/gap_fill/calculate_gap_fill.ts +42 -45
- package/src/helper/qdrant_db_methods.ts +77 -0
- package/src/parse/parse_card/parse_cloze_card.ts +11 -3
- package/src/parse/parse_card/parse_flash_cards.ts +12 -4
- package/src/parse/parse_card/parse_match_card.ts +10 -4
- package/src/parse/parse_card/parse_mcq_card.ts +11 -3
- package/src/parse/parse_card_response.ts +94 -31
- package/src/parse/parse_source_content.ts +9 -1
- package/src/services/open_ai_service.ts +33 -1
- package/src/services/qdrant_service.ts +10 -0
- package/src/types/base_param_type.ts +16 -0
- package/src/types/mongo_concept_fact_type.ts +12 -0
- package/src/types/parsed_card_type.ts +39 -0
- package/src/types/raw_card_response_types/generated_card_response_type.ts +61 -0
- package/src/types/source_taxonomy_type.ts +17 -0
- package/src/typology_gen/generate_typology.ts +13 -12
- package/tsconfig.json +8 -3
- package/.env.example +0 -1
- package/prompts.json +0 -23
- package/readme.md +0 -35
- package/src/constants/prompt_data.ts +0 -301
- package/src/constants/source_data.ts +0 -1036
- package/src/index.ts +0 -72
- package/src/parse/response_format_card.ts +0 -386
- package/src/parse/response_format_typology.ts +0 -44
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type GeneratedCardResponseType = {
|
|
2
|
+
metadata: any;
|
|
3
|
+
generated_content: {
|
|
4
|
+
test_cards: RawTestCardResponseType[];
|
|
5
|
+
};
|
|
6
|
+
status_code: number;
|
|
7
|
+
usage_data: any;
|
|
8
|
+
generated_at: Date;
|
|
9
|
+
};
|
|
10
|
+
export type RawTestCardResponseType = {
|
|
11
|
+
type: string;
|
|
12
|
+
card_content: RawFlashCardResponseType | RawMatchCardResponseType | RawClozeCardResponseType | RawMcqCardResponseType;
|
|
13
|
+
concepts: string[];
|
|
14
|
+
facts: string[];
|
|
15
|
+
bloom_level: number;
|
|
16
|
+
};
|
|
17
|
+
export type RawFlashCardResponseType = {
|
|
18
|
+
front: string;
|
|
19
|
+
back: string;
|
|
20
|
+
explanation?: string;
|
|
21
|
+
};
|
|
22
|
+
export type RawMatchCardResponseType = {
|
|
23
|
+
left_item: string;
|
|
24
|
+
right_item: string;
|
|
25
|
+
}[];
|
|
26
|
+
export type RawClozeCardResponseType = {
|
|
27
|
+
correct_options: string[];
|
|
28
|
+
incorrect_options: string[];
|
|
29
|
+
prompt: string;
|
|
30
|
+
explanation?: string;
|
|
31
|
+
};
|
|
32
|
+
export type RawMcqCardResponseType = {
|
|
33
|
+
prompt: string;
|
|
34
|
+
explanation?: string;
|
|
35
|
+
choices: {
|
|
36
|
+
choice: string;
|
|
37
|
+
is_correct: boolean;
|
|
38
|
+
}[];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=generated_card_response_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated_card_response_type.d.ts","sourceRoot":"","sources":["../../../src/types/raw_card_response_types/generated_card_response_type.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,yBAAyB,GAAG;IACtC,QAAQ,EAAE,GAAG,CAAC;IACd,iBAAiB,EAAE;QACjB,UAAU,EAAE,uBAAuB,EAAE,CAAC;KACvC,CAAC;IACF,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,GAAG,CAAC;IAChB,YAAY,EAAE,IAAI,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,IAAI,EAAE,MAAM,CAAC;IAMb,YAAY,EACR,wBAAwB,GACxB,wBAAwB,GACxB,wBAAwB,GACxB,sBAAsB,CAAC;IAC3B,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,EAAE,CAAC;AAEJ,MAAM,MAAM,wBAAwB,GAAG;IACrC,eAAe,EAAE,MAAM,EAAE,CAAC;IAC1B,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE;QACP,MAAM,EAAE,MAAM,CAAC;QACf,UAAU,EAAE,OAAO,CAAC;KACrB,EAAE,CAAC;CACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generated_card_response_type.js","sourceRoot":"","sources":["../../../src/types/raw_card_response_types/generated_card_response_type.ts"],"names":[],"mappings":";;AAwDA,EAAE;AACF,YAAY;AACZ,WAAW;AACX,UAAU;AACV,QAAQ"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type SourceTaxonomy = {
|
|
2
|
+
concepts_facts: {
|
|
3
|
+
text: string;
|
|
4
|
+
type: string;
|
|
5
|
+
embedding?: number[];
|
|
6
|
+
reference: string;
|
|
7
|
+
}[];
|
|
8
|
+
fields: string[];
|
|
9
|
+
metadata?: any[];
|
|
10
|
+
generate_cards: {
|
|
11
|
+
state: boolean;
|
|
12
|
+
reason: string;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=source_taxonomy_type.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source_taxonomy_type.d.ts","sourceRoot":"","sources":["../../src/types/source_taxonomy_type.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,cAAc,GAAG;IAC3B,cAAc,EAAE;QACd,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;QAEb,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;QACrB,SAAS,EAAE,MAAM,CAAC;KACnB,EAAE,CAAC;IACJ,MAAM,EAAE,MAAM,EAAE,CAAC;IAGjB,QAAQ,CAAC,EAAE,GAAG,EAAE,CAAC;IACjB,cAAc,EAAE;QACd,KAAK,EAAE,OAAO,CAAC;QACf,MAAM,EAAE,MAAM,CAAC;KAChB,CAAC;CACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source_taxonomy_type.js","sourceRoot":"","sources":["../../src/types/source_taxonomy_type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
2
|
+
export declare class GenerateTypology {
|
|
3
|
+
openAiService: OpenAiService;
|
|
4
|
+
prompt: string;
|
|
5
|
+
content: string;
|
|
6
|
+
expectedFields: Array<string>;
|
|
7
|
+
constructor(openAiService: OpenAiService, prompt: string, content: string, expected_fields: Array<string>);
|
|
8
|
+
generate(): Promise<any>;
|
|
9
|
+
parseTypologyOnSuccess(responseData: any): {
|
|
10
|
+
status_code: number;
|
|
11
|
+
metadata: any[];
|
|
12
|
+
field: {
|
|
13
|
+
[x: string]: string | boolean;
|
|
14
|
+
reconcile: boolean;
|
|
15
|
+
}[];
|
|
16
|
+
concepts_facts: any[];
|
|
17
|
+
generate_cards: any;
|
|
18
|
+
summary_cards: any;
|
|
19
|
+
};
|
|
20
|
+
parseFields(fields: Array<string>): {
|
|
21
|
+
[x: string]: string | boolean;
|
|
22
|
+
reconcile: boolean;
|
|
23
|
+
}[];
|
|
24
|
+
parseTypologyOnFailure(responseData: any): Promise<{
|
|
25
|
+
status_code: any;
|
|
26
|
+
metadata: any;
|
|
27
|
+
}>;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=generate_typology.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_typology.d.ts","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,6BAA6B,CAAC;AAI5D,qBAAa,gBAAgB;IACpB,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAM;IACpB,OAAO,EAAE,MAAM,CAAM;IAC5B,cAAc,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;gBAE5B,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,EACf,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC;IAS1B,QAAQ;IAmCd,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;;;;;;;;IA6BxC,WAAW,CAAC,MAAM,EAAE,KAAK,CAAC,MAAM,CAAC;;;;IAQ3B,sBAAsB,CAAC,YAAY,EAAE,GAAG;;;;CAQ/C"}
|
|
@@ -58,26 +58,26 @@ class GenerateTypology {
|
|
|
58
58
|
}
|
|
59
59
|
parseTypologyOnSuccess(responseData) {
|
|
60
60
|
responseData.metadata.status = "completed";
|
|
61
|
-
const
|
|
61
|
+
const generatedContent = responseData.generated_content;
|
|
62
|
+
const concepts = generatedContent.concepts.map((e) => {
|
|
62
63
|
return {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
text: e.concept_text,
|
|
65
|
+
type: "concept",
|
|
66
|
+
reference: e.reference,
|
|
66
67
|
};
|
|
67
68
|
});
|
|
68
|
-
const
|
|
69
|
+
const facts = generatedContent.facts.map((e) => {
|
|
69
70
|
return {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
text: e.fact_text,
|
|
72
|
+
type: "fact",
|
|
73
|
+
reference: e.reference,
|
|
73
74
|
};
|
|
74
75
|
});
|
|
75
|
-
const generatedContent = responseData.generated_content;
|
|
76
76
|
return {
|
|
77
77
|
status_code: 200,
|
|
78
|
-
metadata: responseData.metadata,
|
|
78
|
+
metadata: [responseData.metadata],
|
|
79
79
|
field: this.parseFields(generatedContent.field),
|
|
80
|
-
|
|
80
|
+
concepts_facts: [...concepts, ...facts],
|
|
81
81
|
generate_cards: generatedContent.generate_cards,
|
|
82
82
|
summary_cards: generatedContent.summary_cards,
|
|
83
83
|
// type: responseData.type,
|
|
@@ -101,3 +101,4 @@ class GenerateTypology {
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
exports.GenerateTypology = GenerateTypology;
|
|
104
|
+
//# sourceMappingURL=generate_typology.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_typology.js","sourceRoot":"","sources":["../../src/typology_gen/generate_typology.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare class GenerateArgs {
|
|
2
|
+
generate_card: boolean;
|
|
3
|
+
generate_typology: boolean;
|
|
4
|
+
generate_summary: boolean;
|
|
5
|
+
constructor(generate_card: boolean, generate_typology: boolean, generate_summary: boolean);
|
|
6
|
+
getWhatNeedsToBeGenerated(): string[];
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=generate_args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_args.d.ts","sourceRoot":"","sources":["../../src/utils/generate_args.ts"],"names":[],"mappings":"AAAA,qBAAa,YAAY;IAChB,aAAa,EAAE,OAAO,CAAS;IAC/B,iBAAiB,EAAE,OAAO,CAAS;IACnC,gBAAgB,EAAE,OAAO,CAAS;gBAGvC,aAAa,EAAE,OAAO,EACtB,iBAAiB,EAAE,OAAO,EAC1B,gBAAgB,EAAE,OAAO;IAO3B,yBAAyB;CAa1B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate_args.js","sourceRoot":"","sources":["../../src/utils/generate_args.ts"],"names":[],"mappings":";;;AAAA,MAAa,YAAY;IAKvB,YACE,aAAsB,EACtB,iBAA0B,EAC1B,gBAAyB;QAPpB,kBAAa,GAAY,KAAK,CAAC;QAC/B,sBAAiB,GAAY,KAAK,CAAC;QACnC,qBAAgB,GAAY,KAAK,CAAC;QAOvC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,iBAAiB,GAAG,iBAAiB,CAAC;QAC3C,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAC;IAC3C,CAAC;IAED,yBAAyB;QACvB,IAAI,UAAU,GAAG,EAAE,CAAC;QACpB,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YACnC,UAAU,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,IAAI,CAAC,gBAAgB,IAAI,IAAI,EAAE,CAAC;YAClC,UAAU,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC;QACtC,CAAC;QACD,IAAI,IAAI,CAAC,aAAa,IAAI,IAAI,EAAE,CAAC;YAC/B,UAAU,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC;QACnC,CAAC;QACD,OAAO,UAAU,CAAC;IACpB,CAAC;CACF;AA5BD,oCA4BC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare function parseOpenAiSuccessResponse(responseData: any): {
|
|
2
|
+
status_code: number;
|
|
3
|
+
usage_data: any;
|
|
4
|
+
generated_content: any;
|
|
5
|
+
generated_at: Date;
|
|
6
|
+
};
|
|
7
|
+
export declare function parseOpenAiFailureResponse(errorResponse: any): {
|
|
8
|
+
status_code: any;
|
|
9
|
+
message: any;
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=parse_openai_response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse_openai_response.d.ts","sourceRoot":"","sources":["../../src/utils/parse_openai_response.ts"],"names":[],"mappings":"AAAA,wBAAgB,0BAA0B,CAAC,YAAY,EAAE,GAAG;;;;;EAU3D;AAED,wBAAgB,0BAA0B,CAAC,aAAa,EAAE,GAAG;;;EAM5D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse_openai_response.js","sourceRoot":"","sources":["../../src/utils/parse_openai_response.ts"],"names":[],"mappings":";;AAAA,gEAUC;AAED,gEAMC;AAlBD,SAAgB,0BAA0B,CAAC,YAAiB;IAC1D,IAAI,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAClE,IAAI,MAAM,GAAG,YAAY,CAAC,KAAK,CAAC;IAChC,IAAI,WAAW,GAAG,YAAY,CAAC,OAAO,CAAC;IACvC,OAAO;QACL,WAAW,EAAE,GAAG;QAChB,UAAU,EAAE,MAAM;QAClB,iBAAiB,EAAE,OAAO;QAC1B,YAAY,EAAE,IAAI,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;KAC3C,CAAC;AACJ,CAAC;AAED,SAAgB,0BAA0B,CAAC,aAAkB;;IAC3D,mBAAmB;IACnB,OAAO;QACL,WAAW,EAAE,aAAa,CAAC,MAAM;QACjC,OAAO,EAAE,MAAA,MAAA,aAAa,CAAC,IAAI,0CAAE,KAAK,0CAAE,IAAI;KACzC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "only_ever_generator",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"main": "dist/
|
|
3
|
+
"version": "0.8.0",
|
|
4
|
+
"main": "dist/app.js",
|
|
5
|
+
"types": "dist/app.d.ts",
|
|
5
6
|
"scripts": {
|
|
6
|
-
"start": "npm run build && nodemon dist/
|
|
7
|
+
"start": "npm run build && nodemon dist/app.js",
|
|
7
8
|
"build": "tsc",
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
10
|
+
"example": "npm run build && nodemon dist/app.js"
|
|
9
11
|
},
|
|
10
12
|
"keywords": [],
|
|
11
|
-
"author": "
|
|
13
|
+
"author": "",
|
|
12
14
|
"license": "ISC",
|
|
15
|
+
"description": "",
|
|
13
16
|
"devDependencies": {
|
|
14
|
-
"@types/express": "^
|
|
15
|
-
"@types/node": "^
|
|
16
|
-
"dotenv": "^16.
|
|
17
|
-
"express": "^
|
|
18
|
-
"nodemon": "^3.1.
|
|
17
|
+
"@types/express": "^5.0.1",
|
|
18
|
+
"@types/node": "^22.15.3",
|
|
19
|
+
"dotenv": "^16.5.0",
|
|
20
|
+
"express": "^5.1.0",
|
|
21
|
+
"nodemon": "^3.1.10",
|
|
19
22
|
"ts-node": "^10.9.2",
|
|
20
|
-
"typescript": "^5.
|
|
23
|
+
"typescript": "^5.8.3"
|
|
21
24
|
},
|
|
22
25
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
26
|
+
"@qdrant/js-client-rest": "^1.14.0",
|
|
27
|
+
"axios": "^1.9.0",
|
|
28
|
+
"n": "^10.1.0",
|
|
25
29
|
"stable": "^0.1.8"
|
|
26
30
|
},
|
|
27
31
|
"eslintConfig": {
|
|
@@ -30,4 +34,4 @@
|
|
|
30
34
|
"typescript"
|
|
31
35
|
]
|
|
32
36
|
}
|
|
33
|
-
}
|
|
37
|
+
}
|
package/src/bootstrap/app.ts
CHANGED
|
@@ -1,30 +1,35 @@
|
|
|
1
1
|
import { GenerateCards } from "../card_gen/generate_cards";
|
|
2
2
|
import { ParseSourceContent } from "../parse/parse_source_content";
|
|
3
3
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
-
// import { returnCardGenPrompt } from "../constants/prompts/card_gen_prompt";
|
|
5
|
-
// import { returnTypologyPrompt } from "../constants/prompts/typology_prompt";
|
|
6
4
|
import { GenerateTypology } from "../typology_gen/generate_typology";
|
|
7
5
|
import { GenerateArgs } from "../utils/generate_args";
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
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";
|
|
11
13
|
|
|
12
14
|
export class OnlyEverGenerator {
|
|
13
15
|
public api_key: string = "";
|
|
14
16
|
public openAiService: OpenAiService;
|
|
15
17
|
|
|
16
18
|
/// these fields will be populated inside the constructor
|
|
17
|
-
parsedContent
|
|
19
|
+
parsedContent?: {
|
|
20
|
+
title: string;
|
|
21
|
+
headings: string[];
|
|
22
|
+
content: any[];
|
|
23
|
+
taxonomy: SourceTaxonomy;
|
|
24
|
+
} = undefined;
|
|
18
25
|
promptForTypology: string = "";
|
|
19
26
|
promptForCardGen: string = "";
|
|
20
|
-
expectedFields: Array<string
|
|
21
|
-
|
|
22
|
-
typologyResponse: any = undefined;
|
|
27
|
+
expectedFields: Array<string> = [];
|
|
28
|
+
typologyResponse?: SourceTaxonomy = undefined;
|
|
23
29
|
cardgenResponse: any = undefined;
|
|
24
30
|
summarizeResponse = {};
|
|
25
|
-
gapFillResponse: any = {};
|
|
26
31
|
|
|
27
|
-
constructor(apiKey: string, model: string, generationContent:
|
|
32
|
+
constructor(apiKey: string, model: string, generationContent: BaseParamType) {
|
|
28
33
|
this.api_key = apiKey;
|
|
29
34
|
this.openAiService = new OpenAiService(
|
|
30
35
|
apiKey,
|
|
@@ -39,7 +44,6 @@ export class OnlyEverGenerator {
|
|
|
39
44
|
content: parsedData.content,
|
|
40
45
|
taxonomy: parsedData.taxonomy,
|
|
41
46
|
}),
|
|
42
|
-
// parsedData.type == 'cards' ? this.typologyResponse = parsedData.taxonomy : this.typologyResponse = null;
|
|
43
47
|
(this.typologyResponse = generationContent.content.taxonomy);
|
|
44
48
|
|
|
45
49
|
this.expectedFields = generationContent.content.fields; //returnFields();
|
|
@@ -59,14 +63,35 @@ export class OnlyEverGenerator {
|
|
|
59
63
|
this.typologyResponse = await this.generateTypology(
|
|
60
64
|
this.promptForTypology
|
|
61
65
|
);
|
|
66
|
+
|
|
67
|
+
const embeddings = await this.generateEmbeddings(this.typologyResponse);
|
|
68
|
+
console.log("Embedding generated");
|
|
69
|
+
const localConsolidation = await this.localConsolidation(
|
|
70
|
+
embeddings.concepts_facts,
|
|
71
|
+
this.parsedContent!.title
|
|
72
|
+
);
|
|
73
|
+
console.log("Local consolidation done");
|
|
74
|
+
this.typologyResponse!.concepts_facts =
|
|
75
|
+
localConsolidation.sourceTaxonomyOps;
|
|
76
|
+
const globalConsolidation = await this.globalConsolidation(
|
|
77
|
+
localConsolidation.sourceTaxonomyOps,
|
|
78
|
+
this.parsedContent!.title,
|
|
79
|
+
0.8
|
|
80
|
+
);
|
|
81
|
+
console.log("Global consolidation done");
|
|
82
|
+
this.typologyResponse!.concepts_facts =
|
|
83
|
+
globalConsolidation.source_taxonomy;
|
|
84
|
+
this.typologyResponse!.metadata?.push(embeddings.metadata);
|
|
62
85
|
responseToReturn.push(this.typologyResponse);
|
|
63
86
|
} else if (elem == "generate_card") {
|
|
64
|
-
/// for cards gen to occur, there must be presence of source taxonomy
|
|
65
87
|
if (this.shouldTheCardBeGeneratedAfterTypologyResponse()) {
|
|
66
|
-
this.parsedContent
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
generate_cards: this.typologyResponse
|
|
88
|
+
this.parsedContent!.taxonomy = {
|
|
89
|
+
concepts_facts: this.typologyResponse?.concepts_facts ?? [],
|
|
90
|
+
fields: this.expectedFields,
|
|
91
|
+
generate_cards: this.typologyResponse?.generate_cards ?? {
|
|
92
|
+
state: false,
|
|
93
|
+
reason: "",
|
|
94
|
+
},
|
|
70
95
|
};
|
|
71
96
|
this.cardgenResponse = await this.generateCard(
|
|
72
97
|
this.promptForCardGen,
|
|
@@ -74,19 +99,9 @@ export class OnlyEverGenerator {
|
|
|
74
99
|
false
|
|
75
100
|
);
|
|
76
101
|
responseToReturn.push(this.cardgenResponse);
|
|
77
|
-
|
|
78
|
-
/// check if gap fill is required ie coverage determination
|
|
79
|
-
if (this.cardgenResponse.status_code == 200) {
|
|
80
|
-
this.gapFillResponse = await this._generationForGapFill(
|
|
81
|
-
this.typologyResponse,
|
|
82
|
-
this.cardgenResponse
|
|
83
|
-
);
|
|
84
|
-
responseToReturn.push(this.gapFillResponse);
|
|
85
|
-
}
|
|
86
102
|
}
|
|
87
103
|
}
|
|
88
104
|
return responseToReturn;
|
|
89
|
-
// return [typologyPrompt, cardPrompt];
|
|
90
105
|
}
|
|
91
106
|
|
|
92
107
|
shouldTheCardBeGeneratedAfterTypologyResponse() {
|
|
@@ -97,33 +112,11 @@ export class OnlyEverGenerator {
|
|
|
97
112
|
}
|
|
98
113
|
}
|
|
99
114
|
|
|
100
|
-
async _generationForGapFill(typologyData: any, cardGenData: any,) {
|
|
101
|
-
let gapFill = gapFilling(typologyData, cardGenData);
|
|
102
|
-
let response: any;
|
|
103
|
-
if (
|
|
104
|
-
gapFill.remainingConcepts.length !== 0 ||
|
|
105
|
-
gapFill.remainingFacts.length !== 0
|
|
106
|
-
) {
|
|
107
|
-
this.typologyResponse.facts = gapFill.remainingFacts;
|
|
108
|
-
this.typologyResponse.concepts = gapFill.remainingConcepts;
|
|
109
|
-
response = await this.generateCard(
|
|
110
|
-
this.promptForCardGen +
|
|
111
|
-
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
112
|
-
JSON.stringify(gapFill),
|
|
113
|
-
|
|
114
|
-
"",
|
|
115
|
-
true,
|
|
116
|
-
1,
|
|
117
|
-
);
|
|
118
|
-
}
|
|
119
|
-
return response;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
115
|
async generateCard(
|
|
123
116
|
prompt: string,
|
|
124
117
|
additionalContent: string,
|
|
125
118
|
isGapFill: boolean,
|
|
126
|
-
n: number = 0
|
|
119
|
+
n: number = 0
|
|
127
120
|
) {
|
|
128
121
|
let generateCardsResp = await new GenerateCards(
|
|
129
122
|
this.openAiService
|
|
@@ -131,11 +124,9 @@ export class OnlyEverGenerator {
|
|
|
131
124
|
prompt ?? "",
|
|
132
125
|
JSON.stringify(this.parsedContent) + additionalContent,
|
|
133
126
|
isGapFill,
|
|
134
|
-
this.parsedContent
|
|
127
|
+
this.parsedContent!.taxonomy,
|
|
128
|
+
n
|
|
135
129
|
);
|
|
136
|
-
|
|
137
|
-
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
138
|
-
// response['type'] = 'card_gen';
|
|
139
130
|
return generateCardsResp;
|
|
140
131
|
}
|
|
141
132
|
|
|
@@ -149,26 +140,48 @@ export class OnlyEverGenerator {
|
|
|
149
140
|
return response;
|
|
150
141
|
}
|
|
151
142
|
|
|
152
|
-
async
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
143
|
+
async generateEmbeddings(typologyResponse: any) {
|
|
144
|
+
const concepts_facts = typologyResponse.concepts_facts;
|
|
145
|
+
const texts = concepts_facts.map((e: MongoConceptFactSource) => e.text);
|
|
146
|
+
const embeddings = await new GenerateEmbeddings(
|
|
147
|
+
this.openAiService
|
|
148
|
+
).generateEmbeddings(concepts_facts);
|
|
149
|
+
return embeddings;
|
|
150
|
+
}
|
|
158
151
|
|
|
159
|
-
|
|
160
|
-
|
|
152
|
+
async localConsolidation(
|
|
153
|
+
concepts_facts: {
|
|
154
|
+
text: string;
|
|
155
|
+
type: string;
|
|
156
|
+
reference: string;
|
|
157
|
+
embedding: number[];
|
|
158
|
+
}[],
|
|
159
|
+
sourceId: string
|
|
160
|
+
) {
|
|
161
|
+
const embeddings = new LocalConsolidation().consolidate(
|
|
162
|
+
concepts_facts,
|
|
163
|
+
sourceId
|
|
164
|
+
);
|
|
165
|
+
return embeddings;
|
|
166
|
+
}
|
|
161
167
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
168
|
+
async globalConsolidation(
|
|
169
|
+
concepts_facts: {
|
|
170
|
+
id: string;
|
|
171
|
+
text: string;
|
|
172
|
+
type: string;
|
|
173
|
+
reference: string;
|
|
174
|
+
embedding: number[];
|
|
175
|
+
}[],
|
|
176
|
+
sourceId: string,
|
|
177
|
+
threshold: number
|
|
178
|
+
) {
|
|
179
|
+
const embeddings = await new GlobalConsolidation().consolidate(
|
|
180
|
+
concepts_facts,
|
|
181
|
+
sourceId,
|
|
182
|
+
threshold ?? 0.8
|
|
170
183
|
);
|
|
171
184
|
|
|
172
|
-
return
|
|
185
|
+
return embeddings;
|
|
173
186
|
}
|
|
174
187
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ErrorLogger } from "../logger";
|
|
2
2
|
import { ParseCardResponse } from "../parse/parse_card_response";
|
|
3
3
|
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
+
import { SourceTaxonomy } from "../types/source_taxonomy_type";
|
|
4
5
|
|
|
5
6
|
export class GenerateCards {
|
|
6
7
|
openAiService: OpenAiService;
|
|
@@ -12,37 +13,47 @@ export class GenerateCards {
|
|
|
12
13
|
prompt: string,
|
|
13
14
|
parsedContent: string,
|
|
14
15
|
isGapFill: boolean,
|
|
15
|
-
taxonomy:
|
|
16
|
-
n: number = 0
|
|
16
|
+
taxonomy: SourceTaxonomy,
|
|
17
|
+
n: number = 0
|
|
17
18
|
) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
response.metadata = {
|
|
23
|
-
req_time: response.generated_at ?? new Date(),
|
|
24
|
-
req_type: {
|
|
25
|
-
type: "depth",
|
|
26
|
-
n: updatedNumber,
|
|
27
|
-
bloom_level: 1,
|
|
28
|
-
},
|
|
29
|
-
req_tokens: response.usage_data?.prompt_tokens,
|
|
30
|
-
res_tokens: response.usage_data?.completion_tokens,
|
|
31
|
-
prompt_tokens_details: response.usage_data?.prompt_tokens_details,
|
|
32
|
-
model: this.openAiService.model,
|
|
33
|
-
};
|
|
34
|
-
if (response.status_code == 200) {
|
|
35
|
-
response.metadata.status = "completed";
|
|
36
|
-
let parseCard = new ParseCardResponse().parse(
|
|
37
|
-
response,
|
|
38
|
-
isGapFill,
|
|
39
|
-
taxonomy
|
|
19
|
+
try {
|
|
20
|
+
let response = await this.openAiService?.sendRequest(
|
|
21
|
+
prompt,
|
|
22
|
+
parsedContent
|
|
40
23
|
);
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
24
|
+
var updatedNumber = n + 1;
|
|
25
|
+
response.metadata = {
|
|
26
|
+
req_time: response.generated_at ?? new Date(),
|
|
27
|
+
req_type: {
|
|
28
|
+
type: "depth",
|
|
29
|
+
n: updatedNumber,
|
|
30
|
+
bloom_level: 1,
|
|
31
|
+
},
|
|
32
|
+
req_tokens: response.usage_data?.prompt_tokens,
|
|
33
|
+
res_tokens: response.usage_data?.completion_tokens,
|
|
34
|
+
prompt_tokens_details: response.usage_data?.prompt_tokens_details,
|
|
35
|
+
model: this.openAiService.model,
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
if (response.status_code == 200) {
|
|
39
|
+
response.metadata.status = "completed";
|
|
40
|
+
let parseCard = new ParseCardResponse().parse(
|
|
41
|
+
response,
|
|
42
|
+
isGapFill,
|
|
43
|
+
taxonomy,
|
|
44
|
+
1
|
|
45
|
+
);
|
|
46
|
+
return parseCard;
|
|
47
|
+
} else {
|
|
48
|
+
response.metadata.status = "failed";
|
|
49
|
+
response.metadata.err_message = response.message;
|
|
50
|
+
return response;
|
|
51
|
+
}
|
|
52
|
+
} catch (e: any) {
|
|
53
|
+
new ErrorLogger({
|
|
54
|
+
type: "card_generation",
|
|
55
|
+
data: e.message,
|
|
56
|
+
}).log();
|
|
46
57
|
}
|
|
47
58
|
}
|
|
48
59
|
}
|
package/src/config.ts
CHANGED
|
@@ -160,5 +160,5 @@ Once you are done generating the test cards, review the full list of concepts an
|
|
|
160
160
|
Only stop generating test questions once you believe there is sufficient testing material for learners to fully understand the concepts and remember the facts. The same concept or fact can have multiple test cards, so continue creating test cards until you are confident that there are enough for learners to fully grasp the source material.
|
|
161
161
|
`;
|
|
162
162
|
export function returnCardGenPrompt() {
|
|
163
|
-
|
|
163
|
+
return promptString;
|
|
164
164
|
}
|