Today I will introduce how to use DeepSeek in SAP ECC system/S4 HANA System.
From the website:https://platform.deepseek.com/usage
We can get the open API with https://platform.deepseek.com/api_keys
So it is easy to call it is SAP.
You can find below video to check the right click button to exchange with DeepSeek.
https://www.youtube.com/watch?v=fw3hXIxitjk
https://mp.weixin.qq.com/s/0lqPcG8LZhfjj4VpKkB32Q
About DeepSeek:
DeepSeek is a Chinese AI company dedicated to advancing Artificial General Intelligence (AGI). Established in 2023 and headquartered in Hangzhou, it focuses on developing cutting-edge large language models (LLMs) and multimodal AI systems. The company aims to create transformative technologies that enhance productivity and innovation across industries while prioritizing ethical AI development.
Notable for its open-source contributions, DeepSeek has released models like DeepSeek-R1 and DeepSeek-Chat, demonstrating strong capabilities in reasoning, coding, and creative tasks. Its solutions span applications including intelligent assistants, content generation, education, and enterprise services. Collaborating with academic and industry partners, DeepSeek emphasizes both fundamental research and practical implementations. The company balances open innovation with commercial applications, striving to make advanced AI accessible while maintaining robust safety standards. DeepSeek represents China’s growing influence in AGI research, pushing boundaries in AI’s potential to solve complex real-world challenges.
Report zsap_call_ds_demo.
data:
LV_JSON_REQUEST type STRING .
data LV_CONT type STRING.
LV_CONT = ‘Please Help me to write a abap ALV report to get FI document’.
* 构建JSON请求体
LV_JSON_REQUEST = ‘{“model”:”deepseek-chat”,’
&& ‘”messages”:[‘
&& ‘ {“role”:”system”,”content”:”‘ && LV_CONT && ‘”},’
&& ‘ {“role”:”user”,”content”:”Hello!”}’
&& ‘],’
&& ‘”stream”:false}’.
data GV_OK type C length 6.
data LV_STR type STRING.
data LV_RET type STRING.
perform FRM_TEST using LV_JSON_REQUEST changing LV_RET.
form FRM_TEST using UV_JSON_REQUEST changing CV_RET.
data: LV_STATUS type I,
LV_ERROR_OCCURRED type FLAG,
LV_ERROR_MSG type STRING,
LV_RESPONSE_BODY type STRING.
clear CV_RET.
do 1 times.
perform SEND_JSON using
‘https://api.deepseek.com/chat/completions’ ”
UV_JSON_REQUEST ” JSON报文
changing LV_STATUS
LV_RESPONSE_BODY
LV_ERROR_OCCURRED
LV_ERROR_MSG.
enddo.
* Show result
format color col_heading.
write: / ‘Response status:’, LV_STATUS.
write: / ‘调用成功次数:’, GV_OK.
if LV_ERROR_OCCURRED = ‘X’.
format color col_negative.
write: / ‘Error occurred:’, LV_ERROR_MSG.
endif.
format color col_normal.
write: / ‘Response:’, LV_RESPONSE_BODY.
if LV_RESPONSE_BODY cs `”content”:”`.
perform FRM_CUT using LV_RESPONSE_BODY
`”content”:”`
`”},”logprobs”:`
changing CV_RET.
endif.
endform. “start
form SEND_JSON using IV_URL type STRING
IV_JSON_DATA type STRING
changing CV_STATUS type I
CV_RESPONSE_BODY type STRING
CV_ERROR_OCCURRED type FLAG
CV_ERROR_MSG type STRING.
statics: LO_CLIENT type ref to IF_HTTP_CLIENT.
clear: CV_ERROR_MSG,
CV_STATUS,
CV_ERROR_OCCURRED,
CV_ERROR_MSG.
if IV_URL is initial.
message E349(SBDS) into CV_ERROR_MSG.
CV_ERROR_OCCURRED = ‘X’.
return.
endif.
statics SV_BEGIN type C length 1.
if SV_BEGIN is initial.
call method CL_HTTP_CLIENT=>CREATE_BY_URL
exporting
URL = IV_URL
importing
CLIENT = LO_CLIENT
exceptions
ARGUMENT_NOT_FOUND = 1
PLUGIN_NOT_ACTIVE = 2
INTERNAL_ERROR = 3
others = 4.
if SY-SUBRC ne 0.
message id SY-MSGID type SY-MSGTY number SY-MSGNO
with SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4
into CV_ERROR_MSG.
CV_ERROR_OCCURRED = ‘X’.
return.
endif.
SV_BEGIN = ‘X’.
LO_CLIENT->REQUEST->SET_CONTENT_TYPE( ‘application/json’ ).
LO_CLIENT->REQUEST->SET_METHOD( ‘POST’ ).
* 自定义参数
LO_CLIENT->REQUEST->SET_HEADER_FIELD( NAME = ‘InterfaceName’ VALUE = ‘WWW.HOT583.COM’ ). “//保留。
LO_CLIENT->REQUEST->SET_HEADER_FIELD( NAME = ‘Authorization’ VALUE = ‘Bearer sk-f2asdadfa98932824735981a’ ). “换算成自己的密钥吧。
endif.
LO_CLIENT->REQUEST->SET_CDATA( IV_JSON_DATA ).
call method LO_CLIENT->SEND
exceptions
HTTP_COMMUNICATION_FAILURE = 1
HTTP_INVALID_STATE = 2
HTTP_PROCESSING_FAILED = 3
others = 4.
if SY-SUBRC ne 0.
LO_CLIENT->GET_LAST_ERROR( importing MESSAGE = CV_ERROR_MSG ).
CV_ERROR_OCCURRED = ‘X’.
return.
endif.
LO_CLIENT->RECEIVE( exceptions others = 1 ).
if SY-SUBRC ne 0.
LO_CLIENT->GET_LAST_ERROR( importing MESSAGE = CV_ERROR_MSG ).
CV_ERROR_OCCURRED = ‘X’.
return.
endif.
CV_RESPONSE_BODY = LO_CLIENT->RESPONSE->GET_CDATA( ).
LO_CLIENT->RESPONSE->GET_STATUS( importing CODE = CV_STATUS ).
* CALL METHOD LO_CLIENT->CLOSE( ).”如果多开需要关闭。
GV_OK = GV_OK + 1.
endform.
*&———————————————————————*
*& Form FRM_CUT
*&———————————————————————*
*& 截取AB中间的保留到C。
*&———————————————————————*
form FRM_CUT using UV_INPUT
P_A
P_B
changing CV_RET.
data LV_TMP type STRING.
split UV_INPUT at P_A into LV_TMP CV_RET.
clear LV_TMP.
split CV_RET at P_B into CV_RET LV_TMP.
endform.
If you have problem, please fell free to contact.Thanks.
This post is come from www.hot583.com, you can share/use it with the post original link for free.
But pay attention of any risk yourself.
http://www.hot583.com/category/sap_tech/sap_bapi/
微信原文《The End》