Skip to content

Support api_key parameter in Moderation.create method #122

Closed

Description

@zafercavdar

Description

create method in Moderation class initializes a new instance by calling parent constructor without any parameters. That's why it's impossible make Moderationendpoint 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 in Moderation.create
  • Pass api_key to super class

Activity

  1. changed the title [-]Support api_key parameter in Moderation class[/-] [+]Support api_key parameter in Moderation.create method[/+] on Sep 16, 2022
  2. hallacy commented on Sep 18, 2022

    @hallacy
    Contributor

    Hey @zafercavdar! Thanks for reporting the issue. I'll continue the discussion on the PR just to keep the conversation in one place

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions