Skip to content

Commit 92ccef4

Browse files
authored
Update Readme and add dedicated docs on using Destinations (#231)
1 parent 4145295 commit 92ccef4

File tree

2 files changed

+206
-177
lines changed

2 files changed

+206
-177
lines changed

README.md

Lines changed: 55 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,12 @@ The SDK simplifies the setup and interaction with SAP AI Core, allowing you to f
1414
## Table of Contents
1515

1616
- [General Requirements](#general-requirements)
17-
- [Connecting to SAP AI Core](#connecting-to-sap-ai-core)
18-
- [Option 1: Set Credentials as Environment Variable](#option-1-set-ai-core-credentials)
19-
- [Option 2: Regular Service Binding in SAP BTP Cloud Foundry](#option-2-regular-service-binding-in-sap-btp-cloud-foundry)
20-
- [Option 3: Define and Use a Destination](#option-3-define-and-use-a-destination)
2117
- [Getting Started](#getting-started)
2218
- [What You'll Build](#what-youll-build)
2319
- [Prerequisites](#prerequisites)
24-
- [Write the Code](#write-the-code)
25-
- [Run and Test the Application Locally](#run-and-test-the-application-locally)
26-
- [Deploying to Cloud Foundry (Optional)](#deploying-to-cloud-foundry-optional)
20+
- [Use the Orchestration API](#use-the-orchestration-api)
21+
- [Run the Application Locally](#run-the-application-locally)
22+
- [Explore Further Capabilities](#explore-further-capabilities)
2723
- [Documentation](#documentation)
2824
- [FAQs](#faqs)
2925
- [Contribute, Support and Feedback](#contribute-support-and-feedback)
@@ -35,219 +31,101 @@ The SDK simplifies the setup and interaction with SAP AI Core, allowing you to f
3531

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

38-
- **SAP AI Core Service** enabled in your SAP BTP account.
39-
- [How to enable the AI Core service](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/initial-setup)
40-
- **SAP AI Core Credentials** to access the AI Core service.
41-
- [Connecting to SAP AI Core](#connecting-to-sap-ai-core)
34+
- Java 17 or higher.
35+
- Access to an **SAP AI Core Service** instance.
36+
37+
Please refer to [this documentation on **how to connect the SDK to AI Core**](docs/guides/CONNECTING_TO_AICORE.md).
4238

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

45-
| Dependency | Minimum Version | Recommended Version |
46-
| --- | --- | --- |
47-
| JDK | 17 (LTS) | 21 (LTS) |
48-
| SAP Cloud SDK | 5.6.0 | latest |
49-
| (optional) CAP Java | 3.0.0 | latest |
50-
| (optional) Spring Boot | 3.0 | latest |
41+
| Dependency | Minimum Version | Recommended Version |
42+
|------------------------|-----------------|---------------------|
43+
| JDK | 17 (LTS) | 21 (LTS) |
44+
| SAP Cloud SDK | 5.6.0 | latest |
45+
| (optional) CAP Java | 3.0.0 | latest |
46+
| (optional) Spring Boot | 3.0 | latest |
5147

5248
See [an example `pom.xml` in our Spring Boot application](sample-code/spring-app/pom.xml).
5349

54-
## Connecting to SAP AI Core
55-
56-
To interact with SAP AI Core services, the SAP AI SDK requires credentials available at application runtime.
57-
By default, the SDK automatically extracts these credentials from a service instance of type `aicore` bound to your application.
58-
59-
If running the application locally without this service binding, you may encounter an exception:
60-
61-
```
62-
Could not find any matching service bindings for service identifier 'aicore'
63-
```
64-
65-
There are multiple ways to provide these credentials:
66-
67-
| Option | Description |
68-
|--------|----------------------------------------------------------------------------------------------------------|
69-
| **1** | Create an `.env` file containing an `AICORE_SERVICE_KEY={...}` |
70-
| **2** | Regular service binding in SAP BTP Cloud Foundry (results in `VCAP_SERVICES` environment variable entry) |
71-
| **3** | Define and use a _Destination_ in the SAP BTP Destination Service |
72-
73-
Additional methods (not recommended for production):
74-
75-
- Use the [hybrid testing](https://cap.cloud.sap/docs/advanced/hybrid-testing#services-on-cloud-foundry) approach for
76-
CAP applications (e.g., `cds bind --to aicore --exec mvn spring-boot:run`)
77-
- Leverage a "user-provided" service binding
78-
- Define and use a custom `ServiceBinding` or `ServiceBindingAccessor` in your application
79-
80-
### Option 1: Set AI Core Credentials
81-
82-
<details>
83-
<summary>Click to view detailed steps</summary>
84-
85-
86-
**1. Obtain Service Credentials:**
87-
88-
- Log into the **SAP BTP Cockpit**
89-
- Navigate to **Services** -> **Instances and Subscriptions** -> **Instances** -> **AI Core**
90-
- Click **View Credentials** and copy the JSON content
91-
92-
**2. Create `.env` file:**
93-
94-
- Create an `.env` file in the root directory of your application
95-
- Add a **one line** entry `AICORE_SERVICE_KEY={...}` with the copied JSON
96-
97-
<details>
98-
<summary>Set an environment variable instead of .env</summary>
50+
## Getting Started
9951

100-
**2. Set an Environment Variable: (alternative)**
52+
### What You'll Build
10153

102-
- In your IDE or terminal, set the environment variable `AICORE_SERVICE_KEY` with the copied JSON content
54+
In this quickstart, you'll use the OpenAI GPT-4o model through the [Orchestration Service of AI Core](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/orchestration) for generating text.
55+
The application will send a prompt to the AI model and display the generated response.
10356

104-
ℹ️ The environment variable has priority over the `.env` file.
57+
### Prerequisites
10558

106-
Example Linux/MacOS:
59+
This quickstart assumes you have a **deployment of the Orchestration service available** in the `default` resource group of your AI Core instance.
60+
If you don't have a deployment yet, please refer to [this guide](https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/create-deployment-for-orchestration) on how to create one.
10761

108-
```shell
109-
export AICORE_SERVICE_KEY='{ "clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }'
110-
```
62+
### Add the SDK as a Dependency
11163

112-
Example Windows:
64+
Add the following dependency to your `pom.xml` file:
11365

114-
```shell
115-
$env:AICORE_SERVICE_KEY='{ "clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }'
66+
```xml
67+
<dependency>
68+
<groupId>com.sap.ai.sdk</groupId>
69+
<artifactId>orchestration</artifactId>
70+
<!-- Use the latest version here -->
71+
<version>${ai-sdk.version}</version>
72+
</dependency>
11673
```
11774

118-
</details>
119-
</details>
120-
121-
### Option 2: Regular Service Binding in SAP BTP Cloud Foundry
122-
123-
<details>
124-
<summary>Click to view detailed steps</summary>
125-
75+
### Use the Orchestration API
12676

127-
**1. Bind an existing `aicore` service instance to your application**
77+
We'll use a `client` to interact with the Orchestration service:
12878

129-
SAP BTP provides multiple ways to do this:
130-
131-
- Using the web interface
132-
- Using the CLI
133-
- Using MTA or manifest files
134-
135-
[Learn more about binding service instances to applications](https://help.sap.com/docs/btp/sap-business-technology-platform/binding-service-instances-to-applications)
136-
137-
After restarting your application, you should see an "aicore" entry in the `VCAP_SERVICES` environment variable:
138-
139-
```json
140-
{
141-
"aicore": [
142-
{
143-
"clientid": "...",
144-
"clientsecret": "...",
145-
"url": "...",
146-
"serviceurls": {
147-
"AI_API_URL": "..."
148-
}
149-
}
150-
]
151-
}
79+
```java
80+
var client = new OrchestrationClient();
15281
```
15382

154-
</details>
155-
156-
### Option 3: Define and Use a Destination
157-
158-
<details>
159-
<summary>Click to view detailed steps</summary>
160-
161-
**1. Obtain Service Credentials:** (Same as in Option 1)
162-
163-
**2. Create a Destination:**
164-
165-
- In the **SAP BTP Cockpit**, go to **Connectivity** -> **Destinations**
166-
- Click **New Destination** and configure:
167-
168-
- **Name**: `my-aicore`
169-
- **Type**: `HTTP`
170-
- **URL**: `[serviceurls.AI_API_URL]`
171-
- **Proxy Type**: `Internet`
172-
- **Authentication**: `OAuth2ClientCredentials`
173-
- **Client ID**: `[clientid]`
174-
- **Client Secret**: `[clientsecret]`
175-
- **Token Service URL Type**: `Dedicated`
176-
- **Token Service URL**: `[url]`
177-
178-
**3. Use the Destination in Your Application:**
83+
Next, we'll specify the model we want to use:
17984

18085
```java
181-
Destination destination = DestinationAccessor.getDestination("my-aicore");
182-
AiCoreService aiCoreService = new AiCoreService().withDestination(destination);
183-
DeploymentApi client = new DeploymentApi(aiCoreService);
86+
var config = new OrchestrationModuleConfig()
87+
.withLlmConfig(OrchestrationAiModel.GPT_4O);
18488
```
18589

186-
</details>
90+
Now we can create our first prompt:
18791

188-
## Getting Started
189-
190-
### What You'll Build
191-
192-
In this quickstart, you'll build a simple Spring Boot application that uses the OpenAI GPT-3.5 Turbo model for chat completion.
193-
The application will send a prompt to the AI model and display the generated response.
194-
195-
### Prerequisites
196-
197-
Before you begin, ensure you have:
198-
199-
- Met the [General Requirements](#general-requirements).
200-
- Met the OpenAI Chat Completion module specific requirements
201-
- Refer to [Prerequisites for OpenAI Chat Completion](docs/guides/OPENAI_CHAT_COMPLETION.md#prerequisites)
202-
- Set up the AI Core credentials
203-
using [(1) Environment variable or env-file](#option-1-set-ai-core-credentials)
204-
or [(2) Regular Service Binding](#option-2-regular-service-binding-in-sap-btp-cloud-foundry).
205-
- Deployed the OpenAI GPT-3.5 Turbo model in SAP AI Core.
206-
- Refer to [Deploying the OpenAI GPT-3.5 Turbo Model](docs/guides/OPENAI_CHAT_COMPLETION.md#usage)
92+
```java
93+
var prompt = new OrchestrationPrompt("Hello world! Why is this phrase so famous?");
20794

208-
### Write the Code
95+
var result = client.chatCompletion(prompt, config).getContent();
96+
```
20997

210-
Add the following code to the controller or service class in your Spring Boot application:
98+
The result will be the text generated by the AI model.
21199

212-
```java
213-
// Initialize the client for GPT-3.5 Turbo model
214-
OpenAiClient client = OpenAiClient.forModel(OpenAiModel.GPT_35_TURBO);
215-
216-
// Perform chat completion
217-
OpenAiChatCompletionOutput result =
218-
client
219-
.withSystemPrompt("You are a helpful assistant.")
220-
.chatCompletion("Hello World! Why is this phrase so famous?");
221-
```
100+
### Run the Application Locally
222101

223-
### Run and Test the Application Locally
102+
In order to run the application locally, you need to provide credentials for your AI Core service instance.
224103

225-
Then, compile and run your application:
104+
For this example we'll use a **service key** and pass it as an **environment variable** to the application.
226105

227106
```shell
228107
cd your-spring-app/
229108

230-
mvn compile
109+
# assuming a bash, for other shells (e.g. PowerShell) see the below documentation
110+
export AICORE_SERVICE_KEY='{ "clientid": "...", "clientsecret": "...", "url": "...", "serviceurls": { "AI_API_URL": "..." } }'
111+
112+
# assuming Maven and a Spring Boot application
231113
mvn spring-boot:run
232114
```
233115

234-
### Deploying to Cloud Foundry (Optional)
235-
236-
When deploying your productive application to Cloud Foundry, it is recommended to use **service binding** to provide the AI Core credentials as per [Option 2](#option-2-regular-service-binding-in-sap-btp-cloud-foundry).
237-
238-
Build your application using Maven and deploy it to Cloud Foundry:
116+
Please find **detailed instructions** and more examples [in this documentation](docs/guides/CONNECTING_TO_AICORE.md#using-the-aicore_service_key-environment-variable).
239117

240-
```shell
241-
cf push
242-
```
118+
### Explore Further Capabilities
243119

244-
That's it!
245-
Your application should now be running on Cloud Foundry, and the AI Core credentials are provided securely via service binding.
120+
Check out the options available for the `OrchestrationPrompt` and `OrchestrationModuleConfig` classes.
121+
You can use templating, content filtering, data masking and more.
122+
Please refer to [this documentation](docs/guides/ORCHESTRATION_CHAT_COMPLETION.md) for more information.
246123

247124
## Documentation
248125

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

128+
- [Connecting to AI Core](docs/guides/CONNECTING_TO_AICORE.md)
251129
- [Orchestration Chat Completion](docs/guides/ORCHESTRATION_CHAT_COMPLETION.md)
252130
- [OpenAI Chat Completion](docs/guides/OPENAI_CHAT_COMPLETION.md)
253131
- [AI Core Deployment](docs/guides/AI_CORE_DEPLOYMENT.md)

0 commit comments

Comments
 (0)