Skip to main content

AI SDK for SAP Files Overview

AI Engine and Versions:

  • 2022-12-01
  • 2023-03-15-preview
  • 2023-05-15
  • 2023-06-01-preview
  • 2023-07-01-preview
  • 2023-08-01-preview

Demo Program

Program NamePackageDescription
ZP_MSAISDKDEMO_FILESZPENGG_AZOAI_SDK_DEMOSMS AI SDK for SAP : Demo Program for Files
tip

Review the demo program along with the content of this page to understand the use of AI SDK feature. The demo program was imported to your SAP Application server as part of AI SDK Installation.


Operations

OperationDescription
DeleteDeletes the file with the given file-id. Deletion is also allowed if a file was used, e.g., as training file in a fine-tune job.
GetGets details for a single file specified by the given file-id including status, size, purpose, etc.
Get ContentGets the content of the file specified by the given file-id. Files can be user uploaded content or generated by the service like result metrics of a fine-tune job.
ImportCreates a new file entity by importing data from a provided url. Uploaded files can, for example, be used for training or evaluating fine-tuned models.
ListGets a list of all files owned by the Azure OpenAI resource
UploadCreates a new file entity by uploading data from ABAP Application Server. Uploaded files can, for example, be used for training or evaluating fine-tuned models.

Files - Delete

Deletes the file with the given file-id. Deletion is also allowed if a file was used, e.g., as training file in a fine-tune job.


sdk_instance->files( )->delete(
EXPORTING
fileid = file_id " The identifier of the file.
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
fileidEXPORTINGstringThe identifier of the file.
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
204 No ContentThe file was successfully deleted.
Other Status CodesErrorerrorAn error occurred.

Files - Get

Gets details for a single file specified by the given file-id including status, size, purpose, etc.

DATA:
get_file_info TYPE zif_peng_azoai_sdk_types=>ty_file_get.

sdk_instance->files( )->get(
EXPORTING
fileid = file_id " The identifier of the file.
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
file = get_file_info " ABAP Ready File Information
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
fileidEXPORTINGstringThe identifier of the file.
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
fileIMPORTINGFileABAP Ready File Information
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
200 OKFilefileSuccess
Other Status CodesErrorerrorAn error occurred.

Files - Get Content

Gets the content of the file specified by the given file-id. Files can be user uploaded content or generated by the service like result metrics of a fine-tune job.

DATA:
file_content TYPE string.

sdk_instance->files( )->get_content(
EXPORTING
fileid = uploaded_file_info-id " The identifier of the file.
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
content = file_content " Content of the file
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
fileidEXPORTINGstringThe identifier of the file.
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
contentIMPORTINGstringContent of the file as string
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
200 OKstringcontentSuccess
Other Status CodesErrorerrorAn error occurred.

Files - Import

Creates a new file entity by importing data from a provided url. Imported files can, for example, be used for training or evaluating fine-tuned models.

DATA:
import_location TYPE zif_peng_azoai_sdk_types=>ty_file_import,
imported_file_info TYPE zif_peng_azoai_sdk_types=>ty_file_get.

"Specify location of file to import.
import_location-content_url = 'https://www.testfile.com/puppy.jsonl'.

"Specify what to name the file in AI Engine portal.
import_location-filename = 'Demo_File_Import.jsonl'.

"Perform the import operation.
sdk_instance->files( )->import(
EXPORTING
import_info = import_location
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
file = imported_file_info " ABAP Ready Imported File Information
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
import_infoEXPORTINGFile ImportFile Import Information
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
fileIMPORTINGFileABAP Ready Imported File Information
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
201 CreatedFilefileSuccess
Other Status CodesErrorerrorAn error occurred.

Files - List

Gets a list of all files owned by the Azure OpenAI resource. These include user uploaded content like files with purpose "fine-tune" for training or validation of fine-tunes models as well as files that are generated by the service such as "fine-tune-results" which contains various metrics for the corresponding fine-tune job.

DATA:
file_list TYPE zif_peng_azoai_sdk_types=>ty_file_list.

sdk_instance->files( )->list(
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
filelist = file_list " ABAP Ready list of files
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
filelistIMPORTINGFile ListABAP Ready File List
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
200 OKFile ListfilelistSuccess
Other Status CodesErrorerrorAn error occurred.

Files - Upload

Creates a new file entity by uploading data from ABAP Application Server. Uploaded files can, for example, be used for training or evaluating fine-tuned models.

DATA:
upload_data TYPE zif_peng_azoai_sdk_types=>tty_file_upload,

sdk_instance->files( )->upload(
EXPORTING
filename = 'Demo_File_Upload.jsonl' "File Name
jsonldata = upload_data " JSONL data to upload
IMPORTING
statuscode = status_code " Status Code
statusreason = status_reason " HTTP status description
file = uploaded_file_info " ABAP Ready uploaded file information.
error = error " ABAP Ready error details
).

Parameters and Exceptions

ParameterDirectionData TypeDescription
filenameEXPORTINGstringName of file to be set in AI Portal after successful upload.
jsonldataEXPORTINGFile Upload[]Internal table of training data.
statuscodeIMPORTINGIntegerResponse Code.
statusreasonIMPORTINGStringStatus Description/Reason
fileIMPORTINGFileABAP Ready File Information
errorIMPORTINGErrorABAP Ready error structure, if operation resulted in an error

Responses/Status Code

NameTypeStructure PopulatedDescription
201 CreatedFilefileSuccess
Other Status CodesErrorerrorAn error occurred.