18.8.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 displays 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:

  1. Create a Generative AI Service. See Creating a Generative AI Service Object.
  2. Create an application. See Creating Applications.
  3. Edit the application definition and configure the attributes on the AI tab. See Configuring AI Attributes for an Application.
  4. Create a dynamic action with a True Action:
    • Show AI Assistant - Displays the AI Assistant, an AI-powered chat service, displayed either as a dialog or inline. .
    • Generate Text With AI - Invokes the configured Generative AI Service to generate a one-time response based on user content. This action is ideal for tasks like summarizing or translating text, extracting keywords, or drafting an email.

About Show AI Assistant True Action Behaviors

The Show AI Assistant True Action displays an AI-powered chat service as a dialog or inline. You can edit the Action attributes in Page Designer to define all kinds of behavior. Consider the following examples:

  • Generative AI, System Prompt - Specify a system prompt to give the AI context and provide instruction on how to process the 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.

See Also:

To view an example, see Creating a Dynamic Action to Display AI Assistant.

About Generate Text with AI True Action Behaviors

The Generate Text With AI True Action calls the configured Generative AI Service and generates a one-time response based on user content. This True Action is ideal for tasks like summarizing or translating text, extracting keywords, or drafting an email. You can edit the Action attributes in Page Designer to define all kinds of behavior. Consider the following examples:

  • Generative AI, System Prompt - Specify a system prompt to give the AI context and provide instruction on how to process the input. Supports application and page items and system variables.
  • Input Value, Type - Select the type of user input to be delivered to the AI service. The term input refers to the request text to be sent to the AI service. You have the option to capture to provide this input directly in a page item value or returning it with more complex logic using a JavaScript expression.
  • Use Response, Type - Select how the AI service should return the response. 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. If an item is used, you can control if the response should trigger the change event.

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;
/

See Also:

APEX_AI in Oracle APEX API Reference