[FEATURE] Add AI-based /ask command (complementing #54) (#56)

* docs: add ai documentation

* docker: update docker files for ai/regular versions, lint

* feat: add initial /ask command

* Delete docker-compose.yml

* docker: ignore ollama folder in builds

* fix: add emojis to help commands, capitalize, add ai commands to help menu

* feat: add better logging, thought handling improvements

* bug fixes, better logging and seperation of ai, update docs for ai

* clean, remove prompt and user info from logs, more docs edits

* system prompt change (plaintext only), parse out /think

* clean up, axios tweaks

* cleanup, logging of ratelimit

---------

Co-authored-by: Aidan <aidan@p0ntus.com>
This commit is contained in:
Lucas Gabriel 2025-06-28 16:22:15 -03:00 committed by GitHub
parent 0c364a1814
commit 81294f5721
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 733 additions and 35 deletions

83
src/utils/log.ts Normal file
View file

@ -0,0 +1,83 @@
// LOG.TS
// by ihatenodejs/Aidan
//
// -----------------------------------------------------------------------
//
// This is free and unencumbered software released into the public domain.
//
// Anyone is free to copy, modify, publish, use, compile, sell, or
// distribute this software, either in source code form or as a compiled
// binary, for any purpose, commercial or non-commercial, and by any
// means.
//
// In jurisdictions that recognize copyright laws, the author or authors
// of this software dedicate any and all copyright interest in the
// software to the public domain. We make this dedication for the benefit
// of the public at large and to the detriment of our heirs and
// successors. We intend this dedication to be an overt act of
// relinquishment in perpetuity of all present and future rights to this
// software under copyright law.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
// OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
// OTHER DEALINGS IN THE SOFTWARE.
//
// For more information, please refer to <https://unlicense.org/>
import { flash_model, thinking_model } from "../commands/ai"
class Logger {
private static instance: Logger
private constructor() {}
static getInstance(): Logger {
if (!Logger.instance) {
Logger.instance = new Logger()
}
return Logger.instance
}
logCmdStart(user: string, type: "ask" | "think"): void {
console.log(`\n[✨ AI | START] Received /${type} for model ${type === "ask" ? flash_model : thinking_model}`)
}
logThinking(chatId: number, messageId: number, thinking: boolean): void {
if (thinking) {
console.log(`[✨ AI | THINKING | ${chatId}:${messageId}] Model started thinking`)
} else {
console.log(`[✨ AI | THINKING | ${chatId}:${messageId}] Model stopped thinking`)
}
}
logChunk(chatId: number, messageId: number, text: string, isOverflow: boolean = false): void {
const prefix = isOverflow ? "[✨ AI | OVERFLOW]" : "[✨ AI | CHUNK]"
console.log(`${prefix} [${chatId}:${messageId}] ${text.length} chars pushed to Telegram`)
}
logPrompt(prompt: string): void {
console.log(`[✨ AI | PROMPT] ${prompt.length} chars input`)
}
logError(error: any): void {
if (error.response?.error_code === 429) {
const retryAfter = error.response.parameters?.retry_after || 1
console.error(`[✨ AI | RATE_LIMIT] Too Many Requests - retry after ${retryAfter}s`)
} else if (error.response?.error_code === 400 && error.response?.description?.includes("can't parse entities")) {
console.error("[✨ AI | PARSE_ERROR] Markdown parsing failed, retrying with plain text")
} else {
const errorDetails = {
code: error.response?.error_code,
description: error.response?.description,
method: error.on?.method
}
console.error("[✨ AI | ERROR]", JSON.stringify(errorDetails, null, 2))
}
}
}
export const logger = Logger.getInstance()