upd
This commit is contained in:
parent
b72336c297
commit
11affc09a6
34
bot.py
34
bot.py
@ -164,26 +164,15 @@ def send_voice_text(call):
|
|||||||
transcription_hash = call.data.split(':')[1]
|
transcription_hash = call.data.split(':')[1]
|
||||||
voice_text = transcription_dict.get(transcription_hash)
|
voice_text = transcription_dict.get(transcription_hash)
|
||||||
|
|
||||||
|
answer = bot.reply_to(call.message, "Подождите, я думаю...")
|
||||||
|
|
||||||
if voice_text:
|
if voice_text:
|
||||||
# Generate a response using the ChatGPT model
|
# Generate a response using the ChatGPT model
|
||||||
(response_text, reason, cost) = generate_chat_response(voice_text)
|
(response_text, reason, cost) = generate_chat_response(voice_text)
|
||||||
|
|
||||||
print(response_text)
|
print(response_text)
|
||||||
|
|
||||||
# Send the response back to the user with markdown formatting
|
send_response(call.message, answer, response_text, reason, cost)
|
||||||
try:
|
|
||||||
ans = bot.send_message(chat_id=call.message.chat.id, text=response_text , parse_mode='Markdown')
|
|
||||||
if reason != "stop":
|
|
||||||
bot.reply_to(ans, f"Finish reason: {reason} \nCost: {cost}")
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
bot.send_message(chat_id=call.message.chat.id, text="Что-то пошло не так c ответом. Пробую другой метод...")
|
|
||||||
|
|
||||||
try:
|
|
||||||
bot.send_message(chat_id=call.message.chat.id, text=response_text)
|
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
|
||||||
bot.send_message(chat_id=call.message.chat.id, text="Что-то пошло не так c ответом")
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
bot.send_message(chat_id=call.message.chat.id, text="Не удалось получить текст голосового сообщения.")
|
bot.send_message(chat_id=call.message.chat.id, text="Не удалось получить текст голосового сообщения.")
|
||||||
@ -202,16 +191,27 @@ def handle_message(message):
|
|||||||
print(response_text)
|
print(response_text)
|
||||||
|
|
||||||
# Send the response back to the user with markdown formatting
|
# Send the response back to the user with markdown formatting
|
||||||
|
send_response(message, answer, response_text, reason, cost)
|
||||||
|
|
||||||
|
|
||||||
|
def send_response(message, answer, response_text, reason, cost):
|
||||||
try:
|
try:
|
||||||
ans = bot.edit_message_text(chat_id=message.chat.id, message_id=answer.message_id, text=f"Finish reason: {reason} \nCost: {cost}" )
|
if "stop" not in reason:
|
||||||
|
ans = bot.edit_message_text(chat_id=message.chat.id, message_id=answer.message_id, text=f"Finish reason: {reason} \nCost: {cost}" )
|
||||||
|
bot.reply_to(ans, response_text, parse_mode='Markdown')
|
||||||
|
|
||||||
|
else:
|
||||||
|
bot.delete_message(chat_id=message.chat.id, message_id=answer.message_id)
|
||||||
|
bot.reply_to(message, text=response_text, parse_mode='Markdown')
|
||||||
|
|
||||||
# Send response text with reason and cost formated
|
# Send response text with reason and cost formated
|
||||||
bot.reply_to(ans, response_text, parse_mode='Markdown')
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot.reply_to(message, "Что-то пошло не так c ответом. Пробую другой метод...")
|
bot.reply_to(message, "Что-то пошло не так c ответом. Пробую другой метод...")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
bot.edit_message_text(chat_id=message.chat.id, message_id=answer.message_id, text=response_text)
|
bot.reply_to(message, text=response_text)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
bot.reply_to(message, "Что-то пошло не так c ответом...")
|
bot.reply_to(message, "Что-то пошло не так c ответом...")
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user