Previous Next JavaScript must be enabled to correctly display this content

## 18.9.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 Generative AI Service, configuring AI Attributes for the application, and using AI-enhanced components such as dynamic actions, page processes, or workflow activities.

In general, the steps are as follows:

1. Create a Generative AI Service. See Creating Generative AI Service Objects.
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 an AI-enhanced component:
   - Show AI Assistant - Use a Dynamic Action True Action to display the AI Assistant, an AI-powered chat service, either as a dialog or inline.
   - Generate Text With AI - Use a Dynamic Action True Action, a Page Process, or a Workflow Activity to invoke the configured Generative AI Service and 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.

Tip:

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

About Generate Text with AI Behaviors

You can generate text with AI by using a Dynamic Action True Action, a Page Process, or a Workflow Activity.

Generate Text With AI calls the configured Generative AI Service and generates a one-time response based on user content. This 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 (Dynamic Action only) - 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.

Tip:

For an example of a Dynamic Action True Action, see Creating a Dynamic Action to Generate Text with AI.

For an example of a Page Process, see Creating a Page Process to Generate Text with AI.

For an example of a Workflow Activity, see Adding a Workflow Generate Text with AI Activity.

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

Related Topics

- APEX_AI in Oracle APEX API Reference

Parent topic: Including Generative AI in Applications