Compare commits

..

No commits in common. "c0d48a92dc5c11297ad81d1ea417e6d942cd1336" and "c55e613a4ad950ed27ebc59adb56277d9721e305" have entirely different histories.

2 changed files with 8 additions and 17 deletions

View File

@ -37,7 +37,6 @@ import {
} from './util'; } from './util';
import 'dotenv/config'; import 'dotenv/config';
const KNOWN_USERNAMES = ['vinso1445', 'bapazheng', 'f0oby', 'shibe.mp4', '1thinker', 'bapabakshi', 'keliande27', 'gnuwu', 'scoliono', 'adam28405'];
const config = {}; const config = {};
interface CommandClient extends Client { interface CommandClient extends Client {
@ -151,9 +150,9 @@ async function onNewMessage(message: Message)
message message
]; ];
try {
await message.channel.sendTyping(); await message.channel.sendTyping();
try {
const response = await requestLLMResponse(cleanHistoryList); const response = await requestLLMResponse(cleanHistoryList);
// evaluate response // evaluate response
if (!isGoodResponse(response)) { if (!isGoodResponse(response)) {
@ -214,23 +213,16 @@ async function requestLLMResponse(messages)
queryParams.append(field, config["llmconf"].llmSettings[field]); queryParams.append(field, config["llmconf"].llmSettings[field]);
} }
const llmEndpoint = `${process.env.LLM_HOST}/?${queryParams.toString()}`; const llmEndpoint = `${process.env.LLM_HOST}/?${queryParams.toString()}`;
const messageList = messages.map((m: Message) => { const messageList = messages.map((m: Message) => ({
let role = 'user'; role: m.author.bot ? "assistant" : "user",
if (m.author.id === process.env.CLIENT) { content: m.cleanContent,
role = 'assistant'; }));
} else if (m.author.bot) {
return null;
} else if (KNOWN_USERNAMES.includes(m.author.username)) {
role = m.author.username;
}
return { role, content: m.cleanContent };
});
const reqBody = [ const reqBody = [
{ {
"role": "system", "role": "system",
"content": config["llmconf"].sys_prompt "content": config["llmconf"].sys_prompt
}, },
...messageList.filter(x => x) ...messageList
]; ];
logInfo("[bot] Requesting LLM response with message list: " + reqBody.map(m => m.content)); logInfo("[bot] Requesting LLM response with message list: " + reqBody.map(m => m.content));
const res = await fetch(llmEndpoint, { const res = await fetch(llmEndpoint, {
@ -244,7 +236,7 @@ async function requestLLMResponse(messages)
const txtRaw: string = txt["raw"][0]; const txtRaw: string = txt["raw"][0];
// Depends on chat template used // Depends on chat template used
const prefix = "<|start_header_id|>assistant<|end_header_id|>\n\n"; const prefix = "<|start_header_id|>assistant<|end_header_id|>\n\n";
const suffix = "<|eot_id|>"; const suffix = "<|reserved_special_token_";
const txtStart = txtRaw.lastIndexOf(prefix); const txtStart = txtRaw.lastIndexOf(prefix);
const txtEnd = txtRaw.slice(txtStart + prefix.length); const txtEnd = txtRaw.slice(txtStart + prefix.length);
const txtStop = txtEnd.indexOf(suffix) !== -1 ? txtEnd.indexOf(suffix) : txtEnd.length; const txtStop = txtEnd.indexOf(suffix) !== -1 ? txtEnd.indexOf(suffix) : txtEnd.length;

View File

@ -18,7 +18,6 @@ async function configCommand(interaction: ChatInputCommandInteraction)
{ {
if (interaction.user.id !== process.env.ADMIN) { if (interaction.user.id !== process.env.ADMIN) {
await interaction.reply("You are not authorized to change model settings"); await interaction.reply("You are not authorized to change model settings");
return;
} }
config.llmSettings.max_new_tokens = interaction.options.getInteger('max_new_tokens') ?? config.llmSettings.max_new_tokens; config.llmSettings.max_new_tokens = interaction.options.getInteger('max_new_tokens') ?? config.llmSettings.max_new_tokens;