fix def config, file reading and add vosk api support

This commit is contained in:
huker667 committed 2026-07-15 21:07:09 +03:00
1 parent 631fabf30d
commit 99dbfad460
3 files changed
+70 -20

No files matched your search

+20 -18
View File
@@ -1,19 +1,23 @@
import os 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 from dotenv import load_dotenv
load_dotenv() load_dotenv()
ADMIN_ID = 8243488179 ADMIN_ID = 8243488179
# поставь "" пустой da если хочешь отключить поддержку голосовых
VOSK_API = "http://127.0.0.1:8080/stt"
MAX_CONTEXT = 7 MAX_CONTEXT = 7
MAX_PROMPT = 1500 MAX_PROMPT = 1500
MAX_TOKENS = 1500 MAX_TOKENS = 1500
BEN_IDS = [-1002147940521, -1001834656942, -1003142512395] BEN_IDS = [-1002147940521, -1001834656942, -1003142512395]
ABEN_IDS = [-1002147940521, -1001834656942, -1003142512395]
REPORN_IDS = [-1002147940521, -1002775610996, -1001834656942, -1003142512395] REPORN_IDS = [-1002147940521, -1002775610996, -1001834656942, -1003142512395]
BOT_USERNAME = "Uzbek_GPTrobot" BOT_USERNAME = "UzbekGPTTestBot"
BOT_CALLS = ["узбек", "uzbek", f"@{BOT_USERNAME}"] BOT_CALLS = ["узбек", "uzbek", f"@{BOT_USERNAME}"]
DEFAULT_MODEL = "ollama*gemma4:31b-cloud" DEFAULT_MODEL = "ollama*gemma4:31b-cloud"
@@ -21,11 +25,10 @@ IMAGE_MODEL = "ollama*gemma3:27b-cloud"
DEFAULT_STREAM = "none" DEFAULT_STREAM = "none"
DEFAULT_CALL = "da" DEFAULT_CALL = "da"
DEFAULT_PROMPT = "стандартный" DEFAULT_PROMPT = "стандартный"
DEFAULT_NOTIFY = "net" DEFAULT_NOTIFY = "da"
# SHOW_ACC_MSG показывать ли сообщение, что владелец выключил команду
SHOW_ACC_MSG = True SHOW_ACC_MSG = True
# команды
SETTINGS_COMMAND = True SETTINGS_COMMAND = True
CLEAR_COMMAND = True CLEAR_COMMAND = True
PROMPT_COMMAND = True PROMPT_COMMAND = True
@@ -33,7 +36,7 @@ CONFIG_COMMAND = True
ABOUT_BOT = ( ABOUT_BOT = (
"✅ *об узбекгпт* ✅\n" "✅ *об узбекгпт* ✅\n"
"- создал @zsh69\n" "- создал @zsh69 (хукер667)\n"
"- репозиторий бота: https://git.hkr.at.by/cgit.cgi/uzbekgpt\n" "- репозиторий бота: https://git.hkr.at.by/cgit.cgi/uzbekgpt\n"
"- `git clone https://g.hkr.at.by/uzbekgpt`\n" "- `git clone https://g.hkr.at.by/uzbekgpt`\n"
"- подпешис: t.me/hukerass" "- подпешис: t.me/hukerass"
@@ -48,29 +51,28 @@ PROVIDERS = {
"url": "http://127.0.0.1:11434/v1", "url": "http://127.0.0.1:11434/v1",
"key": "da", "key": "da",
}, },
"krutoiapi": {
"name": "ваше крутое api",
"module": "openai",
"url": "http://localhost:8080/v1/",
"key": "qwera",
},
# "hzai": { # "hzai": {
# "name": "хуйзнает ai", # "name": "хуйзнает ai",
# "module": "openai", # "module": "openai",
# "url": os.getenv("HZAI_URL"), # "url": os.getenv("HZAI_URL"),
# "key": os.getenv("HZAI_KEY"), # "key": os.getenv("HZAI_KEY"),
# }, # },
# "openrouter": {
# "name": "опенроутер",
# "module": "openai",
# "url": "https://openrouter.ai/api/v1/",
# "key": os.getenv("ORAI_KEY")
# }
} }
MODELS = { MODELS = {
"ollama": { "ollama": {
"gemma3:27b-cloud": {"n_tok": 7, "e_tok": 15}, "gemma3:27b-cloud": {"n_tok": 7, "e_tok": 15, "vision": True},
"gemma4:31b-cloud": {"n_tok": 30, "e_tok": 50}, "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") API_TOKEN = os.getenv("API_TOKEN")
+19
View File
@@ -1,4 +1,5 @@
import time import time
import requests
from aiogram.methods import AnswerGuestQuery, SendPoll from aiogram.methods import AnswerGuestQuery, SendPoll
from aiogram.types import InlineQueryResultArticle, InputTextMessageContent, InputRichMessageContent, InputRichMessage, Message from aiogram.types import InlineQueryResultArticle, InputTextMessageContent, InputRichMessageContent, InputRichMessage, Message
@@ -129,3 +130,21 @@ async def answer_poll(
correct_option_id=correct_option_id, 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()
+31 -2
View File
@@ -1,4 +1,5 @@
import asyncio import asyncio
import requests
import base64 import base64
import io import io
import sys import sys
@@ -143,6 +144,34 @@ async def guest_middleware(handler, event, data):
prompt = "" prompt = ""
images = [] 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:
if message.document.file_size > 4096: 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_content = file_bytes.read().decode("utf-8", errors="ignore")
file_bytes.close() file_bytes.close()
prompt = f"<файл>{file_content}</файл>" prompt = f"<файл>{file_content}</файл>{prompt}"
except UnicodeDecodeError: except UnicodeDecodeError:
if event.guest_message: if event.guest_message:
@@ -191,7 +220,7 @@ async def guest_middleware(handler, event, data):
await bot.download(replied.document, destination=file_bytes) await bot.download(replied.document, destination=file_bytes)
file_bytes.seek(0) file_bytes.seek(0)
file_content = file_bytes.read().decode("utf-8", errors="ignore") file_content = file_bytes.read().decode("utf-8", errors="ignore")
prompt = f"<файл>{file_content}</файл>{user_text}" prompt = f"<файл>{file_content}</файл>{prompt}"
except UnicodeDecodeError: except UnicodeDecodeError:
if event.guest_message: if event.guest_message:
await g_answer(data, message, "файл не вошёл❌") await g_answer(data, message, "файл не вошёл❌")