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": elif model == "0.2":
result = client.predict( result = client.predict(
prompt, prompt,
0.05, # 'Temperature' 0.5, # 'Temperature'
128, # 'Max new tokens' 128, # 'Max new tokens'
0.8, # 'Top-p (nucleus sampling)' 0.8, # 'Top-p (nucleus sampling)'
1.8, # 'Repetition penalty' 1.8, # 'Repetition penalty'
@ -22,12 +22,38 @@ def predict(prompt, client, model = "0.1"):
return result 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 # text IN language IN
def translate(text, source): def translate(text, source):
if source == "ru": if source == "ru":
target = "en" target = "en"
elif source == "en": elif source == "en":
target = "ru" target = "ru"
# 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) out = GoogleTranslator(source = source, target = target).translate(text)
return out return out
@ -55,4 +81,5 @@ def gen(text, id, model):
except: except:
pass pass
return translate(predicted, "en") fixed = predicted.replace(r'\n', '\n').replace('\\ n', '\n')
return translate(fixed, "en")

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

Loading…
Cancel
Save