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: 'CompletionChoice' object has no attribute 'message' #224

Open
cdolek opened this issue May 8, 2024 · 6 comments

Comments

@cdolek
Copy link

cdolek commented May 8, 2024

using openai v1.27.0

AttributeError: 'CompletionChoice' object has no attribute 'message'
@Guillem96
Copy link

Same here

@MaartenGr
Copy link
Owner

Could you share the full error message? Also, did you try installing KeyBERT from the main branch?

@cdolek
Copy link
Author

cdolek commented May 9, 2024

Keybert version as installed via poetry:

pip list | grep keybert
keybert                            0.8.4

Full error message:

...
...
     63 embeddings = embedding_model.encode(docs, convert_to_tensor=True)
     65 # Extract keywords
---> 66 keywords = kw_model.extract_keywords(
     67     docs,
     68     embeddings=embeddings,
     69     threshold=.75,
     70 )
     71 logger.info(f"Keywords: {keywords}")
     72 return keywords

File ~/miniconda3/envs/_____/lib/python3.10/site-packages/keybert/_llm.py:107, in KeyLLM.extract_keywords(self, docs, check_vocab, candidate_keywords, threshold, embeddings)
    105     else:
    106         selected_keywords = None
--> 107     in_cluster_keywords = self.llm.extract_keywords(
    108         selected_docs,
    109         selected_keywords
    110     )
    111     in_cluster_keywords = {
    112         doc_id: in_cluster_keywords[index] 
    113         for index, cluster in enumerate(clusters)
    114         for doc_id in cluster
    115     }
    117 # Update out cluster keywords with in cluster keywords

File ~/miniconda3/envs/_____/lib/python3.10/site-packages/keybert/llm/_openai.py:189, in OpenAI.extract_keywords(self, documents, candidate_keywords)
    187     else:
    188         response = self.client.completions.create(model=self.model, prompt=prompt, **self.generator_kwargs)
--> 189     keywords = response.choices[0].message.content.strip()
    190 keywords = [keyword.strip() for keyword in keywords.split(\",\")]
    191 all_keywords.append(keywords)

File ~/miniconda3/envs/_____/lib/python3.10/site-packages/pydantic/main.py:792, in BaseModel.__getattr__(self, item)
    789     return super().__getattribute__(item)  # Raises AttributeError if appropriate
    790 else:
    791     # this is the current error
--> 792     raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')

AttributeError: 'CompletionChoice' object has no attribute 'message'"

@MaartenGr
Copy link
Owner

@cdolek Thanks for sharing. I have a feeling that this is not the full error message since there are multiple steps missing in the message. It is not possible that line 107 itself raises this error as it points towards another line in the code. Could you see whether you can get the full error message?

Also, did you try installing KeyBERT from the main branch? I believe there was a fix there implemented a while ago.

@cdolek
Copy link
Author

cdolek commented May 9, 2024

@MaartenGr I installed keybert as a package not by cloning the main branch. I just checked if the version of package matched with the repo. But, I can try cloning as well.

Updated the error message above to include full output.

@MaartenGr
Copy link
Owner

@cdolek Yes, based on the error message, cloning from the main branch might just fix the issue.

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

3 participants