This article demonstrates the remarkable ease of calling a Vertex AI Foundation Model directly from ABAP. Imagine: unlocking the power of cutting-edge AI without leaving the familiar SAP environment. This groundbreaking approach eliminates barriers and opens doors to a world of possibilities.
In this article, I am going to use the text-bison model to execute a simple summarization requirement and also show how to call the same using ABAP SDK for Google Cloud.
The Text Bison Foundation Model is a large language model offered in Google Cloud’s Vertex AI platform. It’s part of the PaLM 2 family of models, specifically optimized for a variety of natural language tasks, including:
Note: The goal of the article is to discover how seamless AI integration becomes with Vertex AI and ABAP. It does not dwell into any particular SAP use case.
In am in Generative AI Studio, where I have provided the following prompt as an input to the text-bison model.
What should be the right hashtags for this post:
Post: Today, we are releasing the the next version (v1.5) of ABAP SDK for Google Cloud. This version now supports 40+ more APIs including VertexAI, Google Maps platform, Google Workspace and more. We are also releasing a public GitHub repo with quick starts and sample applications. Happy coding!
Hashtags:
I am expecting it to provide the relevant hashtags. Here is how it looks:
The model returns the following response:
#ABAP #GoogleCloud #VertexAI #GoogleMapsPlatform #GoogleWorkspace #CloudComputing #SoftwareDevelopment #DeveloperTools #OpenSource #GitHub #Coding #Programming
Google provides the API’s and the Python SDK to help build your own applications. You can explore the Vertex AP API by going into this link.
We will be using the below API method.
You can read more about the the Vertex AI SDK for Python in this link.
You can simply click View Code in the studio, which will present you a fully functional python code.
⚡️ The cool thing is now you can harness this power even from ABAP using the ABAP SDK for Google Cloud. ⚡️
Below is a comparison with a similar code written in ABAP to access the same set of available foundation models.
Below are some quick steps to get this running in your ABAP system.
Note: The configuration assume that the SAP system is hosted on Google Cloud Platform and you have performed the prerequisite steps. Please refer to this link for other authentication options.
Step1: Configure a Client Key required for connectivity.
Google Cloud Key Name: DEMO_AIPLATFORM
Google Cloud Service Account Name: abap-sdk-dev@gcp-project.iam.gserviceaccount.com
Google Cloud Scope: https://www.googleapis.com/auth/cloud-platform
Google Cloud Project Identifier: gcp-project
Authorization Class: /GOOG/CL_AUTH_GOOGLE
Leave the other fields blank
Step2: Crete a RFC Destination
Step3: Configure Service Mapping
Google Cloud Key Name: DEMO_AIPLATFORM
Google Service Name: aiplatform:v1
RFC Destination: ZGOOG_VERTEXAI_V1
Step4: Create a Program to call Vertex AI model
SE38
and paste the following code. (Please replace the project id in the below code as per your environment).DATA lo_client TYPE REF TO /goog/cl_aiplatform_v1.
DATA lv_p_projects_id TYPE string.
DATA lv_p_locations_id TYPE string.
DATA lv_p_publishers_id TYPE string.
DATA lv_p_models_id TYPE string.
DATA ls_input TYPE /goog/cl_aiplatform_v1=>ty_001.
DATA ls_raw TYPE REF TO data.
DATA ls_output TYPE /goog/cl_aiplatform_v1=>ty_002.
DATA lv_ret_code TYPE i.
DATA lv_err_text TYPE string.
DATA ls_err_resp TYPE /goog/err_resp.
DATA lv_msg TYPE string.
DATA lo_exception TYPE REF TO /goog/cx_sdk.
TYPES:
BEGIN OF t_parameters,
max_output_tokens TYPE i,
temperature TYPE f,
top_k TYPE i,
top_p TYPE f,
END OF t_parameters.
TYPES:
BEGIN OF t_instances,
content TYPE string,
END OF t_instances.
TYPES tt_instances TYPE STANDARD TABLE OF t_instances WITH DEFAULT KEY.
TYPES:
BEGIN OF t_predictions,
citation_metadata TYPE REF TO data,
content TYPE string,
safety_attributes TYPE REF TO data,
END OF t_predictions.
TYPES tt_predictions TYPE STANDARD TABLE OF t_predictions WITH DEFAULT KEY.
DATA lt_predictions TYPE tt_predictions.
TRY.
" Open HTTP Connection
lo_client = NEW #( iv_key_name = 'DEMO_AIPLATFORM' ).
" Populate relevant parameters
lv_p_projects_id = 'gcp-project'.
lv_p_locations_id = 'us-central1'.
lv_p_publishers_id = 'google'.
lv_p_models_id = 'text-bison'.
" Set the Instance and Parameter
ls_input = VALUE #(
parameters = NEW t_parameters( max_output_tokens = 1024
temperature = '0.2'
top_p = '0.8'
top_k = 40 )
instances = NEW tt_instances(
( content = |What should be the right hashtags for this post:| &&
|Post: Today, we are releasing the the next version (v1.5) of ABAP SDK for Google Cloud. | &&
|This version now supports 40+ more APIs including VertexAI, Google Maps platform, | &&
|Google Workspace and more. We are also releasing a public GitHub repo with quick starts | &&
|and sample applications. Happy coding!| &&
|Hashtags: | ) ) ).
" Call API method: aiplatform.projects.locations.publishers.models.predict
lo_client->predict_models( EXPORTING iv_p_projects_id = lv_p_projects_id
iv_p_locations_id = lv_p_locations_id
iv_p_publishers_id = lv_p_publishers_id
iv_p_models_id = lv_p_models_id
is_input = ls_input
IMPORTING
es_output = ls_output
ev_ret_code = lv_ret_code
ev_err_text = lv_err_text
es_err_resp = ls_err_resp ).
IF lo_client->is_success( lv_ret_code ) = abap_true.
ASSIGN ls_output-predictions->* TO FIELD-SYMBOL(<lt_predictions>).
LOOP AT <lt_predictions> ASSIGNING FIELD-SYMBOL(<ls_predictions>).
ASSIGN <ls_predictions>->('CONTENT') TO FIELD-SYMBOL(<lv_content>).
cl_demo_output=>display( <lv_content> ).
EXIT.
ENDLOOP.
ELSE.
MESSAGE lv_err_text TYPE 'E'.
ENDIF.
" Close HTTP Connection
lo_client->close( ).
CATCH /goog/cx_sdk INTO lo_exception.
lv_msg = lo_exception->get_text( ).
MESSAGE lv_msg TYPE 'E'.
ENDTRY.
Output:
On execution the program will show the following output:
This article serves as a stepping stone, demonstrating how to harness the power of the Text Bison LLM model through the ABAP SDK. It showcased how easy it is to access a LLM foundation model.
In future article I will explore some more concrete SAP use cases.Till tehn, please stay tuned!!!
The ABAP SDK for Google Cloud Community is now open! This is a place for you to ask questions, share knowledge, and collaborate with other ABAP developers who are using Google Cloud. We encourage you to get involved in the community and help us make the ABAP SDK for Google Cloud even better. We have a lot of exciting things planned for the future, and we want you to be a part of it.
Click the link to join and innovate with us.
Subscribe to the youtube channel where you would find, a quick 5 minutes overview covering the design principles and capabilities of ABAP SDK, reference architectures and art of the possible SAP solutions based on Google’s AI services, Google Workspace APIs and Google Maps Platform APIs…. along many more insightful references.
Follow this medium tag for more content on ABAP SDK for Google Cloud.
⭐️ Happy Learning! and Happy Innovating! ⭐️
Thanks for sharing @ameya-sap-cloud !!