hotfix
This commit is contained in:
+11
-39
@@ -6,7 +6,7 @@ import openai
|
|||||||
|
|
||||||
async def get_response_to_openai(message: types.Message, bot):
|
async def get_response_to_openai(message: types.Message, bot):
|
||||||
if message.from_user.id in json.load(open("not_work_user.json"))["chat_gpt"]:
|
if message.from_user.id in json.load(open("not_work_user.json"))["chat_gpt"]:
|
||||||
await bot.send_message(message.chat.id, "ПИШЁВ ТИ НАХУЙ")
|
await bot.send_message(message.chat.id, "тебе сюда нельзя")
|
||||||
return
|
return
|
||||||
conn = sqlite3.connect('db.sql')
|
conn = sqlite3.connect('db.sql')
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
@@ -19,7 +19,7 @@ async def get_response_to_openai(message: types.Message, bot):
|
|||||||
message_send.append({"role": "user", "content": ' '.join(message.text.split()[1:])})
|
message_send.append({"role": "user", "content": ' '.join(message.text.split()[1:])})
|
||||||
except sqlite3.OperationalError:
|
except sqlite3.OperationalError:
|
||||||
message_send = [{"role": "user", "content": ' '.join(message.text.split()[1:])}]
|
message_send = [{"role": "user", "content": ' '.join(message.text.split()[1:])}]
|
||||||
print(message_send)
|
try:
|
||||||
response = openai.ChatCompletion.create(
|
response = openai.ChatCompletion.create(
|
||||||
model="gpt-3.5-turbo",
|
model="gpt-3.5-turbo",
|
||||||
messages=message_send,
|
messages=message_send,
|
||||||
@@ -31,6 +31,15 @@ async def get_response_to_openai(message: types.Message, bot):
|
|||||||
)
|
)
|
||||||
await bot.send_message(message.chat.id, f"ChatGPT\n{response['choices'][0]['message']['content']}",
|
await bot.send_message(message.chat.id, f"ChatGPT\n{response['choices'][0]['message']['content']}",
|
||||||
parse_mode=None, reply_to_message_id=message.message_id)
|
parse_mode=None, reply_to_message_id=message.message_id)
|
||||||
|
except Exception as e:
|
||||||
|
print(e)
|
||||||
|
conn = sqlite3.connect('db.sql')
|
||||||
|
cur = conn.cursor()
|
||||||
|
cur.execute(f"DELETE FROM '{str(message.from_user.id)}'")
|
||||||
|
conn.commit()
|
||||||
|
conn.close()
|
||||||
|
await bot.send_message(message.chat.id, "У вас превышено количество сообщений в памяти, я всё очистил"
|
||||||
|
" попробуйте задать вопрос заново))")
|
||||||
try:
|
try:
|
||||||
cur.execute("INSERT INTO 'f' (role, content) VALUES (?, ?)".replace("f", str(message.from_user.id)),
|
cur.execute("INSERT INTO 'f' (role, content) VALUES (?, ?)".replace("f", str(message.from_user.id)),
|
||||||
("user", ' '.join(message.text.split()[1:])))
|
("user", ' '.join(message.text.split()[1:])))
|
||||||
@@ -56,40 +65,3 @@ async def clear_db(message: types.Message):
|
|||||||
cur.execute(f"DELETE FROM '{str(message.from_user.id)}'")
|
cur.execute(f"DELETE FROM '{str(message.from_user.id)}'")
|
||||||
conn.commit()
|
conn.commit()
|
||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
def get_response(message: types.Message):
|
|
||||||
answer_en = get_translation(' '.join(message.text.split()[1:]), "en")
|
|
||||||
# print(answer_en)
|
|
||||||
# response_en = get_response_to_openai(answer_en)
|
|
||||||
# print(response_en)
|
|
||||||
# response_ru = get_translation(response_en, "ru")
|
|
||||||
# resource_ru_not_translate = get_response_to_openai(' '.join(message.text.split()[1:]))
|
|
||||||
# save_file(response_ru, resource_ru_not_translate)
|
|
||||||
|
|
||||||
|
|
||||||
def get_translation(text, language):
|
|
||||||
from deep_translator import GoogleTranslator
|
|
||||||
return GoogleTranslator(target=language).translate(text)
|
|
||||||
|
|
||||||
|
|
||||||
# def get_response_to_openai(text):
|
|
||||||
# import openai
|
|
||||||
# openai.api_key = "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"
|
|
||||||
# response = openai.Completion.create(
|
|
||||||
# model="text-davinci-003",
|
|
||||||
# prompt=text,
|
|
||||||
# temperature=0.5,
|
|
||||||
# max_tokens=1000,
|
|
||||||
# top_p=1.0,
|
|
||||||
# frequency_penalty=0.5,
|
|
||||||
# presence_penalty=0.0
|
|
||||||
# )
|
|
||||||
# return response['choices'][0]['text']
|
|
||||||
|
|
||||||
|
|
||||||
def save_file(response_ru, resource_ru_not_translate):
|
|
||||||
with open('response_ru.txt', 'w') as f:
|
|
||||||
f.write(response_ru)
|
|
||||||
with open('resource_ru_not_translate.txt', 'w') as f:
|
|
||||||
f.write(resource_ru_not_translate)
|
|
||||||
|
|||||||
+1
-1
@@ -43,7 +43,7 @@ async def r_clear(message: types.Message):
|
|||||||
|
|
||||||
@dp.message_handler(content_types=['text'])
|
@dp.message_handler(content_types=['text'])
|
||||||
async def not_work_user(message: types.Message):
|
async def not_work_user(message: types.Message):
|
||||||
if str(message.from_user.id) == "620318992" and message.text == "Гена, бань его нахуй" and message.reply_to_message:
|
if str(message.from_user.id) == "620318992" and message.text == "Гена, бань его" and message.reply_to_message:
|
||||||
with open('../not_work_user.json', 'r') as f:
|
with open('../not_work_user.json', 'r') as f:
|
||||||
data = json.load(f)
|
data = json.load(f)
|
||||||
data['chat_gpt'].append(message.reply_to_message.from_user.id)
|
data['chat_gpt'].append(message.reply_to_message.from_user.id)
|
||||||
|
|||||||
Reference in New Issue
Block a user