Выдает ошибку при запуске бота с встроенным чатомгпт
Бот отвечает лишь на команду /start и чатгпт генерирует лишь 1 ответ, затем терминале появляется эта ошибка. Сам код и ошибку прикреплю ниже.
Сам код:
import telebot
import config
import openai
openai.api_key = config.openai_token
bot = telebot.TeleBot(config.Bot)
def make_post(text):
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[
{"role": "user", "content": "You are an advanced psychologist."
"You can provide emotional support, guidance and advice to users facing a variety of personal problems such as stress, anxiety and relationships. "
"You must not reply to topics that are not related to psychology. "
"You are obliged to ask no more than one question of your interlocutor."
"You must answer only in Russian."
"You are obliged to answer like the psychologist Carl Rogers.\n" + text + "\n"}
]
)
return response.choices[0].message.content
@bot.message_handler(commands=['start'])
def show_start(message):
bot.send_message(message.chat.id, text="Привет!")
@bot.message_handler(content_types=['text'])
def show_response(message):
bot.send_message(message.chat.id, text=make_post(message.text))
bot.polling()
ошибка:
Traceback (most recent call last):
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/main.py", line 33, in <module>
bot.polling()
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/__init__.py", line 1043, in polling
self.__threaded_polling(non_stop=non_stop, interval=interval, timeout=timeout, long_polling_timeout=long_polling_timeout,
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/__init__.py", line 1118, in __threaded_polling
raise e
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/__init__.py", line 1074, in __threaded_polling
self.worker_pool.raise_exceptions()
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/util.py", line 147, in raise_exceptions
raise self.exception_info
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/util.py", line 90, in run
task(*args, **kwargs)
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/telebot/__init__.py", line 6770, in _run_middlewares_and_handler
result = handler['function'](message)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/main.py", line 31, in show_response
bot.send_message(message.chat.id, text=make_post(message.text))
^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/main.py", line 9, in make_post
response = openai.ChatCompletion.create(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/openai/api_resources/chat_completion.py", line 25, in create
return super().create(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create
response, _, api_key = requestor.request(
^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/openai/api_requestor.py", line 230, in request
resp, got_stream = self._interpret_response(result, stream)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/openai/api_requestor.py", line 624, in _interpret_response
self._interpret_response_line(
File "/Users/ekaterina/PycharmProjects/УМ Бот-психолог/venv/lib/python3.11/site-packages/openai/api_requestor.py", line 687, in _interpret_response_line
raise self.handle_error_response(
openai.error.APIError: The server had an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID 5562c88df5a6906c8ee055005a399d6d in your message.) {
"error": {
"message": "The server had an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID 5562c88df5a6906c8ee055005a399d6d in your message.)",
"type": "server_error",
"param": null,
"code": null
}
}
500 {'error': {'message': 'The server had an error while processing your request. Sorry about that! You can retry your request, or contact us through our help center at help.openai.com if the error persists. (Please include the request ID 5562c88df5a6906c8ee055005a399d6d in your message.)', 'type': 'server_error', 'param': None, 'code': None}} {'Date': 'Tue, 23 May 2023 10:35:25 GMT', 'Content-Type': 'application/json', 'Content-Length': '366', 'Connection': 'keep-alive', 'access-control-allow-origin': '*', 'openai-processing-ms': '113', 'openai-version': '2020-10-01', 'strict-transport-security': 'max-age=15724800; includeSubDomains', 'x-ratelimit-limit-requests': '3', 'x-ratelimit-limit-tokens': '40000', 'x-ratelimit-remaining-requests': '1', 'x-ratelimit-remaining-tokens': '39880', 'x-ratelimit-reset-requests': '33.665s', 'x-ratelimit-reset-tokens': '180ms', 'x-request-id': '5562c88df5a6906c8ee055005a399d6d', 'CF-Cache-Status': 'DYNAMIC', 'Server': 'cloudflare', 'CF-RAY': '7cbca6ec49301672-DME', 'alt-svc': 'h3=":443"; ma=86400, h3-29=":443"; ma=86400'}
Process finished with exit code 1