I'm developing a chatbot using OpenAI's Assistants API and facing an issue with integrating the Thread functionality. When trying to create a thread using openai.Thread.create, I encounter an AttributeError stating that the 'openai' module has no attribute 'Thread'.
Here's the code:
import openaiopenai.api_key = "my_key"def my_chatbot(user_input, assistant_id): thread_id = openai.Thread.create(assistant=assistant_id)["id"] openai.Message.create( thread=thread_id, role="user", content=user_input ) run = openai.Run.create( thread=thread_id, assistant=assistant_id ) messages = openai.Message.list(thread=thread_id) return messages["data"][-1]["content"]if __name__ == "__main__": assistant_id = "my_id" while True: user_input = input("Você: ") if user_input.lower() in ["sair", "fechar"]: break chatbot_response = my_chatbot(user_input, assistant_id) print("Chatbot:", chatbot_response)The error message is
Traceback (most recent call last): File "/Users/felipestoker/PycharmProjects/chatbot/main.py", line 34, in <module> chatbot_response = chatbot_webjasper(user_input, assistant_id) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/felipestoker/PycharmProjects/chatbot/main.py", line 8, in chatbot_webjasper thread_id = openai.Thread.create(assistant=assistant_id)["id"] ^^^^^^^^^^^^^AttributeError: module 'openai' has no attribute 'Thread'