in src/zgoog_conversation_agent/zgoog_cl_conversation_agent.clas.abap [0:0]
METHOD send_message_content.
DATA:
ls_content_history TYPE /goog/cl_generative_model=>ty_content_history,
lt_content_history TYPE /goog/cl_generative_model=>tt_content_history,
ls_inline_data TYPE /goog/cl_generative_model=>ty_file_inline_data,
ls_file_uri TYPE /goog/cl_generative_model=>ty_file_uri,
lo_model_response TYPE REF TO /goog/cl_model_response,
ls_current_part TYPE /goog/cl_aiplatform_v1=>ty_740.
FIELD-SYMBOLS:
<ls_conversation_history> TYPE /goog/cl_aiplatform_v1=>ty_695,
<ls_part> TYPE /goog/cl_aiplatform_v1=>ty_740,
<ls_raw_file_data> TYPE /goog/cl_generative_model=>ty_file_inline_data,
<ls_gcs_file_uri> TYPE /goog/cl_generative_model=>ty_file_uri.
gt_conversation_history = get_conversation_history( ).
gs_current_conversation-role = 'user'.
IF gt_conversation_history IS NOT INITIAL.
LOOP AT gt_conversation_history ASSIGNING <ls_conversation_history>.
ls_content_history-role = <ls_conversation_history>-role.
IF <ls_conversation_history>-parts IS NOT INITIAL.
LOOP AT <ls_conversation_history>-parts ASSIGNING <ls_part>.
IF <ls_part>-text IS NOT INITIAL.
ls_content_history-text = <ls_part>-text.
ENDIF.
IF <ls_part>-inline_data IS NOT INITIAL.
ls_inline_data-mime_type = <ls_part>-inline_data-mime_type.
ls_inline_data-file_data = <ls_part>-inline_data-data.
IF <ls_part>-video_metadata IS NOT INITIAL.
ls_inline_data-video_start_offset = <ls_part>-video_metadata-start_offset.
ls_inline_data-video_end_offset = <ls_part>-video_metadata-end_offset.
ENDIF.
APPEND ls_inline_data TO ls_content_history-file_inline_data.
CLEAR ls_inline_data.
ENDIF.
IF <ls_part>-file_data IS NOT INITIAL.
ls_file_uri-mime_type = <ls_part>-file_data-mime_type.
ls_file_uri-file_uri = <ls_part>-file_data-file_uri.
IF <ls_part>-video_metadata IS NOT INITIAL.
ls_file_uri-video_start_offset = <ls_part>-video_metadata-start_offset.
ls_file_uri-video_end_offset = <ls_part>-video_metadata-end_offset.
ENDIF.
APPEND ls_file_uri TO ls_content_history-file_uris.
CLEAR ls_file_uri.
ENDIF.
IF <ls_part>-function_call IS NOT INITIAL.
ls_content_history-function_call = <ls_part>-function_call.
ENDIF.
IF <ls_part>-function_response IS NOT INITIAL.
ls_content_history-function_response = <ls_part>-function_response.
ENDIF.
APPEND ls_content_history TO lt_content_history.
CLEAR:
ls_content_history-text,
ls_content_history-file_inline_data,
ls_content_history-file_uris,
ls_content_history-function_call,
ls_content_history-function_response.
ENDLOOP.
ENDIF.
CLEAR ls_content_history.
ENDLOOP.
ENDIF.
IF lt_content_history IS NOT INITIAL.
go_generative_model->add_content_history( lt_content_history ).
ENDIF.
IF it_raw_file_data IS SUPPLIED.
LOOP AT it_raw_file_data ASSIGNING <ls_raw_file_data>.
go_generative_model->set_inline_data( iv_mime_type = <ls_raw_file_data>-mime_type
iv_data = <ls_raw_file_data>-file_data
iv_video_start_offset = <ls_raw_file_data>-video_start_offset
iv_video_end_offset = <ls_raw_file_data>-video_end_offset ).
ls_current_part-inline_data-mime_type = <ls_raw_file_data>-mime_type.
ls_current_part-inline_data-data = <ls_raw_file_data>-file_data.
ls_current_part-video_metadata-start_offset = <ls_raw_file_data>-video_start_offset.
ls_current_part-video_metadata-end_offset = <ls_raw_file_data>-video_end_offset.
APPEND ls_current_part TO gs_current_conversation-parts.
CLEAR ls_current_part.
ENDLOOP.
ENDIF.
IF it_gcs_file_uris IS SUPPLIED.
LOOP AT it_gcs_file_uris ASSIGNING <ls_gcs_file_uri>.
go_generative_model->set_file_data( iv_mime_type = <ls_gcs_file_uri>-mime_type
iv_file_uri = <ls_gcs_file_uri>-file_uri
iv_video_start_offset = <ls_gcs_file_uri>-video_start_offset
iv_video_end_offset = <ls_gcs_file_uri>-video_end_offset ).
ls_current_part-file_data-mime_type = <ls_gcs_file_uri>-mime_type.
ls_current_part-file_data-file_uri = <ls_gcs_file_uri>-file_uri.
ls_current_part-video_metadata-start_offset = <ls_gcs_file_uri>-video_start_offset.
ls_current_part-video_metadata-end_offset = <ls_gcs_file_uri>-video_end_offset.
APPEND ls_current_part TO gs_current_conversation-parts.
CLEAR ls_current_part.
ENDLOOP.
ENDIF.
lo_model_response = go_generative_model->generate_content( iv_prompt_text ).
gv_text_response = lo_model_response->get_text( ).
ls_current_part-text = iv_prompt_text.
APPEND ls_current_part TO gs_current_conversation-parts.
CLEAR ls_current_part.
gs_content_response = lo_model_response->get_response( ).
update_conversation_history( ).
ro_conversation_agent = me.