only_ever_generator 0.2.7 → 0.2.8
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/card_gen/generate_cards.js +1 -0
- package/dist/constants/prompt_data.js +273 -273
- package/dist/constants/prompts/card_gen_prompt.js +180 -180
- package/dist/constants/prompts/typology_prompt.js +93 -93
- package/package.json +33 -33
- package/readme.md +23 -23
- package/src/bootstrap/app.ts +150 -154
- package/src/card_gen/generate_cards.ts +251 -251
- package/src/config.ts +6 -6
- package/src/constants/api_constants.ts +2 -2
- package/src/constants/prompt_data.ts +296 -296
- package/src/constants/prompts/card_gen_prompt.ts +372 -372
- package/src/constants/prompts/typology_prompt.ts +202 -202
- package/src/constants/source_data.ts +47 -47
- package/src/gap_fill/calculate_gap_fill.ts +52 -52
- package/src/index.ts +61 -61
- package/src/logger.ts +30 -30
- package/src/parse/parse_card_response.ts +289 -289
- package/src/parse/parse_source_content.ts +94 -94
- 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 +55 -55
- package/src/typology_gen/generate_typology.ts +71 -71
- package/src/utils/generate_args.ts +28 -28
- package/src/utils/parse_openai_response.ts +20 -20
- package/tsconfig.json +12 -12
- package/dist/class/parse/parse_source_content.js +0 -62
- package/dist/class/services/open_ai_service.js +0 -25
- package/dist/parse_response/parse_card_response.js +0 -288
- package/dist/parse_response/response_format_card.js +0 -210
- package/dist/parse_response/response_format_typology.js +0 -47
- package/dist/service/open_ai_request.js +0 -57
package/readme.md
CHANGED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
This is a NPM package that handles the all the ai generation for _source on OnlyEver.
|
|
2
|
-
The Generation includes, Knowledge Taxonomy , Summary and Test Cards data for the _source.
|
|
3
|
-
|
|
4
|
-
The class [OnlyEverGenerator] is the Entry point for the generation module it has two required fields,
|
|
5
|
-
[api_key] which is open ai token
|
|
6
|
-
[model] open ai model : 'gpt-3.5-turbo-1106'
|
|
7
|
-
[content] source content : Array<BaseBlocks>
|
|
8
|
-
|
|
9
|
-
The [OnlyEverGenerator] currently exposes a main method, [generate] which handles all types of generation and takes a Param
|
|
10
|
-
```
|
|
11
|
-
generate(generate_typology = false,generate_card = false) method takes two args, generate_typology and generate_cards, which are both boolean.
|
|
12
|
-
For Eg:
|
|
13
|
-
let oeGenerator = new OnlyEverGenerator(
|
|
14
|
-
api_key,
|
|
15
|
-
model,
|
|
16
|
-
[Block1,Block2,Block3], // oe content model
|
|
17
|
-
);
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
let responsesArray = await oeGenerator.generate(true,true);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
```
|
|
1
|
+
This is a NPM package that handles the all the ai generation for _source on OnlyEver.
|
|
2
|
+
The Generation includes, Knowledge Taxonomy , Summary and Test Cards data for the _source.
|
|
3
|
+
|
|
4
|
+
The class [OnlyEverGenerator] is the Entry point for the generation module it has two required fields,
|
|
5
|
+
[api_key] which is open ai token
|
|
6
|
+
[model] open ai model : 'gpt-3.5-turbo-1106'
|
|
7
|
+
[content] source content : Array<BaseBlocks>
|
|
8
|
+
|
|
9
|
+
The [OnlyEverGenerator] currently exposes a main method, [generate] which handles all types of generation and takes a Param
|
|
10
|
+
```
|
|
11
|
+
generate(generate_typology = false,generate_card = false) method takes two args, generate_typology and generate_cards, which are both boolean.
|
|
12
|
+
For Eg:
|
|
13
|
+
let oeGenerator = new OnlyEverGenerator(
|
|
14
|
+
api_key,
|
|
15
|
+
model,
|
|
16
|
+
[Block1,Block2,Block3], // oe content model
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
let responsesArray = await oeGenerator.generate(true,true);
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
```
|
package/src/bootstrap/app.ts
CHANGED
|
@@ -1,154 +1,150 @@
|
|
|
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 {
|
|
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
|
-
apiKey
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
this.
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
}
|
|
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 { gapFilling } from "../gap_fill/calculate_gap_fill";
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
/// OnlyEverGenerator
|
|
12
|
+
|
|
13
|
+
export class OnlyEverGenerator {
|
|
14
|
+
public api_key: string = "";
|
|
15
|
+
public openAiService: OpenAiService;
|
|
16
|
+
|
|
17
|
+
/// these fields will be populated inside the constructor
|
|
18
|
+
parsedContent: any = {};
|
|
19
|
+
promptForTypology: string = "";
|
|
20
|
+
promptForCardGen: string = "";
|
|
21
|
+
expectedFields: Array<string>;
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
typologyResponse: any = {};
|
|
25
|
+
cardgenResponse: any = {};
|
|
26
|
+
summarizeResponse = {};
|
|
27
|
+
gapFillResponse: any = {};
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
constructor(
|
|
31
|
+
apiKey: string,
|
|
32
|
+
model: string,
|
|
33
|
+
generationContent : any
|
|
34
|
+
) {
|
|
35
|
+
this.api_key = apiKey;
|
|
36
|
+
this.openAiService = new OpenAiService(
|
|
37
|
+
apiKey,
|
|
38
|
+
model ?? "gpt-3.5-turbo-1106"
|
|
39
|
+
);
|
|
40
|
+
const parsedData = new ParseSourceContent(generationContent.content).parseData()
|
|
41
|
+
this.parsedContent = {
|
|
42
|
+
title: parsedData.title,
|
|
43
|
+
headings: parsedData.headings,
|
|
44
|
+
content: parsedData.content,
|
|
45
|
+
|
|
46
|
+
},
|
|
47
|
+
// parsedData.type == 'cards' ? this.typologyResponse = parsedData.taxonomy : this.typologyResponse = null;
|
|
48
|
+
this.typologyResponse = parsedData.taxonomy
|
|
49
|
+
|
|
50
|
+
this.expectedFields = generationContent.content.fields; //returnFields();
|
|
51
|
+
this.promptForTypology = returnTypologyPrompt(generationContent.prompt.typology);
|
|
52
|
+
this.promptForCardGen = returnCardGenPrompt(generationContent.prompt.card_generation);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
async generate(
|
|
58
|
+
generate_typology: boolean = false,
|
|
59
|
+
generate_card: boolean = false
|
|
60
|
+
): Promise<Array<any>> {
|
|
61
|
+
let args = new GenerateArgs(generate_card, generate_typology, false, );
|
|
62
|
+
const responseToReturn = [];
|
|
63
|
+
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
64
|
+
for (let elem of whatNeedsToBeGenerated)
|
|
65
|
+
if (elem == "generate_tyopology") {
|
|
66
|
+
this.typologyResponse = await this.generateTypology(
|
|
67
|
+
this.promptForTypology
|
|
68
|
+
);
|
|
69
|
+
responseToReturn.push(this.typologyResponse);
|
|
70
|
+
} else if (elem == "generate_card") {
|
|
71
|
+
/// for cards gen to occur, there must be presence of source taxonomy
|
|
72
|
+
if(this.shouldTheCardBeGeneratedAfterTypologyResponse()){
|
|
73
|
+
this.cardgenResponse = await this.generateCard(
|
|
74
|
+
this.promptForCardGen,
|
|
75
|
+
JSON.stringify(this.typologyResponse),
|
|
76
|
+
false,
|
|
77
|
+
)
|
|
78
|
+
responseToReturn.push(this.cardgenResponse);
|
|
79
|
+
|
|
80
|
+
/// check if gap fill is required ie coverage determination
|
|
81
|
+
if(this.cardgenResponse.status_code == 200) {
|
|
82
|
+
this.gapFillResponse = await this.generationForGapFill(this.typologyResponse, this.cardgenResponse);
|
|
83
|
+
responseToReturn.push(this.gapFillResponse);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return responseToReturn;
|
|
89
|
+
// return [typologyPrompt, cardPrompt];
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
shouldTheCardBeGeneratedAfterTypologyResponse(){
|
|
94
|
+
if(this.typologyResponse){
|
|
95
|
+
return this.typologyResponse.generate_cards.state == true;
|
|
96
|
+
}else{
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async generationForGapFill(typologyData: any, cardGenData: any) {
|
|
103
|
+
let gapFill = gapFilling(typologyData, cardGenData);
|
|
104
|
+
let response :any ;
|
|
105
|
+
if (
|
|
106
|
+
gapFill.remainingConcepts.length !== 0 ||
|
|
107
|
+
gapFill.remainingFacts.length !== 0
|
|
108
|
+
) {
|
|
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
|
+
"Exclude generating these cards",
|
|
114
|
+
JSON.stringify(cardGenData.cards_data),
|
|
115
|
+
true
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
return response;
|
|
119
|
+
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
async generateCard(prompt: string, additionalContent: string, isGapFill: boolean) {
|
|
125
|
+
let generateCards = new GenerateCards(this.openAiService);
|
|
126
|
+
this.cardgenResponse = await generateCards.generateCards(
|
|
127
|
+
prompt ?? "",
|
|
128
|
+
this.parsedContent + additionalContent,
|
|
129
|
+
isGapFill
|
|
130
|
+
);
|
|
131
|
+
|
|
132
|
+
// let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
133
|
+
// response['type'] = 'card_gen';
|
|
134
|
+
return this.cardgenResponse;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
async generateTypology(prompt: string) {
|
|
139
|
+
let response = await new GenerateTypology(
|
|
140
|
+
this.openAiService,
|
|
141
|
+
prompt,
|
|
142
|
+
JSON.stringify(this.parsedContent),
|
|
143
|
+
this.expectedFields
|
|
144
|
+
).generate();
|
|
145
|
+
return response;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
}
|