17.7.4 Including Generative AI in Applications
Include Generative AI in your application by creating a Generative AI Service, configuring application attributes on the AI page, and creating a dynamic action to open the AI Assistant.
- About Including Generative AI in Applications
Learn about including Generative AI (such as an AI Assistant) in your applications. - Configuring AI Attributes for an Application
Edit attributes on the AI page to select a Generative AI Service and define Consent message for a application. - Creating a Dynamic Action to Open AI Assistant
Create a dynamic action to open AI Assistant. - Creating an AI Assistant to Suggest Salary
Create an AI Assistant to suggest salary recommendations.
Parent topic: Managing Generative AI in APEX
17.7.4.1 About Including Generative AI in Applications
Learn about including Generative AI (such as an AI Assistant) in your applications.
You can include AI in your applications by creating a dynamic action which opens the AI Assistant. The actual steps involved can be as simple as hooking a button to the dynamic action.
In general, the steps are as follows:
- Create a Generative AI Service. See Creating a Generative AI Service Object.
- Create an application. See Creating Applications.
- Edit the application definition and configure the attributes on the AI tab. See Configuring AI Attributes for an Application.
- Create a dynamic action with a True Action of Open AI Assistant. See Creating a Dynamic Action to Open AI Assistant.
About the Open AI Assistant True Action
Configuring a Open AI Assistant True Action, is the real power behind this feature. By editing the Action attributes in Page Designer, you can define all kinds of behavior. Consider the following examples:
- Generative AI, System Prompt - Specify a system prompt to give the AI context to request user input. Supports application and page items and system variables.
- Generative AI, Welcome Message - Specify a welcome message the AI Assistant will display. Supports substitutions: Application and page items and system variables.
- Appearance, Display As - Select if AI Assistant should display as a dialog or inline.
- Initial Prompt, Type - Specify the initial prompt (or message) that displays to the user to make it appear it's coming from an actual person. The message can be stored as an item or a value from a JavaScript expression.
- Use Response, Type - Select how the AI Assistant should return responses. The term response refers to the message content of an individual chat message. You have the option to capture this response directly in a page item value or to process it based on more complex logic using JavaScript Code.
- Quick Actions, Type - Enter a message to serve as a chat-wide quick action. A quick action is a pre-defined phrase that, once clicked, will be sent as a user message. Supports template directives, application and page items. and system variables.
Utilizing AI Infrastructure Programmatically
You also access the AI infrastructure programmatically using
the APEX_AI
package. Note that the
APEX_AI
APIs require an APEX session, must linked to an APEX app that has a Generative AI Service properly configured.
Consider the following SQL Developer example:
set serveroutput on;
declare
l_result clob;
begin
apex_session.create_session (
p_app_id => 102,
p_page_id => 1,
p_username => 'ADMIN' );
l_result := apex_ai.generate( 'what''s 1+1?' );
sys.dbms_output.put_line( l_result );
apex_session.delete_session;
exception
when others then
apex_session.delete_session;
raise;
end;
/
Parent topic: Including Generative AI in Applications
17.7.4.2 Configuring AI Attributes for an Application
Edit attributes on the AI page to select a Generative AI Service and define Consent message for a application.
Tip:
Before you can configure attributes on the AI page, you must define a Generative AI Service in Workspace Utilities. See Managing Generative AI Services.To configure AI attributes for an application:
Parent topic: Including Generative AI in Applications
17.7.4.3 Creating a Dynamic Action to Open AI Assistant
Create a dynamic action to open AI Assistant.
Note:
Before you can add a dynamic action to open AI Assistant, you must complete the steps described in About Including Generative AI in Applications. Failure to create a Generative AI Service or edit the application, AI attributes results in an error.The following simple example creates a dynamic action hooked to a button that displays the AI Assistant in a dialog. Note this example only describes the limited number of attributes. This example assumes you have already created an application and page.
To add a dynamic action to open AI Assistant:
Parent topic: Including Generative AI in Applications
17.7.4.4 Creating an AI Assistant to Suggest Salary
Create an AI Assistant to suggest salary recommendations.
The example in this topic describes how to create an AI Assistant that provides salary recommendations for employees. This example assumes you have completed the following tasks:
- Have access the
EMP
table available in EMP / DEPT sample dataset. To learn more, see Using Sample Datasets in Oracle APEX SQL Workshop Guide - Create an interactive report, named
Employees
, and form page, namedEdit Employee
, on theEMP
table. See Managing Interactive Reports.
To create an AI Assistant to suggest salary recommendations:
Parent topic: Including Generative AI in Applications