I have a problem in my code, it keeps giving me this error and I don’t know how to solve it, I would like your help
codigo:
from openai import OpenAI
import telebot
client = OpenAI(
api_key=“api”
bot = telebot.TeleBot(“token”, parse_mode=None)
@bot.message_handler(commands=[‘start’, ‘help’])
def send_welcome(message):
bot.reply_to(message, “Howdy, how are you doing?”)
@bot.message_handler(func=lambda message: True)
def telegram_bot_message(message):
message_text = message.text.lower()
chat_completion = client.chat.completions.create(
messages=[
{
"role": "user",
"content": message_text,
}
],
model="gpt-3.5-turbo-1106",
)
model_response = chat_completion['choices'][0]['message']['content']
# Send the response back to the user
bot.reply_to(message, model_response)
bot.infinity_polling()
error that keeps giving is this:
model_response = chat_completion[‘choices’][0][‘message’][‘content’]
~~~~~~~~~~~~~~~^^^^^^^^^^^
TypeError: ‘ChatCompletion’ object is not subscriptable