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

Getting TypeError: OpenAI.__init__() missing 1 required positional argument: 'client' because older version of openai being used #242 #243

Open
shashnkvats opened this issue Jul 11, 2024 · 1 comment

Comments

@shashnkvats
Copy link

I was trying to implement the code below that was provided in the documentation

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

# Create your LLM
openai.api_key = "sk-..."

prompt = """
I have the following document:
[DOCUMENT]

With the following candidate keywords:
[CANDIDATES]

Based on the information above, improve the candidate keywords to best describe the topic of the document.

Use the following format separated by commas:
<keywords>
"""
llm = OpenAI(model="gpt-3.5-turbo", prompt=prompt, chat=True)

# Load it in KeyLLM
kw_model = KeyLLM(llm)

# Extract keywords
candidate_keywords = [['website', 'couple of days', 'deliver', 'received'],
 ['received', 'package'],
 ['most powerful LLMs',
  'limited APIs',
  'Meta',
  "LLaMA's model weights",
  'research community',
  'noncommercial license']]
keywords = kw_model.extract_keywords(documents, candidate_keywords=candidate_keywords); keywords

when I got the error,

TypeError Traceback (most recent call last)
in <cell line: 20>()
18
19 """
---> 20 llm = OpenAI(model="gpt-3.5-turbo", prompt=prompt, chat=True)
21
22 # Load it in KeyLLM

TypeError: OpenAI.init() missing 1 required positional argument: 'client'

Is it because only the older version of Openai is supported?

@MaartenGr
Copy link
Owner

Ah, it seems that the documentation should be updated. When you use the latest version of OpenAI (older versions are not supported since the major API changes), you can run it as follows:

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)

# Extract keywords
document = "The website mentions that it only takes a couple of days to deliver but I still have not received mine."
keywords = kw_model.extract_keywords(document)

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