OpenAI API provider: Difference between revisions

From MoodleDocs
Update OpenAI documentation
info updated for 5.0
 
(19 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 on the following link <nowiki>https://platform.openai.com</nowiki>
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.
An 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).


==== Configuring OpenAI API provider settings ====
==OpenAI provider instance set-up==


# Go to Admin -> General -> AI -> AI providers
To create a provider instance:
# 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 (OpenAI API keys).
#* OpenAI organization ID: You can get it from  your OpenAI account / Organization settings page (OpenAI account).
#* Set site-wide rate limit: 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
#* Maximum number of requests per user can be configured after enable “Set user rate limit”
# In the “Actions” area enable all actions by clicking on their “Enabled” toggle.


[[File:OpenAI.jpg|none|thumb|600x600px|OpenAI]]
# 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'.


==== Configuring OpenAI API provider actions ====
To configure the OpenAI provider instance:
[[File:OpenAI Actions.png|none|thumb|600x600px|OpenAI Actions]]
Access to the Settings link on each action to configure them.


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


'''Generate text''': You can configure the following settings:
For each action, you can customise the model's behaviour via the settings link.


* 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 in the following link <nowiki>https://platform.openai.com/docs/models</nowiki>  As default is set to “GPT-4o” but it can be change for any other compatible model, see your settings organization limits for more information (<nowiki>https://platform.openai.com/settings/organization/limits</nowiki>)
===Generate text, Summarise text and Explain text===


* API endpoint. Please ensure your API endpoint is compatible with your Model, see more information in the following link <nowiki>https://platform.openai.com/docs/models/model-endpoint-compatibility</nowiki>
# 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.


* System instruction: There are some system instructions as default, but this can be adapted to your needs.  
* 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.


'''Summarise text:''' The required configuration is the same as for the Generate text action.
===Generate image===


'''Generate image''': You can configure the following 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.
* AI model: As default is set to “dall-e-3” but it can be changed for any other image generation compatible model. See more information in the following link <nowiki>https://platform.openai.com/docs/models/dall-e</nowiki>
* API endpointPlease ensure your API endpoint is compatible with your Model.
 
[[File:Generate text in OpenAI.png|none|thumb|600x600px|Generate text in OpenAI]]
 
 
Now we should be able to use OpenAI provider for the AI placements available in our Moodle instance: Course Assistance and HTML Text Editor Placements. Don't forget to enable and configure [[AI placements|AI Placements]] settings.  


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]]

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.