3.3 CHAT Function
This function chats with a Generative AI service given a prompt and potential earlier responses.
Syntax
APEX_AI.CHAT (
p_prompt IN VARCHAR2,
p_system_prompt IN VARCHAR2 DEFAULT NULL,
p_service_static_id IN VARCHAR2 DEFAULT NULL,
p_temperature IN NUMBER DEFAULT NULL,
p_messages IN OUT NOCOPY t_chat_messages )
RETURN CLOB;
Parameters
Parameter | Description |
---|---|
p_prompt |
The user prompt. |
p_system_prompt |
(Optional) System prompt to pass. Some Generative AI services (such as OpenAI) support the use of passing a system prompt to set the context of a conversation. |
p_service_static_id |
The Generative AI Service static ID. If not provided, uses the app's default AI Service. |
p_temperature |
The temperature to use. How the temperature is interpreted depends on the Generative AI Service implementation. Higher temperatures result in more "creative" responses. See the documentation of the Generative AI provider for details and allowed values. |
p_messages |
(Optional) The responses from an earlier conversation. Responses of procedure chat and nl2sql are automatically added to p_responses .
|
Returns
The response for the given prompt and type.
Example
The following example chats with the configured Generative AI Service MY_AI_SERVICE
. In the first interaction, a system prompt is given and then in further 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;
l_response1 clob;
l_response2 clob;
BEGIN
l_response1 := apex_ai.chat(
p_prompt => 'What is Oracle APEX',
p_system_prompt => 'I am an expert in Low Code Application Platforms',
p_service_static_id => 'MY_AI_SERVICE',
p_messages => l_messages);
l_response2 := apex_ai.chat(
p_prompt => 'What is new in 23.2',
p_service_static_id => 'MY_AI_SERVICE',
p_messages => l_messages);
END;
Parent topic: APEX_AI