only_ever_generator 0.7.8 → 0.7.9
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 +96 -0
- package/dist/bootstrap/app.js +42 -48
- package/dist/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.d.ts +7 -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 +7 -0
- package/dist/config.js +3 -0
- package/dist/config.js.map +1 -0
- package/dist/constants/api_constants.d.ts +2 -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 +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 +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 +32 -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 +38 -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 +45 -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 +27 -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 +25 -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 +6 -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 +4 -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 +39 -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 +5 -0
- package/dist/logger.js +1 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts +16 -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 +25 -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 +22 -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 +30 -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 +19 -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 +25 -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 +15 -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 +3 -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 +15 -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 +11 -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 +11 -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 +39 -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 +14 -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 +28 -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 +7 -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 +10 -0
- package/dist/utils/parse_openai_response.js +1 -0
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +17 -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 +6 -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 @@
|
|
|
1
|
+
{"version":3,"file":"source_taxonomy_type.js","sourceRoot":"","sources":["../../src/types/source_taxonomy_type.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -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":";;;;;;;;;;;;AAEA,sCAAwC;AAExC,MAAa,gBAAgB;IAK3B,YACE,aAA4B,EAC5B,MAAc,EACd,OAAe,EACf,eAA8B;QAPzB,WAAM,GAAW,EAAE,CAAC;QACpB,YAAO,GAAW,EAAE,CAAC;QAQ1B,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,cAAc,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC,IAAY,EAAE,EAAE,CACzD,IAAI,CAAC,WAAW,EAAE,CACnB,CAAC;IACJ,CAAC;IACK,QAAQ;;;YACZ,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,CAAA,MAAA,IAAI,CAAC,aAAa,0CAAE,WAAW,CACpD,IAAI,CAAC,MAAM,EACX,IAAI,CAAC,OAAO,CACb,CAAA,CAAC;gBACF,QAAQ,CAAC,cAAc,CAAC,GAAG;oBACzB,IAAI,EAAE,SAAS;oBACf,CAAC,EAAE,CAAC;iBACL,CAAC;gBACF,QAAQ,CAAC,QAAQ,GAAG;oBAClB,QAAQ,EAAE,MAAA,QAAQ,CAAC,YAAY,mCAAI,IAAI,IAAI,EAAE;oBAC7C,QAAQ,EAAE;wBACR,IA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,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,10 @@
|
|
|
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
|
+
};
|
|
@@ -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,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "only_ever_generator",
|
|
3
|
-
"version": "0.7.
|
|
4
|
-
"main": "dist/
|
|
3
|
+
"version": "0.7.9",
|
|
4
|
+
"main": "dist/app.js",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"start": "npm run build && nodemon dist/
|
|
6
|
+
"start": "npm run build && nodemon dist/app.js",
|
|
7
7
|
"build": "tsc",
|
|
8
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
9
|
+
"example": "npm run build && nodemon dist/app.js"
|
|
9
10
|
},
|
|
10
11
|
"keywords": [],
|
|
11
|
-
"author": "
|
|
12
|
+
"author": "",
|
|
12
13
|
"license": "ISC",
|
|
14
|
+
"description": "",
|
|
13
15
|
"devDependencies": {
|
|
14
|
-
"@types/express": "^
|
|
15
|
-
"@types/node": "^
|
|
16
|
-
"dotenv": "^16.
|
|
17
|
-
"express": "^
|
|
18
|
-
"nodemon": "^3.1.
|
|
16
|
+
"@types/express": "^5.0.1",
|
|
17
|
+
"@types/node": "^22.15.3",
|
|
18
|
+
"dotenv": "^16.5.0",
|
|
19
|
+
"express": "^5.1.0",
|
|
20
|
+
"nodemon": "^3.1.10",
|
|
19
21
|
"ts-node": "^10.9.2",
|
|
20
|
-
"typescript": "^5.
|
|
22
|
+
"typescript": "^5.8.3"
|
|
21
23
|
},
|
|
22
24
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
+
"@qdrant/js-client-rest": "^1.14.0",
|
|
26
|
+
"axios": "^1.9.0",
|
|
27
|
+
"n": "^10.1.0",
|
|
25
28
|
"stable": "^0.1.8"
|
|
26
29
|
},
|
|
27
30
|
"eslintConfig": {
|
|
@@ -30,4 +33,4 @@
|
|
|
30
33
|
"typescript"
|
|
31
34
|
]
|
|
32
35
|
}
|
|
33
|
-
}
|
|
36
|
+
}
|
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
|
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { getSimilarConcepts } from "../../helper/qdrant_db_methods";
|
|
2
|
+
|
|
3
|
+
export class GlobalConsolidation {
|
|
4
|
+
async consolidate(
|
|
5
|
+
locally_consolidated_concepts_facts: {
|
|
6
|
+
text: string;
|
|
7
|
+
type: string;
|
|
8
|
+
reference: string;
|
|
9
|
+
id: string;
|
|
10
|
+
embedding: number[];
|
|
11
|
+
}[],
|
|
12
|
+
sourceId: string,
|
|
13
|
+
threshold: number
|
|
14
|
+
) {
|
|
15
|
+
// / for all concepts_facts, find the ,most similar concepts_facts in qdrant, threshold of 0.8
|
|
16
|
+
const similarConcepts = await getSimilarConcepts(
|
|
17
|
+
"concepts-vectors",
|
|
18
|
+
locally_consolidated_concepts_facts,
|
|
19
|
+
threshold ?? 0.8
|
|
20
|
+
);
|
|
21
|
+
const taxonomyConcepts: {
|
|
22
|
+
text: string;
|
|
23
|
+
type: string;
|
|
24
|
+
reference: string;
|
|
25
|
+
id: string;
|
|
26
|
+
}[] = [];
|
|
27
|
+
|
|
28
|
+
const globalUpdatesOps: {
|
|
29
|
+
id: string;
|
|
30
|
+
sourceIdToAdd: string;
|
|
31
|
+
currentPayload: {
|
|
32
|
+
_sources: string[];
|
|
33
|
+
text: string;
|
|
34
|
+
};
|
|
35
|
+
}[] = [];
|
|
36
|
+
|
|
37
|
+
const globalInsertsOps: {
|
|
38
|
+
id: string;
|
|
39
|
+
vector: number[];
|
|
40
|
+
payload: {
|
|
41
|
+
_sources: string[];
|
|
42
|
+
text: string;
|
|
43
|
+
};
|
|
44
|
+
}[] = [];
|
|
45
|
+
for (const index in similarConcepts) {
|
|
46
|
+
const points = similarConcepts[index].points;
|
|
47
|
+
const originalConcept = locally_consolidated_concepts_facts[index];
|
|
48
|
+
if (points.length == 0) {
|
|
49
|
+
taxonomyConcepts.push({
|
|
50
|
+
id: originalConcept.id,
|
|
51
|
+
text: originalConcept.text,
|
|
52
|
+
type: originalConcept.type,
|
|
53
|
+
reference: originalConcept.reference,
|
|
54
|
+
});
|
|
55
|
+
globalInsertsOps.push({
|
|
56
|
+
id: originalConcept.id,
|
|
57
|
+
vector: originalConcept.embedding,
|
|
58
|
+
payload: {
|
|
59
|
+
_sources: [sourceId],
|
|
60
|
+
text: originalConcept.text,
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
} else {
|
|
64
|
+
const consolidatedId = points[0].id;
|
|
65
|
+
const currentPayload = points[0].payload;
|
|
66
|
+
// const currentSources = currentPayload?['_sources'] ?? [];
|
|
67
|
+
taxonomyConcepts.push({
|
|
68
|
+
id: consolidatedId.toString(),
|
|
69
|
+
text: originalConcept.text,
|
|
70
|
+
type: originalConcept.type,
|
|
71
|
+
reference: originalConcept.reference,
|
|
72
|
+
});
|
|
73
|
+
globalUpdatesOps.push({
|
|
74
|
+
id: consolidatedId.toString(),
|
|
75
|
+
sourceIdToAdd: sourceId,
|
|
76
|
+
currentPayload: {
|
|
77
|
+
// _sources: currentPayload['_sources'] ?? [],
|
|
78
|
+
_sources: (currentPayload?._sources ?? []) as string[],
|
|
79
|
+
text: (currentPayload?.text ?? "").toString(),
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return {
|
|
85
|
+
source_taxonomy: taxonomyConcepts,
|
|
86
|
+
global_updates: globalUpdatesOps,
|
|
87
|
+
global_inserts: globalInsertsOps,
|
|
88
|
+
};
|
|
89
|
+
/// if threshold is below 0.8, then add the concept_fact to qdrant
|
|
90
|
+
/// if threshold is above 0.8, then replace the id of the local concept_fact with the id of the global concept_fact
|
|
91
|
+
/// add _source.id to qdrant
|
|
92
|
+
/// return the concepts_facts
|
|
93
|
+
}
|
|
94
|
+
}
|