BERTopic
BERTopic copied to clipboard
module 'openai' has no attribute 'OpenAI'
Hi, I am using the newest version of Bertopic
I am getting the error
AttributeError Traceback (most recent call last)
<ipython-input-10-f6a5594a0164> in <cell line: 19>()
17 topic: <topic label>
18 """
---> 19 client = openai.OpenAI(api_key="sk-zu.......")
20 openai_model = OpenAI(client, model="gpt-3.5-turbo", exponential_backoff=True, chat=True, prompt=prompt)
21
AttributeError: module 'openai' has no attribute 'OpenAI'
My code is below :-
import openai
from bertopic.representation import KeyBERTInspired, MaximalMarginalRelevance, OpenAI
# KeyBERT
keybert_model = KeyBERTInspired()
# MMR
mmr_model = MaximalMarginalRelevance(diversity=0.3)
# GPT-3.5
prompt = """
I have a topic that contains the following documents:
[DOCUMENTS]
The topic is described by the following keywords: [KEYWORDS]
Based on the information above, extract a short but highly descriptive topic label of at most 5 words. Make sure it is in the following format:
topic: <topic label>
"""
client = openai.OpenAI(api_key="sk-zu...")
openai_model = OpenAI(client, model="gpt-3.5-turbo", exponential_backoff=True, chat=True, prompt=prompt)
# All representation models
representation_model = {
"KeyBERT": keybert_model,
"OpenAI": openai_model, # Uncomment if you will use OpenAI
"MMR": mmr_model,
"POS": pos_model
}
Not sure, where's the mistake? Thanks in advance
I am using BerTopic best practices colab https://colab.research.google.com/drive/1BoQ_vakEVtojsd2x_U6-_x52OOuqruj2?usp=sharing#scrollTo=uaxb00nfzejc
what was the solve here?