data: field(40) type c value '(SAPLLOCAL_EDT1)CONTENT[]',
field_ind(40) type c value '(SAPLLOCAL_EDT1)CURSOR-NEW_INDEX'.
assign (field) to <fs_content>.
assign (field_ind) to <fs_ind>.
DATA: lc_content(40) TYPE c VALUE '(SAPLLOCAL_EDT1)CONTENT[]',
lc_index(40) TYPE c VALUE '(SAPLLOCAL_EDT1)CURSOR-NEW_INDEX'.
data:
sdk_instance type ref to zif_peng_azoai_sdk, "MS AI SDK for SAP Instance
status_code type i, "Return Status Code
status_reason type string, "Return Status Reason
returnjson type string, "Return JSON. The content of this JSON string is parsed and made available through ABAP data types.
error type zif_peng_azoai_sdk_types=>ty_error. "ABAP Type for Error
data:
chatcompl_input type zif_peng_azoai_sdk_types=>ty_chatcompletion_input,
chatcompl_output type zif_peng_azoai_sdk_types=>ty_chatcompletion_output.
data:
lv_api_url type string,
lv_api_ver type string,
lv_api_key type string,
lv_depid type string.
DATA: lv_buffer TYPE string,
lv_code TYPE string.
IF keyword = 'ZGPT'.
ASSIGN (lc_content) TO <fs_content>.
ASSIGN (lc_index) TO <fs_ind>.
IF <fs_content> IS ASSIGNED.
IF <fs_ind> IS ASSIGNED AND <fs_ind> > 1.
READ TABLE <fs_content> INDEX <fs_ind> INTO lv_code.
IF lv_code IS INITIAL.
<fs_ind> = <fs_ind> - 1.
READ TABLE <fs_content> INDEX <fs_ind> INTO lv_code.
ENDIF.
ELSE.
READ TABLE <fs_content> INDEX 1 INTO lv_code.
ENDIF.
ENDIF.
lv_api_ver = api_ver.
lv_api_url = api_url.
lv_api_key = api_key.
lv_depid = depid.
sdk_instance = zcl_peng_azoai_sdk_factory=>get_instance( )->get_sdk(
api_version = lv_api_ver
api_base = lv_api_url
api_type = zif_peng_azoai_sdk_constants=>c_apitype-azure
api_key = lv_api_key
).
* Construct the prompt with system and user roles.
append initial line to chatcompl_input-messages assigning field-symbol(<fs_message>).
<fs_message>-role = zif_peng_azoai_sdk_constants=>c_chatcompletion_role-system.
<fs_message>-content = search_role ."|You are an expert ABAP Developer|.
* Pass comments as prompt
append initial line to chatcompl_input-messages assigning <fs_message>.
<fs_message>-role = zif_peng_azoai_sdk_constants=>c_chatcompletion_role-user.
<fs_message>-content = lv_code.
* Invoke Chat completion.
sdk_instance->chat_completions( )->create(
exporting
deploymentid = lv_depid
prompts = chatcompl_input
importing
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
json = returnjson " JSON String returned from AI Resource
response = chatcompl_output
error = error " ABAP Ready error details
).
* Response from open AI.
if chatcompl_output-choices is not initial.
LOOP AT completions_output-choices ASSIGNING FIELD-SYMBOL(<fs_outputtext>).
str_output = |{ str_output }{ <fs_outputtext>-text }|.
ENDLOOP.
endif.
w_buffer =
'*** Begin of AI Generated CODE***'.
append w_buffer to buffer.
w_buffer =
'*----------------------------------------------------------------------*'.
append w_buffer to buffer.
if lv_response is not initial.
split lv_response at cl_abap_char_utilities=>newline into table lt_tab. "cl_abap_char_utilities=>cr_lf
loop at lt_tab into data(w_tab).
w_buffer = w_tab.
append w_buffer to buffer.
endloop.
w_buffer =
'*----------------------------------------------------------------------*'.
append w_buffer to buffer.
w_buffer =
'*** End of AI Generated CODE***'.
append w_buffer to buffer.
ENDIF.
ENDIF.
CATCH zcx_peng_azoai_sdk_exception INTO DATA(_ex).
MESSAGE _ex TYPE 'I'.
ENDTRY.
constants: c_keyword type tse05-keyword value 'ZGPT'.
data: c_fieldname(40) type c value '(SAPLLOCAL_EDT1)TDPARAM'.
field-symbols: <fs_key> type rstxp-tdparam.
assign (c_fieldname) to <fs_key>.
<fs_key> = c_keyword."'ZGPT'.
perform insert_command in program sapllocal_edt1.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
4 | |
4 | |
2 | |
2 | |
2 | |
2 | |
2 | |
1 | |
1 | |
1 |