Call CREATE_CREDENTIAL
to create and store a credential.
Cohere, Google AI, Hugging Face, OpenAI, and Vertex AI require the following authentication parameter:
{ "access_token": "<access token>" }
You will later refer to this credential name when declaring JSON parameters for the UTL_TO_GENERATE_TEXT
call.
exec dbms_vector_chain.drop_credential('<credential name>');
declare
jo json_object_t;
begin
jo := json_object_t();
jo.put('access_token', '<access token>');
dbms_vector_chain.create_credential(
credential_name => '<credential name>',
params => json(jo.to_string));
end;
/
Replace the access_token
and credential_name
values. For example:
declare
jo json_object_t;
begin
jo := json_object_t();
jo.put('access_token', 'AbabA1B123aBc123AbabAb123a1a2ab');
dbms_vector_chain.create_credential(
credential_name => 'HF_CRED',
params => json(jo.to_string));
end;
/
Call UTL_TO_GENERATE_TEXT
:
-- select example
var params clob;
exec :params := '
{
"provider": "<REST provider>",
"credential_name": "<credential name>",
"url": "<REST endpoint URL for text generation service>",
"model": "<REST provider text generation model name>"
}';
select dbms_vector_chain.utl_to_generate_text(
'What is Oracle Text?',json(:params)) from dual;
-- PL/SQL example
declare
input clob;
params clob;
output clob;
begin
input := 'What is Oracle Text?';
params := '
{
"provider": "<REST provider>",
"credential_name": "<credential name>",
"url": "<REST endpoint URL for text generation service>",
"model": "<REST provider text generation model name>"
}';
output := dbms_vector_chain.utl_to_generate_text(input, json(params));
dbms_output.put_line(output);
if output is not null then
dbms_lob.freetemporary(output);
end if;
exception
when OTHERS THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);
DBMS_OUTPUT.PUT_LINE (SQLCODE);
end;
/
Replace the provider
, credential_name
, url
, and model
values. Optionally, you can specify additional REST provider parameters.
Cohere example:
{
"provider": "Cohere",
"credential_name": "COHERE_CRED",
"url": "https://api.cohere.example.com/generateText",
"model": "generate-text-model"
}
Google AI example:
{
"provider": "googleai",
"credential_name": "GOOGLEAI_CRED",
"url": "https://googleapis.example.com/models/",
"model": "generate-text-model"
}
Hugging Face example:
{
"provider": "huggingface",
"credential_name": "HF_CRED",
"url": "https://api.huggingface.example.com/models/",
"model": "generate-text-model"
}
OpenAI example:
{
"provider": "openai",
"credential_name": "OPENAI_CRED",
"url": "https://api.openai.example.com",
"model": "generate-text-model",
"max_tokens": 60,
"temperature": 1.0
}
Vertex AI example:
{
"provider": "vertexai",
"credential_name":"VERTEXAI_CRED",
"url": "https://googleapis.example.com/models/",
"model": "generate-text-model",
"generation_config": {
"temperature": 0.9,
"topP": 1,
"candidateCount": 1,
"maxOutputTokens": 256
}
}