Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyLLM error: AttributeError: 'str' object has no attribute 'completions' #223

Open
anonimoustt opened this issue May 6, 2024 · 9 comments

Comments

@anonimoustt
Copy link

anonimoustt commented May 6, 2024

I was trying to run the following code from your GitHub but got the following error:
import openai
from keybert.llm import OpenAI
from keybert import KeyLLM
from sentence_transformers import SentenceTransformer

Extract embeddings

model = SentenceTransformer('all-MiniLM-L6-v2')
embeddings = model.encode(documents, convert_to_tensor=True)

Create your LLM

openai.api_key = "sk..."#
llm = OpenAI(openai.api_key)

Load it in KeyLLM

kw_model = KeyLLM(llm)

Extract keywords

keywords = kw_model.extract_keywords(documents, embeddings=embeddings, threshold=.75)

AttributeError: 'str' object has no attribute 'completions'

@MaartenGr
Copy link
Owner

There might be a fix for this in the main branch. Could you install keybert using the latest commit? It might resolve your issue. Also, make sure to install the latest version of openai.

@anonimoustt
Copy link
Author

Hi,

Would you please share the latest commit of keybert? I am trying pip install -U keybert command . Thanks

@MaartenGr
Copy link
Owner

You can find more information about how to install it here: https://stackoverflow.com/questions/13685920/install-specific-git-commit-with-pip

@anonimoustt
Copy link
Author

Still getting the error: AttributeError: 'str' object has no attribute 'completions'. I tried with !pip install git+https://github.com/MaartenGr/KeyBERT.git

@MaartenGr
Copy link
Owner

Which version of openai are you using? Have you tried using the latest version?

@anonimoustt
Copy link
Author

Hi, I have used the latest version of OpenAI but I am getting same error. I have a query regarding Efficient LLM in https://maartengr.github.io/KeyBERT/guides/keyllm.html#3-fine-tune-candidate-keywords. You mentioned, if two texts appear together in a cluster, then two texts will have the same keywords. It implies the keywords of text1 can be used as the keywords for the text2? Is it feasible for all cases?

@MaartenGr
Copy link
Owner

@anonimoustt After installing the latest version of openai as well as keybert through the main branch, could you share the full error message? That will tell me where it goes wrong exactly.

You mentioned, if two texts appear together in a cluster, then two texts will have the same keywords. It implies the keywords of text1 can be used as the keywords for the text2? Is it feasible for all cases?

It depends on your definition of "all cases". Having said that, in my experience this works as long as you define properly (through clustering thresholds) when you consider two texts to be similar enough.

@anonimoustt
Copy link
Author

Hi, here is link of google colab code: https://colab.research.google.com/drive/16LbHeLs93Re-sA9kgMHqAPsa3A79KQvB?usp=sharing

AttributeError: 'str' object has no attribute 'completions'

@MaartenGr
Copy link
Owner

Ah, it seems that the documentation should be updated. You should pass a openai.OpenAI client instead of the key:

import openai
from keybert.llm import OpenAI
from keybert import KeyLLM

# Create your LLM
client = openai.OpenAI(api_key=MY_API_KEY)
llm = OpenAI(client)

# Load it in KeyLLM
kw_model = KeyLLM(llm)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants