Add GPT 3.5 for free!

main
Your Name 9 months ago
parent 69a4408bc8
commit 18a1d261ba

@ -1,4 +1,5 @@
from gradio_client import Client
from chat_api import *
from deep_translator import GoogleTranslator
@ -67,19 +68,31 @@ def gen(text, id, model):
client = Client("https://afischer1985-ai-interface.hf.space/")
elif model == "0.2":
client = Client("https://skier8402-mistral-super-fast.hf.space/")
if not model == "3.5":
iddb[str(id)] = client
else:
if not model == "3.5":
client = iddb[str(id)]
prompt = translate(text, "ru")
success = False
while not success:
try:
if model == "0.1" or model == "0.2":
prompt = translate(text, "ru")
predicted = predict(prompt, client, model).replace("</s>", "")
predicted = translate(predicted, "en")
success = True
elif model == "3.5":
# ChatGPT
global setted_models
prompt = text
try:
inst = setted_models[id]
except:
inst = None
predicted = chat_predict(prompt, id, inst)
success = True
except:
pass
fixed = predicted.replace(r'\n', '\n').replace('\\ n', '\n')
return translate(fixed, "en")
return fixed

@ -0,0 +1,18 @@
import g4f
global history
history = {}
def chat_predict(prompt, id, sys_inst = None):
global history
if id not in history:
history[id] = [{"role": "user", "content": prompt}]
else:
history[id].append({"role": "user", "content": prompt})
if sys_inst:
history[id] = [{"role": "system", "content": sys_inst}]
predicted = g4f.ChatCompletion.create(model="gpt-3.5-turbo", messages=history[id])
history[id].append({"role": "assistant", "content": predicted})
return predicted

@ -23,9 +23,11 @@ bot = telebot.TeleBot(API_TOKEN)
def send_welcome(message):
bot.reply_to(message, f"""Это подобие ChatGPT на минималках.
__ Есть 2 версии:
{telebot.formatting.hcode("/m 0.1")} - Простейшая, быстрая, краткая, не помнит что вы говорили.
__ Есть 3 версии:
{telebot.formatting.hcode("/m 0.1")} - Простейшая, быстрейшая, краткая, не помнит что вы говорили.
{telebot.formatting.hcode("/m 0.2")} - Умнее, относительно быстрая, помнит что вы говорили.
{telebot.formatting.hcode("/m 3.5")} - Самая умная, есть цензура, помнит что вы говорили.
(1,2 - Mistral, 3 - ChatGPT)
__ Список кратких команд:
/info - /i
@ -77,7 +79,7 @@ def set_model(message):
pass
model = message.text.split()[1]
if model == "0.1" or model == "0.2":
if model == "0.1" or model == "0.2" or model == "3.5":
setted_models[str(message.chat.id)] = model
bot.reply_to(message, "Установлена новая модель 🤖")
else:
@ -101,17 +103,17 @@ def clear_prompt(message):
@bot.message_handler(commands=['ccontext','cc'])
def clear_context(message):
global iddb
global iddb, history
try:
iddb.pop(str(message.chat.id))
except:
pass
try:
history[id] = []
except:
pass
bot.reply_to(message, "Контекст очищен 🤖")
#@bot.message_handler(commands=['onoff'])
#def set_onoff(message):
#
@bot.message_handler(func=lambda message: True)
def echo_message(message):
@ -122,12 +124,16 @@ def echo_message(message):
setted_models[id] = "0.1"
if id in system_prompts:
if setted_models[id] != 3.5:
prompt = '[INST]' + system_prompts[id] + '[/INST]\n\n' + message.text
else:
prompt = message.text
st = bot.send_message(message.chat.id, "Печатает...")
try:
predicted = gen(prompt, message.chat.id, setted_models[id])
except:
bot.send_message(message.chat.id, "Извините, возникла непредвиденная ошибка")
try:
bot.reply_to(message, predicted, parse_mode="Markdown")
except Exception as e:

Loading…
Cancel
Save