Проблема с VkLongPoll, как решить?
import vk_api
import openai
import os
vk_session = vk_api.VkApi(token='')
openai.api_key = ''
model_engine = "davinci"
model = openai.Model(engine=model_engine)
# Обработчик событий
def handle_event(event):
if event['type'] == 'message_new':
user_id = event['object']['message']['from_id']
message_text = event['object']['message']['text']
if message_text.startswith("/mbot"):
prompt = message_text[6:]
response = model.generate(prompt, max_tokens=60)
answer = response.choices[0].text.strip()
vk_session.method('messages.send', {'user_id': user_id, 'message': answer})
if __name__ == '__main__':
longpoll = vk_api.longpoll.VkLongPoll(vk_session, '')
for event in longpoll.listen():
handle_event(event)
На что получаю ответ
Traceback (most recent call last):
File "c:\VKMontez\index.py", line 27, in
longpoll = vk_api.longpoll.VkLongPoll(vk_session, '216471011')
AttributeError: module 'vk_api' has no attribute 'longpoll'