OpenAI API provider

From MoodleDocs

The Moodle integration with OpenAI provides access to AI actions such as generate text, summarise text and explain text.

Requirements

You need an OpenAI account with access to a paid API key.

When setting up an OpenAI account with an API key, although keys can be generate by both free and paid accounts, API usage is restricted based on the paid tokens available on the account. Access to the API used by the Moodle LMS integration requires a subscription to one of OpenAI’s paid API plans (such as pay-as-you-go). Access, usage limits and pricing tiers are dependent on the model used, so it is best to check the OpenAI API pricing page for the latest information.

OpenAI provider instance set-up

To create a provider instance:

  1. Go to Site administration > General > AI providers.
  2. Click 'Create a new provider instance'.
  3. Select OpenAI as AI provider plugin, enter a name and OpenAI API key from your OpenAI account (OpenAI API keys).
  4. If required, enter an OpenAI organization ID from your (OpenAI account).
  5. If required, set a site-wide rate limit and/or a user rate limit.
  6. Click 'Create instance'.

To configure the OpenAI provider instance:

  1. Go to Site administration > General > AI providers.
  2. Click the settings link for OpenAI.
  3. Enable/disable actions as required.

For each action, you can customise the model's behaviour via the settings link.

Generate text, Summarise text and Explain text

  1. Select the AI model. For information, see OpenAI Models. By default, the model is set to GPT-4o.
  2. Enter an API endpoint. Please ensure your API endpoint is compatible with your selected model. For information, see Model endpoint compatibility.
  3. Review and amend the system instruction as necessary.
  4. Enter values for the following settings as required and save changes.
  • top_p - top_p (nucleus sampling) determines how many possible words to consider. A high value (e.g. 0.9) means the model looks at more words, which makes the generated text more diverse.
  • max_tokens - The maximum number of tokens used in the generated text.
  • frequency_penalty - The frequency penalty adjusts how often words are repeated. The higher the penalty, the less repetitions in the generated text.
  • presence_penalty - The presence penalty encourages the model to use new words by increasing the likelihood of choosing words it hasn't used before. A higher value makes the generated text more diverse, while a lower value allows more repetition.

Generate image

  • Select the AI model. For information, see DALL-E Models. The default is set to dall-e-3 but it can be changed to  any other image generation compatible model.
  • Enter the API endpoint. Please ensure your API endpoint is compatible with your selected model.

To enable the OpenAI provider instance:

  1. Go to Site administration > General > AI providers.
  2. Click the toggle to enable the instance.