Add logging, fix some bugs, move fix from minigpt.py to api.py

main
t 11 months ago
parent ea121d6e28
commit 505de28319

@ -13,7 +13,7 @@ def predict(prompt, client, model = "0.1"):
elif model == "0.2":
result = client.predict(
prompt,
0.05, # 'Temperature'
0.5, # 'Temperature'
128, # 'Max new tokens'
0.8, # 'Top-p (nucleus sampling)'
1.8, # 'Repetition penalty'
@ -22,13 +22,39 @@ def predict(prompt, client, model = "0.1"):
return result
# Detect code
def iscode(text):
langs = ['sql','php','js','java','c','cpp','python','go']
is_code = False
for i in langs:
if i + r'\n' in text:
is_code = True
break
spec = ['section .']
if not is_code:
for i in spec:
if i in text:
is_code = True
break
return is_code
# text IN language IN
def translate(text, source):
if source == "ru":
target = "en"
elif source == "en":
target = "ru"
out = GoogleTranslator(source = source, target = target).translate(text)
# Fix code translate
if '```' in text:
out = ''
for i in text.split('```'):
if iscode(i):
out += '```' + i + '```'
else:
out += GoogleTranslator(source = source, target = target).translate(i)
else:
out = GoogleTranslator(source = source, target = target).translate(text)
return out
iddb = {}
@ -55,4 +81,5 @@ def gen(text, id, model):
except:
pass
return translate(predicted, "en")
fixed = predicted.replace(r'\n', '\n').replace('\\ n', '\n')
return translate(fixed, "en")

@ -34,15 +34,20 @@ __ Список кратких команд:
/prompt - /p
/cprompt - /cp
Канал разработчика: @justuser31
Ещё проекты: @just_openbots (тут много интересного)
{telebot.formatting.hlink("Исходный код","https://gitea.gulyaipole.fun/justuser/just_minigpt")}
""", parse_mode = "HTML")
bot.send_message(message.chat.id, f"""Также настоятельно рекомендую подписаться на канал бота: @justuser31
Обратная связь ( @just_anonchat_bot ) : {telebot.formatting.hcode(":justuser")}""", parse_mode = "HTML")
### MAIN ###
from api import *
import traceback
import logging
setted_models = {}
system_prompts = {}
onoff = {}
@ -123,11 +128,11 @@ def echo_message(message):
st = bot.send_message(message.chat.id, "Печатает...")
predicted = gen(prompt, message.chat.id, setted_models[id])
fixed = predicted.replace(r'\n', '\n').replace('\\ n', '\n')
try:
bot.reply_to(message, fixed, parse_mode="Markdown")
except:
bot.reply_to(message, fixed, parse_mode="HTML")
bot.reply_to(message, predicted, parse_mode="Markdown")
except Exception as e:
bot.reply_to(message, predicted, parse_mode="HTML")
logging.error(traceback.format_exc())
bot.delete_message(message.chat.id, st.id)

Loading…
Cancel
Save