The Oracle APEX 24.2 release introduces an exciting new Dynamic Action called Generate Text with AI. This innovative feature helps developers add AI-driven text generation capabilities to applications, activated via Dynamic Actions. With its intuitive configuration process, this feature is a new way developers can easily harness the power of AI to enhance their applications, making them more accessible and efficient than ever before. Generate Text with AI helps lower the barriers to incorporating advanced AI-driven features, enabling faster development and richer user experiences.

Overview

Prior to the introduction of native Generative AI-powered features in APEX, developers had to establish a web service connection to get a response from a Generative AI service. With the introduction of APEX_AI API in the APEX 24.1 release, developers could call the apex_ai.generate function by passing the correct parameters in order to obtain a response. Now, with the NEW Generate Text with AI Dynamic Action in APEX 24.2 shown in Figure 1, developers can implement AI-driven text generation directly within their applications by configuring a set of attributes in the Property Editor. The functionality is flexible and can cater to various use cases depending on the specific needs of the application.

 

Figure 1. The Generate Text With AI D.A.
Figure 1. The Generate Text With AI D.A.

Let’s dive deeper into the details with examples.

Example 1: System Prompt-Only Configuration

In its simplest form, the Generate Text with AI action generates text dynamically based on a predefined input, using substitution strings, or a combination of both. The action then returns the generated text in a designated page item, such as P1_AI_RESPONSE, providing an easy and seamless way to present the AI-generated content within the application. This functionality allows the application to generate flexible and dynamic text tailored to the specific needs of the application and user interaction.

Steps:

  1. In an APEX page, create a Button.
  2. Create a Dynamic Action on the button.
  3. For Action, choose Generate Text with AI.
  4. For Input Value -> Type, choose Only System Prompt.
  5. For Generative AI -> System Prompt, write your prompt. Alternatively, you can use a Substitution String (Figure 3) to reference the actual prompt.
  6. For Use Response -> Item, select the page item where the action will write the generated text.
Figure 2. Generate Text With AI - Prompt only
Figure 2. Generate Text With AI – Prompt only
Figure 3. Generate Text With AI - Dynamic Prompt
Figure 3. Generate Text With AI – Dynamic Prompt

 

Click the Generate button to generate text. The result is displayed in the AI Reponse textarea below. Note that the generated text may vary based on your AI provider and the system prompt.

Figure 4. Output Generated by AI in a Page Item
Figure 4. Output Generated by AI in a Page Item

 

This approach helps in scenarios where the application autonomously drives the text generation process. For instance, it can power an application feature where a prompt-based response is required without any user interaction, like the automatic generation of summaries or pre-filled form content. Developers can integrate Retrieval-Augmented Generation (RAG) methods to enhance the context of these prompts. .

 

Example 2: System Prompt with Page/Application Items

For applications that require greater flexibility, the Generate Text with AI Dynamic Action incorporates user inputs or dynamically generated content through page or application items. By combining a System Prompt with the content of an item like P1_INPUT_ITEM, the action generates output, which is then displayed in another item such as P1_AI_RESPONSE. This setup helps enable highly dynamic interactions, where the AI-generated text adapts to user inputs or other content within the application, making it more personalized and context-aware.

Steps:

  1. In an APEX page, create a Button.
  2. Create a Dynamic Action on the button.
  3. For Action, choose Generate Text with AI.
  4. Under Input Value, choose the Page Item that will help feed the prompt.
  5. Write your prompt in the System Prompt attribute.
  6. For Use Response -> Item, select the page item where the AI will write the response.
Figure 5. Generate Text With AI - Prompt + Input
Figure 5. Generate Text With AI – Prompt + Input

By allowing the user input to be taken in consideration, it is possible to create some very interesting solutions.

Figure 6. An example of a text being formatted for an E-mail
Figure 6. An example of a text being formatted for an E-mail

This configuration works well for creating interactive applications. Potential use cases include building AI-driven assistants to answer user queries, provide detailed explanations on topics, or assist with repetitive tasks that require a creative touch. It enables developers to dynamically adapt the generated text based on runtime data or user input, resulting in more personalized and context-aware responses.

 

Example 3: Advanced Configuration Using JavaScript

In situations where the input or output elements are not tied to page items, developers can use JavaScript to manage these interactions. For example, when the input comes from a client-side variable or dynamically generated content in pure HTML, JavaScript allows developers to define both the input and output sources for the Generate Text with AI Dynamic Action. This approach provides greater flexibility, enabling the integration of AI functionality with content generated or manipulated on the client side, without being limited to page item bindings. It opens a wider range of possibilities for creating more complex and interactive applications.

The steps are the same as in the Example 2, the main difference being that you need to use JavaScript to reference the elements.

  • For an HTML textarea, write in the input value:
document.querySelector('#input-selector').textContent
  • For an HTML basic input tag, write in the output value:
document.querySelector('#output-selector').value = this.data.response;
Figure 7. Generate Text with AI using custom elements
Figure 7. Generate Text with AI using custom elements

By using JavaScript, you can retrieve and assign values to custom HTML elements. This allows for dynamic interaction with elements that may not be standard form controls or page items.

Figure 8. Generate Text with AI using custom elements
Figure 8. Generate Text with AI using custom elements

This approach is useful for applications that require highly customized interactions, or scenarios where input data is generated dynamically on the client side. Although more verbose, it provides unparalleled flexibility for complex implementations. Developers are encouraged to use JavaScript configurations only when simpler options such as page or application items are not feasible.

Key Takeaways

The Generate Text with AI Dynamic Action in Oracle APEX 24.2 helps enhance the developer’s toolkit by providing a code-free, configurable solution for AI-powered text generation. Whether through straightforward prompts, flexible page items, or advanced JavaScript configurations, this feature adapts to a wide range of application requirements. Developers can leverage the full potential of this Dynamic Action to streamline processes, enhance user experiences, and seamlessly integrate intelligent functionalities into their applications.