only_ever_generator 0.1.5 → 0.1.6
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.js +8 -45
- package/dist/constants/prompts/card_gen_prompt.js +170 -170
- package/dist/constants/prompts/typology_prompt.js +89 -89
- package/dist/gap_fill/calculate_gap_fill.js +42 -0
- package/dist/index.js +54 -49
- package/dist/service/open_ai_request.js +57 -57
- package/package.json +33 -33
- package/readme.md +23 -23
- package/src/bootstrap/app.ts +128 -165
- package/src/card_gen/generate_cards.ts +197 -197
- package/src/config.ts +6 -6
- package/src/constants/api_constants.ts +2 -2
- package/src/constants/prompts/card_gen_prompt.ts +177 -177
- package/src/constants/prompts/typology_prompt.ts +93 -93
- package/src/constants/source_data.ts +35 -35
- package/src/gap_fill/calculate_gap_fill.ts +48 -0
- package/src/index.ts +66 -66
- package/src/parse/parse_card_response.ts +289 -289
- package/src/parse/parse_source_content.ts +70 -70
- package/src/parse/response_format_card.ts +210 -210
- package/src/parse/response_format_typology.ts +43 -43
- package/src/services/open_ai_service.ts +54 -54
- package/src/typology_gen/generate_typology.ts +64 -64
- package/src/utils/generate_args.ts +37 -37
- package/src/utils/parse_openai_response.ts +20 -20
- package/tsconfig.json +12 -12
package/src/bootstrap/app.ts
CHANGED
|
@@ -1,165 +1,128 @@
|
|
|
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 { returnCardGenPrompt } from "../constants/prompts/card_gen_prompt";
|
|
5
|
-
import { returnTypologyPrompt } from "../constants/prompts/typology_prompt";
|
|
6
|
-
import { GenerateTypology } from "../typology_gen/generate_typology";
|
|
7
|
-
import { GenerateArgs } from "../utils/generate_args";
|
|
8
|
-
import { returnFields } from "../constants/source_data";
|
|
9
|
-
import { returnTypologyData } from "../parse/response_format_typology";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
public
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
);
|
|
32
|
-
this.
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
let
|
|
46
|
-
let
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
);
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
allFacts.push(...(this.typologyResponse?.facts ?? []));
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
if (!isEmpty(this.cardgenResponse)) {
|
|
133
|
-
allConcepts.push(...(this.cardgenResponse.missing_concepts ?? []));
|
|
134
|
-
allFacts.push(...(this.cardgenResponse.missing_facts ?? []));
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
for (let card of this.cardgenResponse.cards_data) {
|
|
138
|
-
if (card.concepts.length != 0) {
|
|
139
|
-
generatedConceptsList.push(...card.concepts);
|
|
140
|
-
}
|
|
141
|
-
if (card.facts.length != 0) {
|
|
142
|
-
generatedFactsList.push(...card.facts);
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
let generatedConceptsSet = Array.from(new Set(generatedConceptsList));
|
|
147
|
-
let generatedFactsSet = Array.from(new Set(generatedFactsList));
|
|
148
|
-
|
|
149
|
-
let remainingConcepts: string[] = allConcepts.filter(
|
|
150
|
-
(item) => !generatedConceptsSet.includes(item)
|
|
151
|
-
);
|
|
152
|
-
let remainingFacts: string[] = allFacts.filter(
|
|
153
|
-
(item) => !generatedFactsSet.includes(item)
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
return {
|
|
157
|
-
// allConcepts: allConcepts,
|
|
158
|
-
// allFacts: allFacts,
|
|
159
|
-
// generatedConcepts: generatedConceptsSet,
|
|
160
|
-
// generatedFacts: generatedFactsSet,
|
|
161
|
-
remainingConcepts: remainingConcepts,
|
|
162
|
-
remainingFacts: remainingFacts,
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
}
|
|
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 { returnCardGenPrompt } from "../constants/prompts/card_gen_prompt";
|
|
5
|
+
import { returnTypologyPrompt } from "../constants/prompts/typology_prompt";
|
|
6
|
+
import { GenerateTypology } from "../typology_gen/generate_typology";
|
|
7
|
+
import { GenerateArgs } from "../utils/generate_args";
|
|
8
|
+
import { returnFields } from "../constants/source_data";
|
|
9
|
+
import { returnTypologyData } from "../parse/response_format_typology";
|
|
10
|
+
import { gapFilling } from "../gap_fill/calculate_gap_fill";
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
/// OnlyEverGenerator
|
|
14
|
+
|
|
15
|
+
export class OnlyEverGenerator {
|
|
16
|
+
public api_key: string = "";
|
|
17
|
+
public openAiService: OpenAiService;
|
|
18
|
+
parsedContent: string = "";
|
|
19
|
+
expectedFields: Array<string>;
|
|
20
|
+
constructor(
|
|
21
|
+
apiKey: string,
|
|
22
|
+
model: string,
|
|
23
|
+
content: Array<any>,
|
|
24
|
+
expected_fields: Array<string>
|
|
25
|
+
) {
|
|
26
|
+
this.api_key = apiKey;
|
|
27
|
+
this.openAiService = new OpenAiService(
|
|
28
|
+
apiKey,
|
|
29
|
+
model ?? "gpt-3.5-turbo-1106"
|
|
30
|
+
);
|
|
31
|
+
this.parsedContent = new ParseSourceContent(content).parse();
|
|
32
|
+
this.expectedFields = returnFields();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
typologyResponse: any = {};
|
|
36
|
+
cardgenResponse: any = {};
|
|
37
|
+
summarizeResponse = {};
|
|
38
|
+
gapFillResponse: any = {};
|
|
39
|
+
|
|
40
|
+
async generate(
|
|
41
|
+
generate_typology: boolean = false,
|
|
42
|
+
generate_card: boolean = false
|
|
43
|
+
): Promise<Array<any>> {
|
|
44
|
+
let typologyPrompt = returnTypologyPrompt();
|
|
45
|
+
let cardPrompt = returnCardGenPrompt();
|
|
46
|
+
let args = new GenerateArgs(generate_card, generate_typology, false, {
|
|
47
|
+
typology_prompt: typologyPrompt,
|
|
48
|
+
card_gen_prompt: cardPrompt,
|
|
49
|
+
summary_prompt: "",
|
|
50
|
+
});
|
|
51
|
+
const responseToReturn = [];
|
|
52
|
+
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
53
|
+
for (let elem of whatNeedsToBeGenerated)
|
|
54
|
+
if (elem == "generate_tyopology") {
|
|
55
|
+
this.typologyResponse = await this.generateTypology(
|
|
56
|
+
args.prompts.typology_prompt ?? ""
|
|
57
|
+
);
|
|
58
|
+
responseToReturn.push(this.typologyResponse);
|
|
59
|
+
} else if (elem == "generate_card") {
|
|
60
|
+
if(this.typologyResponse.generate_cards){
|
|
61
|
+
if(this.typologyResponse.generate_cards.state == false){
|
|
62
|
+
console.log('Cards Generation Not Required');
|
|
63
|
+
}else{
|
|
64
|
+
this.cardgenResponse = await this.generateCard(
|
|
65
|
+
args.prompts.card_gen_prompt ?? "",
|
|
66
|
+
this.parsedContent + JSON.stringify(this.typologyResponse),
|
|
67
|
+
false
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
else{
|
|
73
|
+
this.cardgenResponse = await this.generateCard(
|
|
74
|
+
args.prompts.card_gen_prompt ?? "",
|
|
75
|
+
this.parsedContent,
|
|
76
|
+
false
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
responseToReturn.push(this.cardgenResponse);
|
|
81
|
+
}
|
|
82
|
+
if (this.cardgenResponse.status_code == 200) {
|
|
83
|
+
let gapFill = gapFilling(this.typologyResponse, this.cardgenResponse);
|
|
84
|
+
if (
|
|
85
|
+
gapFill.remainingConcepts.length !== 0 ||
|
|
86
|
+
gapFill.remainingFacts.length !== 0
|
|
87
|
+
) {
|
|
88
|
+
this.gapFillResponse = await this.generateCard(
|
|
89
|
+
args.prompts.card_gen_prompt ?? "",
|
|
90
|
+
this.parsedContent +
|
|
91
|
+
"Generate cards only suitable for the given remaining concepts and facts" +
|
|
92
|
+
JSON.stringify(gapFill) +
|
|
93
|
+
"Exclude generating these cards" +
|
|
94
|
+
JSON.stringify(this.cardgenResponse.cards_data),
|
|
95
|
+
true
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
responseToReturn.push(this.gapFillResponse);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return responseToReturn;
|
|
102
|
+
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
async generateCard(prompt: string, content: string, isGapFill: boolean) {
|
|
106
|
+
let generateCards = new GenerateCards(this.openAiService);
|
|
107
|
+
let cardgenResponse = await generateCards.generateCards(
|
|
108
|
+
prompt ?? "",
|
|
109
|
+
content,
|
|
110
|
+
isGapFill
|
|
111
|
+
);
|
|
112
|
+
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
113
|
+
// response['type'] = 'card_gen';
|
|
114
|
+
return cardgenResponse;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async generateTypology(prompt: string) {
|
|
118
|
+
let response = await new GenerateTypology(
|
|
119
|
+
this.openAiService,
|
|
120
|
+
prompt,
|
|
121
|
+
this.parsedContent,
|
|
122
|
+
this.expectedFields
|
|
123
|
+
).generate();
|
|
124
|
+
return response;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
}
|