-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.js
140 lines (117 loc) · 3.76 KB
/
utils.js
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
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
import inquirer from 'inquirer';
import fs from 'fs'; // read file
import chalk from 'chalk';
let filePath = "readCode.txt";
let defaultSystemMessage = 'You are a helpful assistant that answers concisely in the given max token to you.'
let defaultAnimeSystemMessage = 'You are a helpful and cute waifu assistant that answers concisely in the given max token to you.'
let defaultMaxTokens = 80
/**
* @returns {string} - whether a code or user input from the command like.
*/
export const enterMessage = async () => {
const question = await inquirer.prompt({
name: 'askIfReadCode',
type: 'list',
message: 'read code?',
choices: [
'no',
'yes',
'exit program',
]
});
if (question.askIfReadCode === 'yes') {
try {
const code = fs.readFileSync(filePath, 'utf-8');
return code;
} catch (error) {
console.error(`Error reading file: ${error.message}`);
process.exit(1);
}
} else if (question.askIfReadCode === 'no' ){
const answer = await inquirer.prompt({
name: 'enterMessage',
type: 'input',
message: `\n${chalk.blueBright('You:')} `,
default() {
return 'Enter message';
},
});
return answer.enterMessage;
} else {
return 'exit'
}
};
/**
* @returns {number} - we need to cast and return a number because
* inquirer returns a string and api wants number
*/
export const getMaxTokens = async () => {
const answer = await inquirer.prompt ({
name: 'askIfChangeMaxTokens',
type: 'list',
message: 'change the Max tokens? \n default: ' + defaultMaxTokens,
choices: [
'no',
'yes',
],
});
if(answer.askIfChangeMaxTokens === 'no') {
return defaultMaxTokens
} else {
const answer = await inquirer.prompt({
name: 'getMaxTokens',
type: 'input',
message: 'Enter max tokens: ',
})
return parseInt(answer.getMaxTokens)
}
}
/**
* @returns {string} - returns the user message, whether custom
* or the default ones.
*/
export const getSystemMessage = async () => {
const answer = await inquirer.prompt ({
name: 'askIfChangeSystemMessage',
type: 'list',
message: 'change the system model message? (to better fine tune the answer to your wants)\n default: ' + defaultSystemMessage,
choices: [
'no',
'waifu',
'yes',
],
});
if (answer.askIfChangeSystemMessage === 'no') {
return defaultSystemMessage
} else if (answer.askIfChangeSystemMessage === 'yes') {
const answer = await inquirer.prompt({
name: 'getSytemMessage',
type: 'input',
message: 'Enter system role message/context: ',
})
defaultSystemMessage = answer.getSytemMessage
return answer.getSytemMessage
} else {
return defaultAnimeSystemMessage;
}
}
/**
* @returns {string} - just the model type in string.
* all are in turbo to maximize cost efficiency.
*/
export const getModel = async () => {
const answer = await inquirer.prompt({
name: 'getModel',
type: 'list',
message: 'Select the model to be used: ',
choices: [
'Chatgpt-4',
'chatgpt-3.5',
],
});
if (answer.getModel === 'chatgpt-3.5') {
return 'gpt-3.5-turbo-0125'; // Corrected to return the selected model
} else {
return 'gpt-4-turbo-preview';
}
}