only_ever_generator 1.0.0 → 1.0.2
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 +72 -3
- package/dist/class/parse/parse_source_content.js +62 -0
- package/dist/class/services/open_ai_service.js +3 -2
- package/dist/constants/prompts/card_gen_prompt.js +247 -53
- package/dist/constants/prompts/typology_prompt.js +12 -13
- package/dist/constants/source_data.js +1 -3
- package/dist/index.js +103 -25
- package/dist/service/open_ai_request.js +3 -4
- package/dist/utils/parse_openai_response.js +10 -1
- package/package.json +2 -2
- package/readme.md +32 -0
- package/src/bootstrap/app.ts +89 -4
- package/src/class/parse/parse_source_content.ts +71 -0
- package/src/class/services/open_ai_service.ts +4 -2
- package/src/constants/prompts/card_gen_prompt.ts +249 -55
- package/src/constants/prompts/typology_prompt.ts +12 -13
- package/src/constants/source_data.ts +2 -2
- package/src/index.ts +134 -25
- package/src/service/open_ai_request.ts +5 -6
- package/src/utils/parse_openai_response.ts +11 -0
package/src/index.ts
CHANGED
|
@@ -1,32 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
// import { returnTypologyPrompt } from './constants/prompts/typology_prompt.js';
|
|
7
|
-
// // import { generateTypology } from './typology_gen/generate_typology.ts';
|
|
8
|
-
// import {OpenAiService} from './class/services/open_ai_service.js';
|
|
9
|
-
// import config from './config.js';
|
|
10
|
-
// import { generateTypology } from './typology_gen/generate_typology.js';
|
|
11
|
-
// import { OnlyEverGenerator } from './bootstrap/app.js';
|
|
1
|
+
|
|
2
|
+
import { ParseSourceContent } from "./class/parse/parse_source_content";
|
|
3
|
+
import { OpenAiService } from "./class/services/open_ai_service";
|
|
4
|
+
import { returnCardGenPrompt } from "./constants/prompts/card_gen_prompt";
|
|
5
|
+
import { returnTypologyPrompt } from "./constants/prompts/typology_prompt";
|
|
12
6
|
// const app = express();
|
|
13
7
|
// const port = 3000;
|
|
14
8
|
// let openAiService = new OpenAiService(config.openAIKey);
|
|
15
9
|
|
|
16
|
-
import { OpenAiService } from "./class/services/open_ai_service";
|
|
17
10
|
|
|
18
|
-
// let oeGen = new OnlyEverGenerator(config.openAIKey)
|
|
19
|
-
// app.get('/', async (req, res) => {
|
|
20
11
|
|
|
21
|
-
//
|
|
22
|
-
//
|
|
12
|
+
// let oeGen = new OnlyEverGenerator(config.openAIKey, returnSourceData())
|
|
13
|
+
// app.get('/', async (req, res) => {
|
|
14
|
+
// let data = oeGen.returnParsedContent();
|
|
15
|
+
// // let parsedData = parseResponse()
|
|
16
|
+
// res.send(data);
|
|
23
17
|
// });
|
|
24
18
|
|
|
25
19
|
// app.get('/openAI', async (req,res)=> {
|
|
26
20
|
// // let prompt = returnPromt();
|
|
27
21
|
|
|
28
22
|
// let prompt = returnCardGenPrompt();
|
|
29
|
-
// let content = returnSourceData()
|
|
23
|
+
// let content = returnSourceData().toString()
|
|
30
24
|
// let headings = returnHeadings();
|
|
31
25
|
// // let aiRequest = await openAIRequest(prompt,content);
|
|
32
26
|
// let aiRequest = await oeGen.generateCard(prompt,content);
|
|
@@ -36,8 +30,20 @@ import { OpenAiService } from "./class/services/open_ai_service";
|
|
|
36
30
|
// app.get('/typology', async(req,res)=>{
|
|
37
31
|
// {
|
|
38
32
|
// let typologyPrompt = returnTypologyPrompt();
|
|
39
|
-
// let
|
|
40
|
-
// let
|
|
33
|
+
// let cardPrompt = returnCardGenPrompt();
|
|
34
|
+
// let args = new GenerateArgs(
|
|
35
|
+
// true,
|
|
36
|
+
// true,
|
|
37
|
+
// false,
|
|
38
|
+
// {
|
|
39
|
+
// typology_prompt: typologyPrompt,
|
|
40
|
+
// card_gen_prompt: cardPrompt,
|
|
41
|
+
// summary_prompt: "",
|
|
42
|
+
// }
|
|
43
|
+
// )
|
|
44
|
+
// let typologyRequest = await oeGen.generate(
|
|
45
|
+
// args,
|
|
46
|
+
// );
|
|
41
47
|
// res.send(typologyRequest);
|
|
42
48
|
|
|
43
49
|
// }
|
|
@@ -51,20 +57,123 @@ import { OpenAiService } from "./class/services/open_ai_service";
|
|
|
51
57
|
|
|
52
58
|
|
|
53
59
|
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
54
64
|
export class OnlyEverGenerator{
|
|
55
65
|
public api_key: string = '';
|
|
56
66
|
public openAiService: OpenAiService | undefined;
|
|
57
|
-
|
|
58
|
-
constructor(apiKey:string){
|
|
67
|
+
parsedContent: String = '';
|
|
68
|
+
constructor(apiKey:string, model: String, content: Array<any>){
|
|
59
69
|
this.api_key = apiKey;
|
|
60
|
-
this.openAiService = new OpenAiService(apiKey);
|
|
70
|
+
this.openAiService = new OpenAiService(apiKey,model ?? 'gpt-3.5-turbo-1106');
|
|
71
|
+
this.parsedContent = new ParseSourceContent(content).parse();
|
|
61
72
|
};
|
|
62
73
|
|
|
74
|
+
typologyResponse = {};
|
|
75
|
+
cardgenResponse = {};
|
|
76
|
+
summarizeResponse = {};
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
async generate(
|
|
82
|
+
generate_card : boolean = false,
|
|
83
|
+
generate_typology: boolean =false,
|
|
84
|
+
): Promise<Array<any>> {
|
|
85
|
+
let typologyPrompt = returnTypologyPrompt();
|
|
86
|
+
let cardPrompt = returnCardGenPrompt();
|
|
87
|
+
let args = new GenerateArgs(
|
|
88
|
+
generate_card,
|
|
89
|
+
generate_typology,
|
|
90
|
+
false,
|
|
91
|
+
{
|
|
92
|
+
typology_prompt: typologyPrompt,
|
|
93
|
+
card_gen_prompt: cardPrompt,
|
|
94
|
+
summary_prompt: ''
|
|
95
|
+
},
|
|
96
|
+
|
|
97
|
+
);
|
|
98
|
+
const responseToReturn = [];
|
|
99
|
+
const whatNeedsToBeGenerated = args.getWhatNeedsToBeGenerated();
|
|
100
|
+
for(let elem of whatNeedsToBeGenerated)
|
|
101
|
+
if(elem == 'generate_tyopology'){
|
|
102
|
+
this.typologyResponse = await this.generateTypology(args.prompts.typology_prompt ?? '', this.parsedContent);
|
|
103
|
+
responseToReturn.push(this.typologyResponse);
|
|
104
|
+
}else if(elem == 'generate_card'){
|
|
105
|
+
|
|
106
|
+
this.cardgenResponse = await this.generateCard(args.prompts.card_gen_prompt ?? '', this.parsedContent + JSON.stringify(this.typologyResponse));
|
|
107
|
+
responseToReturn.push(this.cardgenResponse);
|
|
108
|
+
}else if(elem == 'generate_summary'){
|
|
109
|
+
this.summarizeResponse = await this.generateSummary(args.prompts.summary_prompt ?? '', this.parsedContent);
|
|
110
|
+
responseToReturn.push(this.summarizeResponse);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return responseToReturn;
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
_returnParsedContent(){
|
|
118
|
+
return this.parsedContent;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
|
|
63
122
|
async generateCard(prompt: String, content: String){
|
|
64
|
-
|
|
123
|
+
let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
124
|
+
response['type'] = 'card_gen';
|
|
125
|
+
return response;
|
|
65
126
|
}
|
|
66
127
|
|
|
67
128
|
async generateTypology(prompt:String,content:String){
|
|
68
|
-
|
|
69
|
-
|
|
129
|
+
let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
130
|
+
response['type'] = 'typology';
|
|
131
|
+
return response;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
async generateSummary(prompt:String,content:String){
|
|
135
|
+
let response = await this.openAiService?.sendRequest(prompt,this.parsedContent);
|
|
136
|
+
response['type']= 'summary';
|
|
137
|
+
return response;
|
|
138
|
+
}
|
|
139
|
+
|
|
70
140
|
}
|
|
141
|
+
|
|
142
|
+
export class GenerateArgs{
|
|
143
|
+
public generate_card : boolean = false;
|
|
144
|
+
public generate_typology: boolean = false;
|
|
145
|
+
public generate_summary: boolean = false;
|
|
146
|
+
public prompts = {
|
|
147
|
+
typology_prompt: '',
|
|
148
|
+
card_gen_prompt: '',
|
|
149
|
+
summary_prompt: ''
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
constructor(generate_card: boolean,generate_typology: boolean, generate_summary: boolean, prompts = {
|
|
153
|
+
typology_prompt: '',
|
|
154
|
+
card_gen_prompt: '',
|
|
155
|
+
summary_prompt: ''
|
|
156
|
+
}){
|
|
157
|
+
this.generate_card = generate_card;
|
|
158
|
+
this.generate_typology = generate_typology;
|
|
159
|
+
this.generate_summary = generate_summary;
|
|
160
|
+
this.prompts = prompts
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
getWhatNeedsToBeGenerated(){
|
|
164
|
+
let returnData = [];
|
|
165
|
+
if(this.generate_typology == true){
|
|
166
|
+
returnData.push('generate_tyopology')
|
|
167
|
+
}
|
|
168
|
+
if(this.generate_summary == true){
|
|
169
|
+
returnData.push('generate_summary')
|
|
170
|
+
}
|
|
171
|
+
if(this.generate_card == true){
|
|
172
|
+
returnData.push('generate_card');
|
|
173
|
+
}
|
|
174
|
+
return returnData;
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import axios from "axios";
|
|
2
2
|
import config from "../config.js";
|
|
3
|
-
import { parseOpenAiSuccessResponse } from "../utils/parse_openai_response.js";
|
|
3
|
+
import { parseOpenAiFailureResponse, parseOpenAiSuccessResponse } from "../utils/parse_openai_response.js";
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
export async function openAIRequest(content:String,prompt:String,token:String){
|
|
6
|
+
export async function openAIRequest(content:String,prompt:String,token:String,model: String){
|
|
7
7
|
try{
|
|
8
8
|
let message = [
|
|
9
9
|
{
|
|
@@ -17,7 +17,7 @@ export async function openAIRequest(content:String,prompt:String,token:String){
|
|
|
17
17
|
url,
|
|
18
18
|
//data
|
|
19
19
|
{
|
|
20
|
-
"model":
|
|
20
|
+
"model": model,
|
|
21
21
|
"messages": message,
|
|
22
22
|
"response_format": {"type": "json_object"},
|
|
23
23
|
},
|
|
@@ -40,8 +40,7 @@ export async function openAIRequest(content:String,prompt:String,token:String){
|
|
|
40
40
|
}else{
|
|
41
41
|
console.log('failed');
|
|
42
42
|
return response.statusText as any;
|
|
43
|
-
}}catch (err) {
|
|
44
|
-
|
|
45
|
-
throw err;
|
|
43
|
+
}}catch (err:any) {
|
|
44
|
+
return parseOpenAiFailureResponse(err.response);
|
|
46
45
|
}
|
|
47
46
|
}
|
|
@@ -3,8 +3,19 @@ export function parseOpenAiSuccessResponse(responseData: any){
|
|
|
3
3
|
let usuage = responseData.usage;
|
|
4
4
|
let createdTime = responseData.created;
|
|
5
5
|
return {
|
|
6
|
+
'status_code': 200,
|
|
6
7
|
'usage_data': usuage,
|
|
7
8
|
'generated_content':choices,
|
|
8
9
|
'generated_at': createdTime
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export function parseOpenAiFailureResponse(errorResponse: any){
|
|
14
|
+
let usuage = errorResponse.usuage;
|
|
15
|
+
// let statusCode =
|
|
16
|
+
return {
|
|
17
|
+
'status_code': errorResponse.status,
|
|
18
|
+
|
|
19
|
+
|
|
9
20
|
}
|
|
10
21
|
}
|