diff options
| author | huker667 <huker@tuta.io> | 2026-07-15 21:07:09 +0300 |
|---|---|---|
| committer | huker667 <huker@tuta.io> | 2026-07-15 21:07:09 +0300 |
| commit | 99dbfad460e725d49b633665d164c24b3b1b5ec1 (patch) | |
| tree | 1f920f2bc2b2eb2df3477cfe25fdb62e8f2713d9 | |
| parent | 631fabf30dec054aa0c7561dbbbf862527096b71 (diff) | |
| download | uzbekgpt-99dbfad460e725d49b633665d164c24b3b1b5ec1.tar.gz uzbekgpt-99dbfad460e725d49b633665d164c24b3b1b5ec1.tar.bz2 uzbekgpt-99dbfad460e725d49b633665d164c24b3b1b5ec1.zip | |
fix def config, file reading and add vosk api support
| -rw-r--r-- | config_def.py | 38 | ||||
| -rw-r--r-- | helpers.py | 19 | ||||
| -rw-r--r-- | main.py | 33 |
3 files changed, 70 insertions, 20 deletions
diff --git a/config_def.py b/config_def.py index 6383cd6..1562002 100644 --- a/config_def.py +++ b/config_def.py @@ -1,19 +1,23 @@ import os -from prompts import SYSTEM_PROMPTS, IMAGE_PROMPT +from prompts import SYSTEM_PROMPTS, IMAGE_PROMPT, ADD_TO_PROMPT, NEW_MD, OLD_MD from dotenv import load_dotenv load_dotenv() ADMIN_ID = 8243488179 +# поставь "" пустой da если хочешь отключить поддержку голосовых +VOSK_API = "http://127.0.0.1:8080/stt" + MAX_CONTEXT = 7 MAX_PROMPT = 1500 MAX_TOKENS = 1500 BEN_IDS = [-1002147940521, -1001834656942, -1003142512395] +ABEN_IDS = [-1002147940521, -1001834656942, -1003142512395] REPORN_IDS = [-1002147940521, -1002775610996, -1001834656942, -1003142512395] -BOT_USERNAME = "Uzbek_GPTrobot" +BOT_USERNAME = "UzbekGPTTestBot" BOT_CALLS = ["узбек", "uzbek", f"@{BOT_USERNAME}"] DEFAULT_MODEL = "ollama*gemma4:31b-cloud" @@ -21,11 +25,10 @@ IMAGE_MODEL = "ollama*gemma3:27b-cloud" DEFAULT_STREAM = "none" DEFAULT_CALL = "da" DEFAULT_PROMPT = "стандартный" -DEFAULT_NOTIFY = "net" +DEFAULT_NOTIFY = "da" -# SHOW_ACC_MSG показывать ли сообщение, что владелец выключил команду SHOW_ACC_MSG = True -# команды + SETTINGS_COMMAND = True CLEAR_COMMAND = True PROMPT_COMMAND = True @@ -33,7 +36,7 @@ CONFIG_COMMAND = True ABOUT_BOT = ( "✅ *об узбекгпт* ✅\n" - "- создал @zsh69\n" + "- создал @zsh69 (хукер667)\n" "- репозиторий бота: https://git.hkr.at.by/cgit.cgi/uzbekgpt\n" "- `git clone https://g.hkr.at.by/uzbekgpt`\n" "- подпешис: t.me/hukerass" @@ -48,29 +51,28 @@ PROVIDERS = { "url": "http://127.0.0.1:11434/v1", "key": "da", }, + "krutoiapi": { + "name": "ваше крутое api", + "module": "openai", + "url": "http://localhost:8080/v1/", + "key": "qwera", + }, # "hzai": { # "name": "хуйзнает ai", # "module": "openai", # "url": os.getenv("HZAI_URL"), # "key": os.getenv("HZAI_KEY"), # }, - # "openrouter": { - # "name": "опенроутер", - # "module": "openai", - # "url": "https://openrouter.ai/api/v1/", - # "key": os.getenv("ORAI_KEY") - # } } MODELS = { "ollama": { - "gemma3:27b-cloud": {"n_tok": 7, "e_tok": 15}, - "gemma4:31b-cloud": {"n_tok": 30, "e_tok": 50}, + "gemma3:27b-cloud": {"n_tok": 7, "e_tok": 15, "vision": True}, + "gemma4:31b-cloud": {"n_tok": 30, "e_tok": 50, "vision": True}, + }, + "krutoiapi": { + "da": {"n_tok": 30, "e_tok": 50, "vision": False}, }, - # "hzai": { - # "google/gemma-3-27b-it": {"n_tok": 60, "e_tok": 120}, - # "allah-2-7b": {"n_tok": 50, "e_tok": 100}, - # }, } API_TOKEN = os.getenv("API_TOKEN") @@ -1,4 +1,5 @@ import time +import requests from aiogram.methods import AnswerGuestQuery, SendPoll from aiogram.types import InlineQueryResultArticle, InputTextMessageContent, InputRichMessageContent, InputRichMessage, Message @@ -129,3 +130,21 @@ async def answer_poll( correct_option_id=correct_option_id, ) ) + + +def send_to_vosk(audio): + files = { + "audio": ( + "voice.ogg", + audio, + "audio/ogg" + ) + } + + r = requests.post( + VOSK_API, + files=files, + timeout=15 + ) + + return r.json() @@ -1,4 +1,5 @@ import asyncio +import requests import base64 import io import sys @@ -143,6 +144,34 @@ async def guest_middleware(handler, event, data): prompt = "" images = [] + + voice = None + + if VOSK_API != "": + if message.voice: + voice = message.voice + elif replied and replied.voice: + voice = replied.voice + + if voice: + if voice.duration > 60: + da = "не врат не пойдёт такой длинный голосовой сообщение" \ + ". \nнадо меньше 60 секунд da✅" + if event.guest_message: + await g_answer(data, message, da) + else: + await message.reply(da) + buf = BytesIO() + await bot.download(voice, destination=buf) + buf.seek(0) + + result = await asyncio.to_thread( + send_to_vosk, + buf.read() + ) + + prompt = f"<голосовое сообщение>{result.get('text', 'не распознано')}</голосовое сообщение>{prompt}" + if message.document: if message.document.file_size > 4096: @@ -161,7 +190,7 @@ async def guest_middleware(handler, event, data): file_content = file_bytes.read().decode("utf-8", errors="ignore") file_bytes.close() - prompt = f"<файл>{file_content}</файл>" + prompt = f"<файл>{file_content}</файл>{prompt}" except UnicodeDecodeError: if event.guest_message: @@ -191,7 +220,7 @@ async def guest_middleware(handler, event, data): await bot.download(replied.document, destination=file_bytes) file_bytes.seek(0) file_content = file_bytes.read().decode("utf-8", errors="ignore") - prompt = f"<файл>{file_content}</файл>{user_text}" + prompt = f"<файл>{file_content}</файл>{prompt}" except UnicodeDecodeError: if event.guest_message: await g_answer(data, message, "файл не вошёл❌") |