OpenAI API provider: Difference between revisions

From MoodleDocs
mNo edit summary
info updated for 5.0
 
Line 1: Line 1:
{{AI subsystem}}
{{AI subsystem}}
Moodle LMS’s integration with OpenAI provides access to AI Actions such as generate text, generate image or summarise course content.  
The Moodle integration with [https://platform.openai.com/docs/overview OpenAI] provides access to AI actions such as generate text, summarise text and explain text.


For more information about OpenAI, see https://platform.openai.com.
==Requirements==


==Requirements==
You need an OpenAI account with access to a paid API key.  
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 [https://openai.com/api/pricing/ OpenAI API pricing page] for the latest information.
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 [https://openai.com/api/pricing/ OpenAI API pricing page] for the latest information.


==Configuring OpenAI API provider settings==
==OpenAI provider instance set-up==
#Go to ''Site administration > General > AI > AI providers''.
 
#Enable the "OpenAI API Provider" by clicking on the “Enabled” toggle.
To create a provider instance:
#Click on the "OpenAI API Provider" settings link.
#In the “Settings” area proceed to configure the following:
#*OpenAI API key: You can get the key from your OpenAI account / API Keys ([https://platform.openai.com/account/api-keys OpenAI API keys]).
#*OpenAI organization ID: You find this in  your OpenAI account / Organization settings page ([https://platform.openai.com/account/org-settings OpenAI account]).
#*Set site-wide rate limit: An optional feature to limit the number of requests that the OpenAI API Provider can receive across the entire site every hour.
#* Maximum number of site-wide requests can be configured after enable “Set site-wide rate limit”.
#*Set user rate limit: An optional feature to limit the number of AI requests each user can make to this provider each hour.
#*Maximum number of requests per user can be configured after enable “Set user rate limit”.
# In the “Actions” area you can control which available Actions are enabled and configure further Action settings.<br />


== Configuring OpenAI API provider actions==
# Go to ''Site administration > General > AI providers''.
# Click 'Create a new provider instance'.
# Select OpenAI as AI provider plugin, enter a name and OpenAI API key from your OpenAI account ([https://platform.openai.com/account/api-keys OpenAI API keys]).
# If required, enter an OpenAI organization ID from your ([https://platform.openai.com/account/org-settings OpenAI account]).
# If required, set a site-wide rate limit and/or a user rate limit.
# Click 'Create instance'.


[[File:OpenAI Actions.png|none|thumb|600x600px|OpenAI Actions]]
To configure the OpenAI provider instance:
The following Action settings are available for the OpenAI provider


'''Generate text:''' You can configure the following settings:   
# Go to ''Site administration > General > AI providers''.
# Click the settings link for OpenAI.
# Enable/disable actions as required.


* AI model: OpenAI API is powered by a diverse set of models with different capabilities and price points. There is more information about at [https://platform.openai.com/docs/models OpenAI Models]. By default, the model is set to “GPT-4o”,  but this can be configured to any other compatible model. For more details, [https://platform.openai.com/settings/organization/limits see your organization's settings and limits information].
For each action, you can customise the model's behaviour via the settings link.


*API endpoint. Please ensure your API endpoint is compatible with your selected model. For more information, visit [https://platform.openai.com/docs/models/model-endpoint-compatibility Model endpoint compatibility].
===Generate text, Summarise text and Explain text===
*System instruction: There are default system instructions in place to help direct the expected response format from the AI, but these can be customised to suit your specific needs. These are used to ensure a smooth user experience where only the requested text generation is returned, with no salutations, repetition of the request etc. It is therefore recommended these are not modified unless you are confident the change is absolutely necessary.


# Select the AI model. For information, see [https://platform.openai.com/docs/models OpenAI Models]. By default, the model is set to GPT-4o.
# Enter an API endpoint. Please ensure your API endpoint is compatible with your selected model. For information, see [https://platform.openai.com/docs/models/model-endpoint-compatibility Model endpoint compatibility].
# Review and amend the system instruction as necessary.
# Enter values for the following settings as required and save changes.


'''Summarise text:''' The required configuration is the same as for the Generate text Action.  
* 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:''' You can configure the following settings:
===Generate image===


*AI model: The default is set to “dall-e-3” but it can be changed to  any other image generation compatible model.  For more details, visit: [https://platform.openai.com/docs/models/dall-e DALL-E Models].
*Select the AI model. For information, see [https://platform.openai.com/docs/models/dall-e DALL-E Models]. The default is set to dall-e-3 but it can be changed to  any other image generation compatible model.
*API endpointPlease ensure your API endpoint is compatible with your selected model.
*Enter the API endpoint. Please ensure your API endpoint is compatible with your selected model.


To enable the OpenAI provider instance:


With all of the above enabled and configured, the OpenAI provider can be used for all of the AI placements available in your Moodle LMS instance; '''Course Assistance''' and '''HTML Text Editor''' placements. Don't forget to also enable and configure [[AI placements|'''AI Placements''']] settings. [[File:Generate text in OpenAI.png|none|thumb|600x600px|OpenAI Provider - Generate text settings]]
# Go to ''Site administration > General > AI providers''.
[[File:OpenAI Provider - Generate image.png|none|thumb|600x600px|OpenAI Provider - Generate image settings]]
# Click the toggle to enable the instance.


[[es:Proveedor OpenAI API]]
[[es:Proveedor OpenAI API]]
[[de:OpenAI API-Anbieter]]
[[de:OpenAI API-Anbieter]]

Latest revision as of 13:15, 24 June 2025

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.