OpenAI API provider: Difference between revisions

From MoodleDocs
No edit summary
info updated for 5.0
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{AI subsystem}}
{{AI subsystem}}
{{New features}}
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.


Moodle LMS’s integration with OpenAI provides access to AI Actions such as generate text, generate image or summarise course content. 
==Requirements==


More information about OpenAI can be found at https://platform.openai.com.
You need an OpenAI account with access to a paid API key.  
 
===Requirements:===
An OpenAI account with access to a paid API key. In Moodle LMS 4.5.0, both an OpenAI API key and OpenAI organization ID are required, however the organization ID will become optional from 4.5.1.


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.
#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]). (This is a required field for Moodle LMS 4.5.0, but will be optional from 4.5.1.)
#*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 ===
 
[[File:OpenAI Actions.png|none|thumb|600x600px|OpenAI Actions]]
The following Action settings are available for the OpenAI Provider. 


'''Generate text:''' You can configure the following settings:   
To create a provider instance:


* 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].
# 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'.


*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].
To configure the OpenAI provider instance:
*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.


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


'''Summarise text:''' The required configuration is the same as for the Generate text Action.  
For each action, you can customise the model's behaviour via the settings link.


'''Generate image:''' You can configure the following settings:
===Generate text, Summarise text and Explain text===


*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 OpenAI Models]. By default, the model is set to GPT-4o.
*API endpointPlease ensure your API endpoint is compatible with your selected model.
# 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.


* 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.


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]]
===Generate image===
[[File:OpenAI Provider - Generate image.png|none|thumb|600x600px|OpenAI Provider - Generate image settings]]


*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.
*Enter the API endpoint. Please ensure your API endpoint is compatible with your selected model.


To enable the OpenAI provider instance:


# Go to ''Site administration > General > AI providers''.
# 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.