create or replace function get_gpt_response( p_question varchar2 ) return clob is v_api_key constant varchar2(100) := ''; v_response dbms_cloud_types.resp; begin v_response := dbms_cloud.send_request( uri => 'https://api.openai.com/v1/chat/completions', method => dbms_cloud.method_post, -- Headers must be of type JSON_OBJECT headers => json_object( 'Content-Type' value 'application/json', 'Authorization' value 'Bearer ' || v_api_key ), -- Request body must be a JSON structure converted to BLOB body => utl_raw.cast_to_raw( json_object( 'model' value 'gpt-3.5-turbo', 'messages' value json_array( json_object( 'role' value 'user', 'content' value p_question ) ), 'temperature' value 0.5 ) ) ); return dbms_cloud.get_response_text(v_response); end get_gpt_response; /