Skip to content

Commit 54d09f7

Browse files
committed
fix: tokens length
1 parent a6a635b commit 54d09f7

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

src/commands/grzesiu.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const configuration = new Configuration({
99
});
1010
const openai = new OpenAIApi(configuration);
1111

12+
const MAX_TOKENS = 2049;
13+
const RESPONSE_TOKENS = 64;
1214
const BANNED_PATTERNS = /[`\[\]{}\(\)]|http/g;
1315
const COOLDOWN = 60;
1416
const GRZESIU_DELAY = 1500;
@@ -26,7 +28,7 @@ const grzesiu: Command = {
2628
const response = await openai.createCompletion('text-davinci-001', {
2729
prompt,
2830
temperature: 1,
29-
max_tokens: 64,
31+
max_tokens: RESPONSE_TOKENS,
3032
top_p: 1,
3133
frequency_penalty: 0,
3234
presence_penalty: 2,
@@ -59,8 +61,6 @@ const grzesiu: Command = {
5961

6062
export default grzesiu;
6163

62-
const MAX_TOKENS = 2049;
63-
6464
const getRandomInt = (len: number) => Math.floor(Math.random() * len);
6565

6666
const getRandomIndices = (num: number, max: number) => {
@@ -85,7 +85,7 @@ const generateGrzesiuPrompt = async (username: string, question: string) => {
8585
const txt = uniqueLines.reduce((txt, line) => {
8686
const newTxt = txt + `${GRZESIU_NAME}: ` + line + '\n';
8787
const fullConvo = getFullConvo(newTxt, username, question);
88-
return fullConvo.length <= MAX_TOKENS ? newTxt : txt;
88+
return fullConvo.length <= MAX_TOKENS - RESPONSE_TOKENS ? newTxt : txt;
8989
}, '');
9090
return getFullConvo(txt, username, question);
9191
};

0 commit comments

Comments
 (0)