diff --git a/prc_26ai_query_run_insight.sql b/prc_26ai_query_run_insight.sql new file mode 100644 index 0000000..fc5b275 --- /dev/null +++ b/prc_26ai_query_run_insight.sql @@ -0,0 +1,63 @@ +create or replace procedure prc_26ai_query_run_insight(p_query_id in number, p_synthesizespeech in varchar2) +as + v_json_result CLOB; + v_narrate_result CLOB; + + -- Variáveis para processamento + v_aggregated_array CLOB; + + -- sintetizar voz ( ) + v_flag_synthesizespeech varchar2(1) := p_synthesizespeech; -- [Y | N] + +begin + for r1 in ( select id, 'SELECT json_arrayagg(c1) FROM ( SELECT JSON_OBJECT(v1.*) c1 FROM ( ' || sql_query || ' ) v1 WHERE ROWNUM <= 20 )' sql_query + from tb_26ai_query_insight + where query_id = p_query_id ) loop + + begin + + begin + EXECUTE IMMEDIATE(R1.sql_query) INTO v_json_result; + + --DBMS_OUTPUT.PUT_LINE(v_json_result); + + v_narrate_result := FNC_26AI_RAG('Descreva o resultado obtido da query que esta contida neste JSON: ' || v_json_result || + 'Não cite que se trata de um JSON, foque apenas na descrição do resultado.' || + 'Esta descrição não tem objetivo técnico, de detalhes do comando, mas sim dos resultados obtidos com foco em insigths.' + ,'OCI_CRED') ; + + if v_flag_synthesizespeech = 'Y' then + + -- proc_speech_synthesizespeech (p_text => v_narrate_result, + -- p_filename => 'audio_' || p_query_id || '_insight_' || r1.id || '.mp3' + -- ); + null; + + end if; + + -- + -- chamar api para gerar arquivo de audio num bucket (api: SynthesizeSpeech) + -- + + insert into tb_26ai_query_run_insight + values(p_query_id, + r1.id, + v_json_result, + v_narrate_result, + case + when v_flag_synthesizespeech = 'Y' then + 'audio_' || p_query_id || '_insight_' || r1.id || '.mp3' + else + null + end); + commit; + + exception + when others then + null; + end; + + end; + end loop; +end; +/ \ No newline at end of file diff --git a/prc_26ai_query_run_insight_pending.sql b/prc_26ai_query_run_insight_pending.sql new file mode 100644 index 0000000..310fd22 --- /dev/null +++ b/prc_26ai_query_run_insight_pending.sql @@ -0,0 +1,21 @@ +create or replace procedure prc_26ai_query_run_insight_pending(p_synthesizespeech in varchar2) +as + +begin + for r1 in ( select query_id + from TB_26AI_QUERY_HISTORY + where RUN_SQL_DATE is null + order by REGISTER_DATE + ) loop + + prc_26ai_query_run_insight( r1.query_id , p_synthesizespeech ); + + update TB_26AI_QUERY_HISTORY + set RUN_SQL_DATE = sysdate + where query_id = r1.query_id ; + + commit; + + end loop; +end; +/ \ No newline at end of file