/chat-with-context-caching.sql Secret
Created
August 2, 2024 09:27
Google GeminiのgenerateContentを呼び出す
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare | |
l_contents json_array_t := json_array_t(); | |
l_content json_object_t; | |
l_parts json_array_t; | |
l_part json_object_t; | |
l_model_response clob; | |
l_prompt_token_count number; | |
l_candidates_token_count number; | |
l_total_token_count number; | |
l_cached_content_token_count number; | |
begin | |
/* c001 = role, clob001 = text */ | |
apex_collection.add_member( | |
p_collection_name => 'CHAT' | |
,p_c001 => 'user' | |
,p_clob001 => :P1_MESSAGE | |
); | |
/* | |
* 送信するcontentsオブジェクトを作成する。 | |
*/ | |
for c in ( | |
select c001, clob001 from apex_collections where collection_name = 'CHAT' | |
order by seq_id asc | |
) | |
loop | |
l_content := json_object_t(); | |
l_parts := json_array_t(); | |
l_part := json_object_t(); | |
l_part.put('text', c.clob001); | |
l_parts.append(l_part); | |
l_content.put('parts', l_part); | |
l_content.put('role', c.c001); | |
l_contents.append(l_content); | |
end loop; | |
-- | |
utl_google_gemini_context_caching.generate_content( | |
p_contents => l_contents | |
,p_cached_content => :P1_CACHED_CONTENT | |
,p_credential_static_id => :G_CREDENTIAL | |
,p_model_response => l_model_response | |
,p_prompt_token_count => l_prompt_token_count | |
,p_candidates_token_count => l_candidates_token_count | |
,p_total_token_count => l_total_token_count | |
,p_cached_content_token_count => l_cached_content_token_count | |
); | |
apex_collection.add_member( | |
p_collection_name => 'CHAT' | |
,p_c001 => 'model' | |
,p_clob001 => l_model_response | |
,p_n001 => l_prompt_token_count | |
,p_n002 => l_candidates_token_count | |
,p_n003 => l_total_token_count | |
,p_n004 => l_cached_content_token_count | |
); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment