up
This commit is contained in:
parent
18a1d261ba
commit
0f9829d718
9
api.py
9
api.py
@ -58,6 +58,7 @@ def translate(text, source):
|
|||||||
out = GoogleTranslator(source = source, target = target).translate(text)
|
out = GoogleTranslator(source = source, target = target).translate(text)
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
|
||||||
iddb = {}
|
iddb = {}
|
||||||
|
|
||||||
def gen(text, id, model):
|
def gen(text, id, model):
|
||||||
@ -67,20 +68,21 @@ def gen(text, id, model):
|
|||||||
if model == "0.1":
|
if model == "0.1":
|
||||||
client = Client("https://afischer1985-ai-interface.hf.space/")
|
client = Client("https://afischer1985-ai-interface.hf.space/")
|
||||||
elif model == "0.2":
|
elif model == "0.2":
|
||||||
client = Client("https://skier8402-mistral-super-fast.hf.space/")
|
# client = Client("https://skier8402-mistral-super-fast.hf.space/")
|
||||||
|
client = Client("https://nonamed33-minigpt-api.hf.space/")
|
||||||
|
# Changed to private space
|
||||||
if not model == "3.5":
|
if not model == "3.5":
|
||||||
iddb[str(id)] = client
|
iddb[str(id)] = client
|
||||||
else:
|
else:
|
||||||
if not model == "3.5":
|
if not model == "3.5":
|
||||||
client = iddb[str(id)]
|
client = iddb[str(id)]
|
||||||
|
|
||||||
success = False
|
|
||||||
try:
|
try:
|
||||||
|
# if True:
|
||||||
if model == "0.1" or model == "0.2":
|
if model == "0.1" or model == "0.2":
|
||||||
prompt = translate(text, "ru")
|
prompt = translate(text, "ru")
|
||||||
predicted = predict(prompt, client, model).replace("</s>", "")
|
predicted = predict(prompt, client, model).replace("</s>", "")
|
||||||
predicted = translate(predicted, "en")
|
predicted = translate(predicted, "en")
|
||||||
success = True
|
|
||||||
elif model == "3.5":
|
elif model == "3.5":
|
||||||
# ChatGPT
|
# ChatGPT
|
||||||
global setted_models
|
global setted_models
|
||||||
@ -90,7 +92,6 @@ def gen(text, id, model):
|
|||||||
except:
|
except:
|
||||||
inst = None
|
inst = None
|
||||||
predicted = chat_predict(prompt, id, inst)
|
predicted = chat_predict(prompt, id, inst)
|
||||||
success = True
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
74
minigpt.py
74
minigpt.py
@ -1,4 +1,5 @@
|
|||||||
import telebot
|
import telebot
|
||||||
|
from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
|
|
||||||
### LOAD TOKEN ###
|
### LOAD TOKEN ###
|
||||||
import json, os
|
import json, os
|
||||||
@ -24,17 +25,18 @@ def send_welcome(message):
|
|||||||
bot.reply_to(message, f"""Это подобие ChatGPT на минималках.
|
bot.reply_to(message, f"""Это подобие ChatGPT на минималках.
|
||||||
|
|
||||||
__ Есть 3 версии:
|
__ Есть 3 версии:
|
||||||
{telebot.formatting.hcode("/m 0.1")} - Простейшая, быстрейшая, краткая, не помнит что вы говорили.
|
0.1 - Простейшая, быстрейшая, краткая, не помнит что вы говорили.
|
||||||
{telebot.formatting.hcode("/m 0.2")} - Умнее, относительно быстрая, помнит что вы говорили.
|
0.2 - Умнее, относительно быстрая, помнит что вы говорили.
|
||||||
{telebot.formatting.hcode("/m 3.5")} - Самая умная, есть цензура, помнит что вы говорили.
|
3.5 - Самая умная, есть цензура, помнит что вы говорили.
|
||||||
(1,2 - Mistral, 3 - ChatGPT)
|
/m - Выбор модели
|
||||||
|
|
||||||
__ Список кратких команд:
|
__ Список команд:
|
||||||
/info - /i
|
help - Справка
|
||||||
/model - /m
|
i - Информация о конфигурации
|
||||||
/ccontext - /cc
|
m - Сменить модель
|
||||||
/prompt - /p
|
cc - Очистить контекст
|
||||||
/cprompt - /cp
|
p - Задать инструкцию (системную)
|
||||||
|
cp - Сбросить инструкцию
|
||||||
|
|
||||||
Ещё проекты: @just_openbots (тут много интересного)
|
Ещё проекты: @just_openbots (тут много интересного)
|
||||||
{telebot.formatting.hlink("Исходный код","https://gitea.gulyaipole.fun/justuser/just_minigpt")}
|
{telebot.formatting.hlink("Исходный код","https://gitea.gulyaipole.fun/justuser/just_minigpt")}
|
||||||
@ -70,26 +72,45 @@ def info(message):
|
|||||||
System-prompt: {telebot.formatting.hcode(prompt)}
|
System-prompt: {telebot.formatting.hcode(prompt)}
|
||||||
""", parse_mode="HTML")
|
""", parse_mode="HTML")
|
||||||
|
|
||||||
@bot.message_handler(commands=['model','m'])
|
|
||||||
|
############ MODEL SELECTION ############
|
||||||
|
|
||||||
|
@bot.message_handler(commands=['m'])
|
||||||
def set_model(message):
|
def set_model(message):
|
||||||
|
bot.send_message(message.chat.id, "Выберите новую модель:", reply_markup=gen_markup(str(message.chat.id)))
|
||||||
|
|
||||||
|
def gen_markup(id):
|
||||||
|
markup = InlineKeyboardMarkup()
|
||||||
|
markup.row_width = 3
|
||||||
|
markup.add(InlineKeyboardButton("0.1", callback_data=id+"_0.1"),
|
||||||
|
InlineKeyboardButton("0.2", callback_data=id+"_0.2"),
|
||||||
|
InlineKeyboardButton("3.5", callback_data=id+"_3.5") )
|
||||||
|
return markup
|
||||||
|
|
||||||
|
@bot.callback_query_handler(func=lambda call: True)
|
||||||
|
def callback_query(call):
|
||||||
global setted_models, iddb
|
global setted_models, iddb
|
||||||
|
id = call.data.split("_")[0] ; m = call.data.split("_")[1]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
iddb.pop(str(message.chat.id))
|
iddb.pop(id)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
model = message.text.split()[1]
|
if m == "0.1":
|
||||||
if model == "0.1" or model == "0.2" or model == "3.5":
|
setted_models[id] = "0.1"
|
||||||
setted_models[str(message.chat.id)] = model
|
elif m == "0.2":
|
||||||
bot.reply_to(message, "Установлена новая модель 🤖")
|
setted_models[id] = "0.2"
|
||||||
else:
|
elif m == "3.5":
|
||||||
bot.reply_to(message, "Неизвестная модель")
|
setted_models[id] = "3.5"
|
||||||
|
bot.send_message(int(id), "Успешно установлена новая модель 🤖")
|
||||||
|
|
||||||
|
##########################################
|
||||||
|
|
||||||
@bot.message_handler(commands=['prompt','p'])
|
@bot.message_handler(commands=['p'])
|
||||||
def set_prompt(message):
|
def set_prompt(message):
|
||||||
global system_prompts
|
global system_prompts
|
||||||
system_prompts[str(message.chat.id)] = message.text[8:]
|
system_prompts[str(message.chat.id)] = message.text[3:]
|
||||||
bot.reply_to(message, "Установлен новый system-prompt 🤖")
|
bot.reply_to(message, "Установлен новый system-prompt 🤖")
|
||||||
@bot.message_handler(commands=['cprompt','cp'])
|
@bot.message_handler(commands=['cprompt','cp'])
|
||||||
def clear_prompt(message):
|
def clear_prompt(message):
|
||||||
@ -101,7 +122,7 @@ def clear_prompt(message):
|
|||||||
bot.reply_to(message, "System-prompt очищен 🤖")
|
bot.reply_to(message, "System-prompt очищен 🤖")
|
||||||
|
|
||||||
|
|
||||||
@bot.message_handler(commands=['ccontext','cc'])
|
@bot.message_handler(commands=['cc'])
|
||||||
def clear_context(message):
|
def clear_context(message):
|
||||||
global iddb, history
|
global iddb, history
|
||||||
try:
|
try:
|
||||||
@ -117,23 +138,30 @@ def clear_context(message):
|
|||||||
|
|
||||||
@bot.message_handler(func=lambda message: True)
|
@bot.message_handler(func=lambda message: True)
|
||||||
def echo_message(message):
|
def echo_message(message):
|
||||||
|
if bot.get_chat(message.chat.id).type == "private" or message.text[:2] == "/a":
|
||||||
global setted_models, system_prompts
|
global setted_models, system_prompts
|
||||||
|
|
||||||
|
if message.text[:2] == "/a":
|
||||||
|
text = message.text[3:]
|
||||||
|
else:
|
||||||
|
text = message.text
|
||||||
|
|
||||||
id = str(message.chat.id)
|
id = str(message.chat.id)
|
||||||
if id not in setted_models:
|
if id not in setted_models:
|
||||||
setted_models[id] = "0.1"
|
setted_models[id] = "0.1"
|
||||||
|
|
||||||
if id in system_prompts:
|
if id in system_prompts:
|
||||||
if setted_models[id] != 3.5:
|
if setted_models[id] != 3.5:
|
||||||
prompt = '[INST]' + system_prompts[id] + '[/INST]\n\n' + message.text
|
prompt = '[INST]' + system_prompts[id] + '[/INST]\n\n' + text
|
||||||
else:
|
else:
|
||||||
prompt = message.text
|
prompt = text
|
||||||
|
|
||||||
st = bot.send_message(message.chat.id, "Печатает...")
|
st = bot.send_message(message.chat.id, "Печатает...")
|
||||||
try:
|
try:
|
||||||
predicted = gen(prompt, message.chat.id, setted_models[id])
|
predicted = gen(prompt, message.chat.id, setted_models[id])
|
||||||
except:
|
except:
|
||||||
bot.send_message(message.chat.id, "Извините, возникла непредвиденная ошибка")
|
bot.send_message(message.chat.id, "Извините, возникла непредвиденная ошибка")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bot.reply_to(message, predicted, parse_mode="Markdown")
|
bot.reply_to(message, predicted, parse_mode="Markdown")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
|
Loading…
Reference in New Issue
Block a user