A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message text is empty

38 Views Asked by At

I get a response but also an error: "A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: message text is empty" but message is not empty and i get response.

And the answer starts with the symbols???:

In the picture, I ask you to write 3 brands of cars, the answer begins with something unclear. enter image description here

import telebot
import openai

bot = telebot.TeleBot("")
openai.api_key = ""


@bot.message_handler(content_types=['text'])
def giveAnswerFromAi(message):
    print(message.chat.title, message.chat.username)
    if message.chat.id == -1002097745017:  # айді чату, де тільки він буде відповідати
        # print(message.text)
        if "@QuestionToAi333_bot" in message.text:
            message.text = message.text.replace("@QuestionToAi333_bot ", "")
            try:
                response = openai.Completion.create(
                    model="gpt-3.5-turbo-instruct",  # використання моделі GPT-3.5 Davinci
                    prompt=message.text,
                    max_tokens=1500
                )
                full_response = response['choices'][0]['text']  # отримання повної відповіді
                if full_response.strip():  # перевірка, чи не є повідомлення порожнім
                    lines = full_response.splitlines()  # розділ на лінії
                    for line in lines:
                        try:
                            bot.send_message(message.chat.id, line)  # відправлення кожного рядка окремо як відповідь
                        except Exception as e:
                            print(e)
                else:
                    print("Empty response from OpenAI")
            except Exception as e:
                print("Error:", e)
    else:
        bot.send_message(message.chat.id,
                         "bot is private, contact - @123123")
        # відповідь в особистих повідомленнях, що бот приватний. надання контакту


bot.polling(none_stop=True, interval=0)

tried asking chatgpt but they didn't fix the problem

0

There are 0 best solutions below