OpenAI API provider: Difference between revisions

From MoodleDocs
info updated for 5.0
 
(12 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{AI subsystem}}
{{AI subsystem}}
{{Work in progress}}
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.
{{New features}}


Moodle integration with OpenAI provides a service that lets people use advanced AI tools like generate a text, generate an image or summarize a text. 
==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: ===
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.
A paid OpenAI account with access to the API key (Usage limits and pricing tiers are dependent on the level of access and the volume of queries). 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, site administrators can generate keys with both free and paid accounts, however API usage is restricted based on the account type and payment method. '''Access to the API used by the Moodle LMS integration requires a subscription to one of OpenAI’s paid plans''', such as the Pay-as-you-go or Pro/Enterprise plan, which provide different levels of access depending on the selected pricing tier.
==OpenAI provider instance set-up==


=== Configuring OpenAI API provider settings ===
To create a provider instance:
# 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 ===
# Go to ''Site administration > General > AI providers''.
[[File:OpenAI Actions.png|none|thumb|600x600px|OpenAI Actions]]
# 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]).
The following Action settings are available for the OpenAI Provider.
# 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'.


'''Generate text:''' You can configure the following settings:
To configure the OpenAI 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 OpenAI models at the following link [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, see [https://platform.openai.com/settings/organization/limits your organization's settings and limits information].
# Go to ''Site administration > General > AI providers''.
# Click the settings link for OpenAI.
# Enable/disable actions as required.


* API endpoint. Please ensure your API endpoint is compatible with your selected model. For more information, visit this link  <nowiki>https://platform.openai.com/docs/models/model-endpoint-compatibility</nowiki>
For each action, you can customise the model's behaviour via the settings link.


* System instruction: There are default system instructions in place, but these can be customised to suit your specific needs.
===Generate text, Summarise text and Explain text===


'''Summarise text:''' The required configuration is the same as for the Generate text Action.  
# 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.


'''Generate image'''
* 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.


* 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].
===Generate image===
* API endpoint:  Please ensure your API endpoint is compatible with your selected model.


[[File:Generate text in OpenAI.png|none|thumb|600x600px|Generate text in OpenAI]]
*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''.
With the above enabled and configured, the OpenAI Provider can be used for 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.
# Click the toggle to enable the instance.


[[es:Proveedor OpenAI API]]
[[es:Proveedor OpenAI API]]
[[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.