MaartenGr / MaartenGr/BERTopic
random openai issue with plain bertopic use
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.8k
- Forks
- 921
- Avg merge
- 22h 24m
- Merged PRs (30d)
- 5
Description
Hello,
Note, this was running as on April 22nd.
!pip install -U bertopic
import bertopic
bertopic.version
Error log:
AttributeError: module 'openai' has no attribute 'OpenAI'
AttributeError Traceback (most recent call last)
File , line 1
----> 1 import bertopic
2 bertopic.version
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-390f0499-9705-4ba6-ba4a-010185dffaa9/lib/python3.10/site-packages/bertopic/init.py:1
----> 1 from bertopic._bertopic import BERTopic
3 version = "0.16.1"
5 all = [
6 "BERTopic",
7 ]
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-390f0499-9705-4ba6-ba4a-010185dffaa9/lib/python3.10/site-packages/bertopic/_bertopic.py:48
46 from bertopic import plotting
47 from bertopic.cluster import BaseCluster
---> 48 from bertopic.backend import BaseEmbedder
49 from bertopic.representation._mmr import mmr
50 from bertopic.backend._utils import select_backend
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-390f0499-9705-4ba6-ba4a-010185dffaa9/lib/python3.10/site-packages/bertopic/backend/init.py:8
6 # OpenAI Embeddings
7 try:
----> 8 from bertopic.backend._openai import OpenAIBackend
9 except ModuleNotFoundError:
10 msg = "pip install openai \n\n"
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-390f0499-9705-4ba6-ba4a-010185dffaa9/lib/python3.10/site-packages/bertopic/backend/_openai.py:9
5 from typing import List, Mapping, Any
6 from bertopic.backend import BaseEmbedder
----> 9 class OpenAIBackend(BaseEmbedder):
10 """ OpenAI Embedding Model
11
12 Arguments:
(...)
32 ```
33 """
34 def init(self,
35 client: openai.OpenAI,
36 embedding_model: str = "text-embedding-ada-002",
37 delay_in_seconds: float = None,
38 batch_size: int = None,
39 generator_kwargs: Mapping[str, Any] = {}):
File /local_disk0/.ephemeral_nfs/envs/pythonEnv-390f0499-9705-4ba6-ba4a-010185dffaa9/lib/python3.10/site-packages/bertopic/backend/_openai.py:35, in OpenAIBackend()
9 class OpenAIBackend(BaseEmbedder):
10 """ OpenAI Embedding Model
11
12 Arguments:
(...)
32 ```
33 """
34 def init(self,
---> 35 client: openai.OpenAI,
36 embedding_model: str = "text-embedding-ada-002",
37 delay_in_seconds: float = None,
38 batch_size: int = None,
39 generator_kwargs: Mapping[str, Any] = {}):
40 super().init()
41 self.client = client
AttributeError: module 'openai' has no attribute 'OpenAI'
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with bertopic/backend/_openai.py and the import path shown in the traceback, then reproduce the failure with the reported pip install and import commands. Done means importing BERTopic no longer raises the reported AttributeError with the supported OpenAI dependency setup.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100