only_ever_generator 1.0.3 → 1.0.5
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 +91 -0
- package/dist/bootstrap/app.d.ts.map +1 -0
- package/dist/bootstrap/app.js +120 -84
- package/dist/bootstrap/app.js.map +1 -0
- package/dist/card_gen/generate_cards.d.ts +7 -0
- package/dist/card_gen/generate_cards.d.ts.map +1 -0
- package/dist/card_gen/generate_cards.js +60 -0
- 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 +4 -1
- 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 +11 -0
- package/dist/constants/api_constants.js.map +1 -0
- package/dist/constants/prompt_data.d.ts +5 -0
- package/dist/constants/prompt_data.d.ts.map +1 -0
- package/dist/constants/prompt_data.js +303 -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 +100 -203
- 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 +78 -34
- package/dist/constants/prompts/typology_prompt.js.map +1 -0
- package/dist/constants/source_data.d.ts +173 -0
- package/dist/constants/source_data.d.ts.map +1 -0
- package/dist/constants/source_data.js +962 -10
- 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/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 +43 -0
- 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 +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +86 -149
- 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 +42 -0
- package/dist/logger.js.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts +10 -0
- package/dist/parse/parse_card/parse_cloze_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_cloze_card.js +126 -0
- package/dist/parse/parse_card/parse_cloze_card.js.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts +19 -0
- package/dist/parse/parse_card/parse_flash_cards.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_flash_cards.js +34 -0
- package/dist/parse/parse_card/parse_flash_cards.js.map +1 -0
- package/dist/parse/parse_card/parse_match_card.d.ts +16 -0
- package/dist/parse/parse_card/parse_match_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_match_card.js +82 -0
- package/dist/parse/parse_card/parse_match_card.js.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts +24 -0
- package/dist/parse/parse_card/parse_mcq_card.d.ts.map +1 -0
- package/dist/parse/parse_card/parse_mcq_card.js +104 -0
- 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.d.ts.map +1 -0
- package/dist/parse/parse_card_response.js +100 -0
- 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.d.ts.map +1 -0
- package/dist/parse/parse_source_content.js +186 -0
- package/dist/parse/parse_source_content.js.map +1 -0
- package/dist/parse/response_format_card.d.ts +177 -0
- package/dist/parse/response_format_card.d.ts.map +1 -0
- package/dist/parse/response_format_card.js +372 -0
- package/dist/parse/response_format_card.js.map +1 -0
- package/dist/parse/response_format_typology.d.ts +2 -0
- package/dist/parse/response_format_typology.d.ts.map +1 -0
- package/dist/{parse_response → parse}/response_format_typology.js +18 -18
- 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 +92 -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/typology-parsed-response.d.ts +62 -0
- package/dist/typology-parsed-response.d.ts.map +1 -0
- package/dist/typology-parsed-response.js +1936 -0
- package/dist/typology-parsed-response.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 +92 -15
- 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 +28 -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 +11 -10
- package/dist/utils/parse_openai_response.js.map +1 -0
- package/package.json +19 -7
- package/prompts.json +23 -0
- package/readme.md +16 -13
- package/src/bootstrap/app.ts +167 -107
- package/src/card_gen/generate_cards.ts +58 -0
- package/src/config.ts +5 -3
- package/src/constants/api_constants.ts +7 -0
- package/src/constants/prompt_data.ts +301 -0
- package/src/constants/prompts/card_gen_prompt.ts +101 -208
- package/src/constants/prompts/typology_prompt.ts +81 -33
- package/src/constants/source_data.ts +1029 -23
- 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/gap_fill/calculate_gap_fill.ts +50 -0
- package/src/helper/qdrant_db_methods.ts +77 -0
- package/src/index.ts +98 -164
- package/src/logger.ts +30 -0
- package/src/parse/parse_card/parse_cloze_card.ts +136 -0
- package/src/parse/parse_card/parse_flash_cards.ts +33 -0
- package/src/parse/parse_card/parse_match_card.ts +94 -0
- package/src/parse/parse_card/parse_mcq_card.ts +105 -0
- package/src/parse/parse_card_response.ts +117 -0
- package/src/parse/parse_source_content.ts +202 -0
- package/src/parse/response_format_card.ts +386 -0
- package/src/parse/response_format_typology.ts +44 -0
- package/src/services/open_ai_service.ts +88 -0
- package/src/services/qdrant_service.ts +10 -0
- package/src/typology-parsed-response.ts +1932 -0
- package/src/typology_gen/generate_typology.ts +101 -12
- package/src/utils/generate_args.ts +29 -0
- package/src/utils/parse_openai_response.ts +17 -19
- package/tsconfig.json +8 -3
- package/dist/class/parse/parse_source_content.js +0 -62
- package/dist/class/services/open_ai_service.js +0 -25
- package/dist/parse_response/response_format_card.js +0 -210
- package/dist/service/open_ai_request.js +0 -58
- package/src/class/parse/parse_source_content.ts +0 -71
- package/src/class/services/open_ai_service.ts +0 -18
- package/src/parse_response/response_format_card.ts +0 -211
- package/src/parse_response/response_format_typology.ts +0 -44
- package/src/service/open_ai_request.ts +0 -46
package/readme.md
CHANGED
|
@@ -8,25 +8,28 @@ The class [OnlyEverGenerator] is the Entry point for the generation module it ha
|
|
|
8
8
|
|
|
9
9
|
The [OnlyEverGenerator] currently exposes a main method, [generate] which handles all types of generation and takes a Param
|
|
10
10
|
```
|
|
11
|
-
|
|
11
|
+
generate(generate_typology = false,generate_card = false) method takes two args, generate_typology and generate_cards, which are both boolean.
|
|
12
12
|
For Eg:
|
|
13
13
|
let oeGenerator = new OnlyEverGenerator(
|
|
14
14
|
api_key,
|
|
15
15
|
model,
|
|
16
16
|
[Block1,Block2,Block3], // oe content model
|
|
17
17
|
);
|
|
18
|
-
|
|
19
|
-
true,
|
|
20
|
-
true,
|
|
21
|
-
false,
|
|
22
|
-
{
|
|
23
|
-
typology_prompt: typologyPrompt,
|
|
24
|
-
card_gen_prompt: cardPrompt,
|
|
25
|
-
summary_prompt: summary prompt,
|
|
26
|
-
}
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
let responsesArray = await oeGenerator.generate(args);
|
|
18
|
+
|
|
30
19
|
|
|
20
|
+
let responsesArray = await oeGenerator.generate(true,true);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
Exposed a new method ```gapFill``` from OnlyEverGenerator
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
async gapFill(factsMaps: any, aiCards: Array<any>) {}
|
|
27
|
+
/// factsmap
|
|
28
|
+
/// {
|
|
29
|
+
/// remaining_facts: [],
|
|
30
|
+
/// remaining_concepts: [],
|
|
31
|
+
//}
|
|
32
|
+
|
|
33
|
+
/// aicards is array of ai cards
|
|
31
34
|
|
|
32
35
|
```
|
package/src/bootstrap/app.ts
CHANGED
|
@@ -1,107 +1,167 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
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
|
+
|
|
11
|
+
export class OnlyEverGenerator {
|
|
12
|
+
public api_key: string = "";
|
|
13
|
+
public openAiService: OpenAiService;
|
|
14
|
+
|
|
15
|
+
/// these fields will be populated inside the constructor
|
|
16
|
+
parsedContent: any = {};
|
|
17
|
+
promptForTypology: string = "";
|
|
18
|
+
promptForCardGen: string = "";
|
|
19
|
+
expectedFields: Array<string>;
|
|
20
|
+
|
|
21
|
+
typologyResponse: any = undefined;
|
|
22
|
+
cardgenResponse: any = undefined;
|
|
23
|
+
summarizeResponse = {};
|
|
24
|
+
gapFillResponse: any = {};
|
|
25
|
+
|
|
26
|
+
constructor(apiKey: string, model: string, generationContent: any) {
|
|
27
|
+
this.api_key = apiKey;
|
|
28
|
+
this.openAiService = new OpenAiService(
|
|
29
|
+
apiKey,
|
|
30
|
+
model ?? "gpt-3.5-turbo-1106"
|
|
31
|
+
);
|
|
32
|
+
const parsedData = new ParseSourceContent(
|
|
33
|
+
generationContent.content
|
|
34
|
+
).parseData();
|
|
35
|
+
(this.parsedContent = {
|
|
36
|
+
title: parsedData.title,
|
|
37
|
+
headings: parsedData.headings,
|
|
38
|
+
content: parsedData.content,
|
|
39
|
+
taxonomy: parsedData.taxonomy,
|
|
40
|
+
}),
|
|
41
|
+
(this.typologyResponse = generationContent.content.taxonomy);
|
|
42
|
+
|
|
43
|
+
this.expectedFields = generationContent.content.fields; //returnFields();
|
|
44
|
+
this.promptForTypology = generationContent.prompt.typology;
|
|
45
|
+
this.promptForCardGen = generationContent.prompt.card_generation;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async generate(
|
|
49
|
+
generate_typology: boolean = false,
|
|
50
|
+
generate_card: boolean = false
|
|
51
|
+
): Promise<Array<any>> {
|
|
52
|
+
let args = new GenerateArgs(generate_card, generate_typology, false);
|
|
53
|
+
const responseToReturn = [];
|
|
54
|
+
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
55
|
+
for (let elem of whatNeedsToBeGenerated)
|
|
56
|
+
if (elem == "generate_tyopology") {
|
|
57
|
+
this.typologyResponse = await this.generateTypology(
|
|
58
|
+
this.promptForTypology
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const embeddings = await this.generateEmbeddings(this.typologyResponse);
|
|
62
|
+
this.typologyResponse.concepts_facts = embeddings.concepts_facts;
|
|
63
|
+
this.typologyResponse.metadata.push(embeddings.metadata);
|
|
64
|
+
responseToReturn.push(this.typologyResponse);
|
|
65
|
+
} else if (elem == "generate_card") {
|
|
66
|
+
if (this.shouldTheCardBeGeneratedAfterTypologyResponse()) {
|
|
67
|
+
this.parsedContent.taxonomy = {
|
|
68
|
+
concepts_facts: this.typologyResponse.concepts_facts,
|
|
69
|
+
generate_cards: this.typologyResponse.generate_cards,
|
|
70
|
+
};
|
|
71
|
+
this.cardgenResponse = await this.generateCard(
|
|
72
|
+
this.promptForCardGen,
|
|
73
|
+
JSON.stringify(this.typologyResponse),
|
|
74
|
+
false
|
|
75
|
+
);
|
|
76
|
+
responseToReturn.push(this.cardgenResponse);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
return responseToReturn;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
shouldTheCardBeGeneratedAfterTypologyResponse() {
|
|
83
|
+
if (this.typologyResponse) {
|
|
84
|
+
return this.typologyResponse?.generate_cards?.state == true;
|
|
85
|
+
} else {
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
async generateCard(
|
|
91
|
+
prompt: string,
|
|
92
|
+
additionalContent: string,
|
|
93
|
+
isGapFill: boolean,
|
|
94
|
+
n: number = 0
|
|
95
|
+
) {
|
|
96
|
+
let generateCardsResp = await new GenerateCards(
|
|
97
|
+
this.openAiService
|
|
98
|
+
).generateCards(
|
|
99
|
+
prompt ?? "",
|
|
100
|
+
JSON.stringify(this.parsedContent) + additionalContent,
|
|
101
|
+
isGapFill,
|
|
102
|
+
this.parsedContent.taxonomy,
|
|
103
|
+
n
|
|
104
|
+
);
|
|
105
|
+
return generateCardsResp;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async generateTypology(prompt: string) {
|
|
109
|
+
let response = await new GenerateTypology(
|
|
110
|
+
this.openAiService,
|
|
111
|
+
prompt,
|
|
112
|
+
JSON.stringify(this.parsedContent),
|
|
113
|
+
this.expectedFields
|
|
114
|
+
).generate();
|
|
115
|
+
return response;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
async generateEmbeddings(typologyResponse: any) {
|
|
119
|
+
const concepts_facts = typologyResponse.concepts_facts;
|
|
120
|
+
const texts = concepts_facts.map((e: any) => e.text);
|
|
121
|
+
const embeddings = await new GenerateEmbeddings(
|
|
122
|
+
this.openAiService
|
|
123
|
+
).generateEmbeddings(concepts_facts);
|
|
124
|
+
return embeddings;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
async localConsolidation(
|
|
128
|
+
concepts_facts: {
|
|
129
|
+
text: string;
|
|
130
|
+
type: string;
|
|
131
|
+
reference: string;
|
|
132
|
+
embedding: number[];
|
|
133
|
+
}[],
|
|
134
|
+
sourceId: string
|
|
135
|
+
) {
|
|
136
|
+
const embeddings = new LocalConsolidation().consolidate(
|
|
137
|
+
concepts_facts,
|
|
138
|
+
sourceId
|
|
139
|
+
);
|
|
140
|
+
return embeddings;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async globalConsolidation(
|
|
144
|
+
concepts_facts: {
|
|
145
|
+
id: string;
|
|
146
|
+
text: string;
|
|
147
|
+
type: string;
|
|
148
|
+
reference: string;
|
|
149
|
+
embedding: number[];
|
|
150
|
+
}[],
|
|
151
|
+
sourceId: string,
|
|
152
|
+
threshold: number
|
|
153
|
+
) {
|
|
154
|
+
const embeddings = await new GlobalConsolidation().consolidate(
|
|
155
|
+
concepts_facts,
|
|
156
|
+
sourceId,
|
|
157
|
+
threshold ?? 0.8
|
|
158
|
+
);
|
|
159
|
+
// const writeConsolidatedData =
|
|
160
|
+
// new WriteConsolidatedData().writeConsolidatedData(
|
|
161
|
+
// embeddings,
|
|
162
|
+
// [],
|
|
163
|
+
// sourceId
|
|
164
|
+
// );
|
|
165
|
+
return embeddings;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { ErrorLogger } from "../logger";
|
|
2
|
+
import { ParseCardResponse } from "../parse/parse_card_response";
|
|
3
|
+
import { OpenAiService } from "../services/open_ai_service";
|
|
4
|
+
|
|
5
|
+
export class GenerateCards {
|
|
6
|
+
openAiService: OpenAiService;
|
|
7
|
+
constructor(openAiService: OpenAiService) {
|
|
8
|
+
this.openAiService = openAiService;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async generateCards(
|
|
12
|
+
prompt: string,
|
|
13
|
+
parsedContent: string,
|
|
14
|
+
isGapFill: boolean,
|
|
15
|
+
taxonomy: any,
|
|
16
|
+
n: number = 0
|
|
17
|
+
) {
|
|
18
|
+
try {
|
|
19
|
+
let response = await this.openAiService?.sendRequest(
|
|
20
|
+
prompt,
|
|
21
|
+
parsedContent
|
|
22
|
+
);
|
|
23
|
+
var updatedNumber = n + 1;
|
|
24
|
+
// console.log("response to card generation ", response);
|
|
25
|
+
// response["request_type"] = ;
|
|
26
|
+
response.metadata = {
|
|
27
|
+
req_time: response.generated_at ?? new Date(),
|
|
28
|
+
req_type: {
|
|
29
|
+
type: "depth",
|
|
30
|
+
n: updatedNumber,
|
|
31
|
+
bloom_level: 1,
|
|
32
|
+
},
|
|
33
|
+
req_tokens: response.usage_data?.prompt_tokens,
|
|
34
|
+
res_tokens: response.usage_data?.completion_tokens,
|
|
35
|
+
prompt_tokens_details: response.usage_data?.prompt_tokens_details,
|
|
36
|
+
model: this.openAiService.model,
|
|
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
|
+
);
|
|
45
|
+
return parseCard;
|
|
46
|
+
} else {
|
|
47
|
+
response.metadata.status = "failed";
|
|
48
|
+
response.metadata.err_message = response.message;
|
|
49
|
+
return response;
|
|
50
|
+
}
|
|
51
|
+
} catch (e: any) {
|
|
52
|
+
new ErrorLogger({
|
|
53
|
+
type: "card_generation",
|
|
54
|
+
data: e.message,
|
|
55
|
+
}).log();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
package/src/config.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import "dotenv/config";
|
|
2
2
|
|
|
3
3
|
const config = {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
openAIKey: process.env.OPEN_AI_KEY as string,
|
|
5
|
+
qdrantApiKey: process.env.QDRANT_API_KEY,
|
|
6
|
+
qdrantUrl: process.env.QDRANT_URL,
|
|
7
|
+
};
|
|
6
8
|
|
|
7
|
-
export default config;
|
|
9
|
+
export default config;
|