Support api_key parameter in Moderation.create method
zafercavdar opened this issue · comments
Zafer Cavdar commented
Description
create
method in Moderation
class initializes a new instance by calling parent constructor without any parameters. That's why it's impossible make Moderation
endpoint calls without setting API key as environment variable or setting it through openai.api_key
in contrast to Completion
class.
How to reproduce
import openai
openai.api_key = None
moderator = openai.Moderation(api_key=api_key)
text = "hello world"
response = moderator.create(input=text, model="text-moderation-stable")
> AuthenticationError: No API key provided. You can set your API key in code using 'openai.api_key = <API-KEY>',
or you can set the environment variable OPENAI_API_KEY=<API-KEY>).
If your API key is stored in a file, you can point the openai module at it with 'openai.api_key_path = <PATH>'.
You can generate API keys in the OpenAI web interface. See https://onboard.openai.com for details, or email support@openai.com if you have any questions.
Potential solution
- Accept
api_key
parameter inModeration.create
- Pass
api_key
to super class
hallacy commented
Hey @zafercavdar! Thanks for reporting the issue. I'll continue the discussion on the PR just to keep the conversation in one place