You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

138 lines
3.6 KiB

10 months ago
import telebot
### LOAD TOKEN ###
import json, os
if not os.path.exists('db.json'):
db = {"token": "None"}
js = json.dumps(db, indent=2)
with open("db.json", "w") as outfile:
outfile.write(js)
print('Input token in "None" (db.json)')
exit()
with open('db.json', 'r') as openfile:
db = json.load(openfile)
API_TOKEN = db["token"]
bot = telebot.TeleBot(API_TOKEN)
##################
10 months ago
@bot.message_handler(commands=['help', 'start'])
def send_welcome(message):
bot.reply_to(message, f"""Это подобие ChatGPT на минималках.
__ Есть 2 версии:
{telebot.formatting.hcode("/m 0.1")} - Простейшая, быстрая, краткая, не помнит что вы говорили.
{telebot.formatting.hcode("/m 0.2")} - Умнее, относительно быстрая, помнит что вы говорили.
__ Список кратких команд:
/info - /i
/model - /m
/ccontext - /cc
/prompt - /p
/cprompt - /cp
Канал разработчика: @justuser31
Ещё проекты: @just_openbots (тут много интересного)
{telebot.formatting.hlink("Исходный код","https://gitea.gulyaipole.fun/justuser/just_minigpt")}
""", parse_mode = "HTML")
10 months ago
### MAIN ###
from api import *
setted_models = {}
system_prompts = {}
onoff = {}
@bot.message_handler(commands=['info','i'])
def info(message):
global setted_models, system_prompts
id = str(message.chat.id)
if id not in setted_models:
setted_models[id] = "0.1"
if id not in system_prompts:
prompt = "None"
else:
prompt = system_prompts[str(message.chat.id)]
bot.send_message(message.chat.id, f"""____ Информация ____
Версия: {setted_models[id]}
System-prompt: {telebot.formatting.hcode(prompt)}
""", parse_mode="HTML")
@bot.message_handler(commands=['model','m'])
def set_model(message):
global setted_models, iddb
try:
iddb.pop(str(message.chat.id))
except:
pass
model = message.text.split()[1]
if model == "0.1" or model == "0.2":
setted_models[str(message.chat.id)] = model
bot.reply_to(message, "Установлена новая модель 🤖")
else:
bot.reply_to(message, "Неизвестная модель")
@bot.message_handler(commands=['prompt','p'])
def set_prompt(message):
global system_prompts
system_prompts[str(message.chat.id)] = message.text[8:]
bot.reply_to(message, "Установлен новый system-prompt 🤖")
@bot.message_handler(commands=['cprompt','cp'])
def clear_prompt(message):
global system_prompts
try:
system_prompts.pop(str(message.chat.id))
except:
pass
bot.reply_to(message, "System-prompt очищен 🤖")
@bot.message_handler(commands=['ccontext','cc'])
def clear_context(message):
global iddb
try:
iddb.pop(str(message.chat.id))
except:
pass
bot.reply_to(message, "Контекст очищен 🤖")
#@bot.message_handler(commands=['onoff'])
#def set_onoff(message):
#
10 months ago
@bot.message_handler(func=lambda message: True)
def echo_message(message):
global setted_models, system_prompts
10 months ago
id = str(message.chat.id)
if id not in setted_models:
setted_models[id] = "0.1"
if id in system_prompts:
prompt = '[INST]' + system_prompts[id] + '[/INST]\n\n' + message.text
else:
prompt = message.text
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.delete_message(message.chat.id, st.id)
10 months ago
############
bot.infinity_polling()