Skip to content
generated from SAP/repository-template

Integrate chat completion into your business applications with SAP Cloud SDK for AI. Leverage the Generative AI Hub of SAP AI Core to make use of templating, grounding, data masking, content filtering and more. Access all features of SAP AI Core with the SAP Cloud SDK for AI.

License

Notifications You must be signed in to change notification settings

SAP/ai-sdk-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

build CodeQL REUSE status Fosstars security rating

SAP Cloud SDK SAP Cloud SDK for AI (for Java)

SAP Cloud SDK for AI is the official Software Development Kit (SDK) for SAP AI Core, SAP Generative AI Hub, and Orchestration Service.

This SDK enables developers to seamlessly integrate AI capabilities, such as chat completion, into their Java-based business applications using SAP's Generative AI Hub. Leverage powerful features like templating, grounding, data masking, and content filtering to build intelligent applications. The SDK simplifies the setup and interaction with SAP AI Core, allowing you to focus on delivering value through AI integration.

Table of Contents

General Requirements

To use the SDK in a Java application, it is necessary to understand the technical prerequisites and required versions for common dependencies.

  • Java 17 or higher.
  • Access to an SAP AI Core Service instance.

Please refer to this documentation on how to connect the SDK to AI Core.

The following table lists the required versions, based on the latest release:

Dependency Minimum Version Recommended Version
JDK 17 (LTS) 21 (LTS)
SAP Cloud SDK 5.6.0 latest
(optional) CAP Java 3.0.0 latest
(optional) Spring Boot 3.0 latest

See an example pom.xml in our Spring Boot application.

Getting Started

What You'll Build

In this quickstart, you'll use the OpenAI GPT-4o model through the Orchestration Service of AI Core for generating text. The application will send a prompt to the AI model and display the generated response.

Prerequisites

This quickstart assumes you have a deployment of the Orchestration service available in the default resource group of your AI Core instance. If you don't have a deployment yet, please refer to this guide on how to create one.

Add the SDK as a Dependency

Add the following dependency to your pom.xml file:

<dependency>
    <groupId>com.sap.ai.sdk</groupId>
    <artifactId>orchestration</artifactId>
    <!-- Use the latest version here -->
    <version>${ai-sdk.version}</version>
</dependency>

Use the Orchestration API

We'll use a client to interact with the Orchestration service:

var client = new OrchestrationClient();

Next, we'll specify the model we want to use:

var config = new OrchestrationModuleConfig()
        .withLlmConfig(OrchestrationAiModel.GPT_4O);

Now we can create our first prompt:

var prompt = new OrchestrationPrompt("Hello world! Why is this phrase so famous?");

var result = client.chatCompletion(prompt, config).getContent();

The result will be the text generated by the AI model.

Run the Application Locally

In order to run the application locally, you need to provide credentials for your AI Core service instance.

For this example we'll use a service key and pass it as an environment variable to the application.

cd your-spring-app/

# assuming a bash, for other shells (e.g. PowerShell) see the below documentation
export AICORE_SERVICE_KEY='{ "clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }'

# assuming Maven and a Spring Boot application
mvn spring-boot:run

Please find detailed instructions and more examples in this documentation.

Explore Further Capabilities

Check out the options available for the OrchestrationPrompt and OrchestrationModuleConfig classes. You can use templating, content filtering, data masking and more. Please refer to this documentation for more information.

Documentation

For more detailed information and advanced usage, please refer to the following:

FAQs

"How to add a custom header to AI Core requests?"

Create a HeaderProvider.

"There's a vulnerability warning CVE-2021-41251?"

This is a known false-positive finding. Depending on the tooling any product called "SAP Cloud SDK" or similar with a low version number may be marked as vulnerable, incorrectly. Please consider suppressing the warning, as we do.

"Are there any example projects?"

Explore example applications and code snippets:

Contribute, Support and Feedback

This project is open to feature requests/suggestions, bug reports etc. via GitHub issues. Contribution and feedback are encouraged and always welcome. For more information about how to contribute, the project structure, as well as additional contribution information, see our Contribution Guidelines.

Security / Disclosure

If you find any bug that may be a security problem, please follow our instructions at in our security policy on how to report it. Please do not create GitHub issues for security-related doubts or problems.

Code of Conduct

We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone. By participating in this project, you agree to abide by its Code of Conduct at all times.

Licensing

Copyright 2024 SAP SE or an SAP affiliate company and ai-sdk-java contributors. Please see our LICENSE for copyright and license information. Detailed information including third-party components and their licensing/copyright information is available via the REUSE tool.

About

Integrate chat completion into your business applications with SAP Cloud SDK for AI. Leverage the Generative AI Hub of SAP AI Core to make use of templating, grounding, data masking, content filtering and more. Access all features of SAP AI Core with the SAP Cloud SDK for AI.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages