3.2 CHAT Function Signature 1

This function chats with a Generative AI service given a prompt and potential earlier responses.

Syntax

APEX_AI.CHAT (
    p_agent_static_id           IN              VARCHAR2,
    p_prompt                    IN              CLOB,
    p_messages                  IN OUT NOCOPY   t_chat_messages,
    p_request_handler_procedure IN              VARCHAR2        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_messages The responses from an earlier conversation. Responses are automatically added to p_messages for an easy conversational experience.
p_request_handler_procedure Optional PL/SQL procedure invoked to inspect or modify provider requests before they are sent.

Returns

The response for the given prompt.

Example

The following example chats with the assistant configured as my-oracle-assistant. In the first interaction, a system prompt is given. In later interactions, the context is passed to the generative AI service in the form of parameter p_messages.

DECLARE
  l_messages  apex_ai.t_chat_messages := apex_ai.c_chat_messages;
  l_response1 clob;
  l_response2 clob;
BEGIN
  l_response1 := apex_ai.chat(
    p_agent_static_id   => 'my-oracle-assistant',
    p_prompt            => 'What is Oracle APEX',
    p_messages          => l_messages );
  l_response2 := apex_ai.chat(
    p_agent_static_id   => 'my-oracle-assistant',
    p_prompt            => 'What is new in the latest release',
    p_messages          => l_messages );
END;