3.5 GENERATE Function Signature 1

This function generates a response for a given prompt based on an AI Agent.

If the Agent has Response Format set to "JSON Object", this function returns a stringified JSON object. Starting with Oracle AI Database 26ai, the incoming JSON object is automatically validated against the agent's JSON Schema. For earlier database versions, Oracle recommends validating the JSON object programmatically before further processing.

Syntax

FUNCTION apex_ai.generate (
    p_agent_static_id              IN               VARCHAR2,
    p_prompt                       IN               CLOB,
    p_request_handler_procedure    IN               VARCHAR2        DEFAULT NULL,
    p_attachments                  IN               t_attachments   DEFAULT NULL )
    RETURN CLOB;

Parameters

Parameter Description
p_agent_static_id The static ID of the AI Agent defined under the application's Shared Components.
p_prompt The user prompt.
p_request_handler_procedure Advanced. Optional PL/SQL procedure invoked to inspect or modify provider requests before they are sent.
p_attachments An optional collection of file attachments. Whether a specific file type is supported depends on the AI provider and model.

Returns

The response for the given prompt.

Example

The following example generates a response using the AI service configured via AI Agent with static ID low_code_expert.

DECLARE
    l_response clob;
BEGIN
    l_response :=
        apex_ai.generate (
            p_prompt            =>'What is Oracle APEX',
            p_agent_static_id   =>'low_code_expert' );
END;