BerTopic OpenAI Embedding parameter

I want to use openai embeddings for bertopic emmbeding parameter
but i cannot use because of version changes

my code

Bertopic Documentation for openai embeddings
Ekran görüntüsü 2024-01-03 170222

It looks like you might be using an older pip version of openai.
Have you tried upgrading it?

pip3 install openai --upgrade
1 Like

Yes, I tried to upgrade the OpenAI version, but this time another error occurred.

Welcome to the amazing world of OpenAI API libs!
Welcome to the amazing world of python!

It says in the error message: consider running pip install openai==0.28.1

check your version then with pip show openai

you may run into the problem again you had in the first post, but it’s possible that that was an issue with the 1.0 versions, so you might not.

1 Like

Yes, as you suggested, I installed and tried version 0.28.1, but the result remains the same; it still gives an error.

unfortunately, I can’t reproduce it - it works on my machine with this configuration

I don’t know if openai was actually a function at some point so it was just openai(api_key...) but I’m not 100% certain.

Ideally, I’d suggest you step into the openai import and see what you’re actually importing, but if you’re not experienced enough for that, and until someone comes along that remembers how the call went, we can try this:

I see you have jupyter

can you try doing a minimal attempt at getting the client to work?

import os
import openai

client = openai.OpenAI(
    # This is the default and can be omitted

chat_completion =
            "role": "user",
            "content": "Say this is a test",

and if that doesn’t work, the output from




I’m restricted to phone-only access here.

This is an active GitHub issue.

Temporary solution is to downgrade as mentioned. Then you need to initialize openai using the old builder way.

import openai

openai.api_key = "bop"

If you’re feeling helpful you can migrate the library instead

1 Like

okay, I can try

Ekran görüntüsü 2024-01-06 141211

solved the problem but with another method thanks for your help
I could not understand the cause of the error,
it was enough to create a custom embedding builder
I share the solution