From 3b6d200b21e16dc9cad343339caaaf5862f1a506 Mon Sep 17 00:00:00 2001 From: Aidan Date: Sat, 5 Jul 2025 16:24:00 -0400 Subject: [PATCH] ai mod cmds improvements, remove phi4 models for bad performance to output, push example env --- config/ai.ts | 14 -------------- telegram/commands/ai.ts | 33 ++++++++++++++++++++++++++++---- telegram/locales/english.json | 5 ++++- telegram/locales/portuguese.json | 5 ++++- webui/.env.example | 2 ++ webui/.gitignore | 1 + 6 files changed, 40 insertions(+), 20 deletions(-) create mode 100644 webui/.env.example diff --git a/config/ai.ts b/config/ai.ts index de8d402..6c6ddb0 100755 --- a/config/ai.ts +++ b/config/ai.ts @@ -327,13 +327,6 @@ export const models: ModelInfo[] = [ descriptionEn: 'Phi-4 is a 14B parameter, state-of-the-art open model from Microsoft. ', descriptionPt: 'Phi-4 é um modelo de 14B de última geração, aberto pela Microsoft.', models: [ - { - name: 'hf.co/unsloth/Phi-4-mini-reasoning-GGUF', - label: 'Phi4 Mini Reasoning', - parameterSize: '4B', - thinking: true, - uncensored: false - }, { name: 'phi4:14b', label: 'Phi4 14B', @@ -341,13 +334,6 @@ export const models: ModelInfo[] = [ thinking: false, uncensored: false }, - { - name: 'hf.co/unsloth/Phi-4-reasoning-plus-GGUF', - label: 'Phi4 Reasoning Plus', - parameterSize: '14B', - thinking: true, - uncensored: false - }, { name: 'huihui_ai/phi4-abliterated:14b', label: 'Phi4 Uncensored 14B', diff --git a/telegram/commands/ai.ts b/telegram/commands/ai.ts index 244678e..87ff59c 100755 --- a/telegram/commands/ai.ts +++ b/telegram/commands/ai.ts @@ -984,11 +984,30 @@ export default (bot: Telegraf, db: NodePgDatabase) => { return; } + let stoppedCurrentRequest = false; const initialLength = requestQueue.length; const filteredQueue = requestQueue.filter(item => item.userId !== targetUserId); const removedCount = initialLength - filteredQueue.length; - if (removedCount === 0) { + requestQueue.length = 0; + requestQueue.push(...filteredQueue); + + if (currentRequest && currentRequest.userId === targetUserId) { + currentRequest.abortController?.abort(); + + try { + await axios.post(`${process.env.ollamaApi}/api/generate`, { + model: currentRequest.model, + keep_alive: 0, + }, { timeout: 5000 }); + } catch (error) { + console.log("[✨ AI] Could not unload model after cancellation:", error.message); + } + + stoppedCurrentRequest = true; + } + + if (removedCount === 0 && !stoppedCurrentRequest) { await ctx.reply(Strings.ai.noQueueItems.replace("{userId}", String(targetUserId)), { parse_mode: 'Markdown', ...(reply_to_message_id && { reply_parameters: { message_id: reply_to_message_id } }) @@ -996,10 +1015,16 @@ export default (bot: Telegraf, db: NodePgDatabase) => { return; } - requestQueue.length = 0; - requestQueue.push(...filteredQueue); + let responseMessage = ""; + if (stoppedCurrentRequest && removedCount > 0) { + responseMessage = Strings.ai.stoppedCurrentAndCleared.replace("{count}", String(removedCount)).replace("{userId}", String(targetUserId)); + } else if (stoppedCurrentRequest) { + responseMessage = Strings.ai.stoppedCurrentRequestOnly.replace("{userId}", String(targetUserId)); + } else { + responseMessage = Strings.ai.queueCleared.replace("{count}", String(removedCount)).replace("{userId}", String(targetUserId)); + } - await ctx.reply(Strings.ai.queueCleared.replace("{count}", String(removedCount)).replace("{userId}", String(targetUserId)), { + await ctx.reply(responseMessage, { parse_mode: 'Markdown', ...(reply_to_message_id && { reply_parameters: { message_id: reply_to_message_id } }) }); diff --git a/telegram/locales/english.json b/telegram/locales/english.json index 76e630d..a6d7575 100755 --- a/telegram/locales/english.json +++ b/telegram/locales/english.json @@ -120,7 +120,10 @@ "requestStopped": "🛑 Your AI request has been stopped.", "requestRemovedFromQueue": "🛑 Your AI request has been removed from the queue.", "noActiveRequest": "ℹ️ You don't have any active AI requests to stop.", - "executionTimeoutReached": "\n\n⏱️ Max execution time limit reached!" + "executionTimeoutReached": "\n\n⏱️ Max execution time limit reached!", + "stoppedCurrentAndCleared": "🛑 Stopped current request and cleared {count} queued item(s) for user {userId}.", + "stoppedCurrentRequestOnly": "🛑 Stopped current request for user {userId} (no queued items found).", + "stoppedCurrentAndClearedQueue": "🛑 Stopped current request and cleared all queued items for user {userId}." }, "maInvalidModule": "Please provide a valid module ID from The Mod Archive.\nExample: `/modarchive 81574`", "maDownloadError": "Error downloading the file. Check the module ID and try again.", diff --git a/telegram/locales/portuguese.json b/telegram/locales/portuguese.json index 9ef22ed..1f9bc23 100755 --- a/telegram/locales/portuguese.json +++ b/telegram/locales/portuguese.json @@ -123,7 +123,10 @@ "requestStopped": "🛑 Sua solicitação de IA foi interrompida.", "requestRemovedFromQueue": "🛑 Sua solicitação de IA foi removida da fila.", "noActiveRequest": "ℹ️ Você não tem nenhuma solicitação ativa de IA para parar.", - "executionTimeoutReached": "\n\n⏱️ Limite máximo de tempo de execução atingido!" + "executionTimeoutReached": "\n\n⏱️ Limite máximo de tempo de execução atingido!", + "stoppedCurrentAndCleared": "🛑 Parou solicitação atual e limpou {count} item(s) da fila para o usuário {userId}.", + "stoppedCurrentRequestOnly": "🛑 Parou solicitação atual para o usuário {userId} (nenhum item na fila encontrado).", + "stoppedCurrentAndClearedQueue": "🛑 Parou solicitação atual e limpou todos os itens da fila para o usuário {userId}." }, "maInvalidModule": "Por favor, forneça um ID de módulo válido do The Mod Archive.\nExemplo: `/modarchive 81574`", "maDownloadError": "Erro ao baixar o arquivo. Verifique o ID do módulo e tente novamente.", diff --git a/webui/.env.example b/webui/.env.example new file mode 100644 index 0000000..d00c580 --- /dev/null +++ b/webui/.env.example @@ -0,0 +1,2 @@ +botApiUrl = "http://kowalski:3030" +databaseUrl = "postgres://kowalski:kowalski@localhost:5432/kowalski" \ No newline at end of file diff --git a/webui/.gitignore b/webui/.gitignore index 5ef6a52..7b8da95 100755 --- a/webui/.gitignore +++ b/webui/.gitignore @@ -32,6 +32,7 @@ yarn-error.log* # env files (can opt-in for committing if needed) .env* +!.env.example # vercel .vercel