Skip to content

Commit e00224d

Browse files
committed
token in config
1 parent 6584555 commit e00224d

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

config.example.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const GPT_MODE = {
1010
export const AI_NAME = "DecryptGPT"; // AI Name
1111
export const MAX_RETRIES = 3; // Number of retries before throwing an error
1212
export const PREV_MESSAGES_LIMIT = 6; // Chat history limit
13+
export const MAX_TOKENS = 4096; // Maximum number of tokens
1314
export const CHAT_GPT_ENABLED = true; // Enable or disable the bot
1415
export const DALL_E_ENABLED = true; // Enable or disable image generation
1516
export const DEFAULT_MODE = GPT_MODE.TEXT; // Default model on boot

utils/respondToMessage.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
import splitMessage from "./splitMessage.js";
22
import handleApiErrors from "./handleApiErrors.js";
3-
import { GPT_MODE, MODEL_NAME, MAX_RETRIES, BETTER_LOG } from "../config.js";
3+
import {
4+
GPT_MODE,
5+
MODEL_NAME,
6+
MAX_RETRIES,
7+
BETTER_LOG,
8+
MAX_TOKENS
9+
} from "../config.js";
410
import fs from "node:fs";
511
import path from "node:path";
612

713
let lastSpeechFile = null;
814

15+
/**
16+
* Handles responding to a message with either text or voice
17+
* @param {Message} message - The Discord message to respond to
18+
* @param {Client} client - The Discord client instance
19+
* @param {Array} conversationLog - Array of previous messages for context
20+
*/
921
async function respondToMessage(message, client, conversationLog) {
1022
const typingInterval = setInterval(() => message.channel.sendTyping(), 5000);
1123

@@ -22,7 +34,7 @@ async function respondToMessage(message, client, conversationLog) {
2234
};
2335

2436
if (client.currentMode === GPT_MODE.TEXT) {
25-
requestPayload.max_tokens = 4096;
37+
requestPayload.max_tokens = MAX_TOKENS;
2638
}
2739

2840
if (BETTER_LOG) {
@@ -61,6 +73,12 @@ async function respondToMessage(message, client, conversationLog) {
6173
}
6274
}
6375

76+
/**
77+
* Handles generating and sending TTS audio responses
78+
* @param {Message} message - The Discord message to respond to
79+
* @param {Client} client - The Discord client instance
80+
* @param {string} text - The text to convert to speech
81+
*/
6482
async function sendTtsResponse(message, client, text) {
6583
const speechFile = path.resolve(`./speech-${Date.now()}.mp3`);
6684

@@ -75,9 +93,11 @@ async function sendTtsResponse(message, client, text) {
7593
voice: "echo",
7694
input: text,
7795
});
96+
7897
const buffer = Buffer.from(await mp3.arrayBuffer());
7998
await fs.promises.writeFile(speechFile, buffer);
8099
lastSpeechFile = speechFile;
100+
81101
await message.channel.send({
82102
files: [
83103
{
@@ -94,4 +114,4 @@ async function sendTtsResponse(message, client, text) {
94114
}
95115
}
96116

97-
export default respondToMessage;
117+
export default respondToMessage;

0 commit comments

Comments
 (0)