CREATE_CREDENTIAL
をコールして、資格証明を作成および格納します。
Google AI、Hugging Face、OpenAIおよびVertex AIには、次の認証パラメータが必要です:
{ "access_token": "<access token>" }
後で、UTL_TO_GENERATE_TEXT
コールのJSONパラメータを宣言するときに、この資格証明名を参照します。
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;
/
access_token
およびcredential_name
を独自の値に置き換えます。次に例を示します。
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;
/
UTL_TO_GENERATE_TEXT
をコールします。
-- select example
var input clob;
var media_data blob;
var media_type clob;
var params clob;
begin
:input := 'Describe this image';
:media_data := load_blob_from_file('DEMO_DIR', 'bird.jpg');
:media_type := 'image/jpeg';
:params := '
{
"provider" : "<REST provider>",
"credential_name": "<credential name>",
"url" : "<REST endpoint URL for text generation service>",
"model" : "<REST provider text generation model name>",
"max_tokens" : <maximum number of tokens in the output text>
}';
end;
/
select dbms_vector_chain.utl_to_generate_text(:input, :media_data, :media_type, json(:params));
-- PL/SQL example
declare
input clob;
media_data blob;
media_type varchar2(32);
params clob;
output clob;
begin
input := 'Describe this image';
media_data := load_blob_from_file('DEMO_DIR', 'bird.jpg');
media_type := 'image/jpeg';
params := '
{
"provider" : "<REST provider>",
"credential_name": "<credential name>",
"url" : "<REST endpoint URL for text generation service>",
"model" : "<REST provider text generation model name>",
"max_tokens" : <maximum number of tokens in the output text>
}';
output := dbms_vector_chain.utl_to_generate_text(
input, media_data, media_type, json(params));
dbms_output.put_line(output);
if output is not null then
dbms_lob.freetemporary(output);
end if;
if media_data is not null then
dbms_lob.freetemporary(media_data);
end if;
exception
when OTHERS THEN
DBMS_OUTPUT.PUT_LINE (SQLERRM);
DBMS_OUTPUT.PUT_LINE (SQLCODE);
end;
/
provider
、credential_name
、url
およびmodel
を独自の値に置き換えます。オプションで、追加のRESTプロバイダ・パラメータを指定できます。これを次の例に示します:
Google AIの例:
{
"provider" : "googleai",
"credential_name": "GOOGLEAI_CRED",
"url" : "https://generativelanguage.googleapis.com/v1beta/models/",
"model" : "gemini-pro:generateContent"
}
Hugging Faceの例:
{
"provider" : "huggingface",
"credential_name": "HF_CRED",
"url" : "https://api-inference.huggingface.co/models/",
"model" : "gpt2"
}
ノート:
Hugging Faceでは、プロンプトを必要としないイメージ・キャプション・モデルが使用されます。イメージとともにプロンプトを入力した場合、プロンプトは無視されます。
OpenAIの例:
{
"provider" : "openai",
"credential_name": "OPENAI_CRED",
"url" : "https://api.openai.com/v1/chat/completions",
"model" : "gpt-4o-mini",
"max_tokens" : 60
}
Vertex AIの例:
{
"provider" : "vertexai",
"credential_name" : "VERTEXAI_CRED",
"url" : "https://LOCATION-aiplatform.googleapis.com/v1/projects/PROJECT/locations/LOCATION/publishers/google/models/",
"model" : "gemini-1.0-pro:generateContent",
"generation_config": {
"temperature" : 0.9,
"topP" : 1,
"candidateCount" : 1,
"maxOutputTokens": 256
}
}