Skip to content

Commit 2f4bcc7

Browse files
committed
Merge remote-tracking branch 'origin/main' into grounding-client
# Conflicts: # pom.xml
2 parents a84ab71 + 5a14d4f commit 2f4bcc7

File tree

103 files changed

+19162
-39
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+19162
-39
lines changed

.pipeline/checkstyle-suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,12 @@
88
<!-- Suppress generated clients -->
99
<suppress files="[/\\]core[/\\]client[/\\]" checks=".*"/>
1010
<suppress files="[/\\]core[/\\]model[/\\]" checks=".*"/>
11+
<suppress files="[/\\]openai[/\\]generated[/\\]model[/\\]" checks=".*"/>
1112
<suppress files="[/\\]orchestration[/\\]model[/\\]" checks=".*"/>
1213
<suppress files="[/\\]grounding[/\\]api[/\\]" checks=".*"/>
1314
<suppress files="[/\\]grounding[/\\]model[/\\]" checks=".*"/>
1415
<!-- Suppress TODOs -->
1516
<suppress files="OpenAiChatMessage.java" checks="TodoComment" lines="257,7" />
17+
<suppress files="ChatCompletionResponseMessage.java" checks="TodoComment" lines="53,34" />
18+
<suppress files="CreateChatCompletionRequest.java" checks="TodoComment" lines="73,47" />
1619
</suppressions>

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,19 @@ For SAP internal development, you can also use `SNAPSHOT` builds from the [inter
155155

156156
### _"How to add a custom header to AI Core requests?"_
157157

158-
Create a [HeaderProvider](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations#about-headerproviders).
158+
The AI SDK leverages the destination concept from the SAP Cloud SDK to manage the connection to AI Core.
159+
This opens up a wide range of possibilities to customize the connection, including adding custom headers.
159160

161+
```java
162+
var service = new AiCoreService();
163+
var service = service.withBaseDestination(
164+
DefaultHttpDestination.fromDestination(service.getBaseDestination())
165+
.header("my-header-key", "my-header-value")
166+
.build()
167+
);
168+
```
169+
170+
For more information, please refer to the [AI Core connectivity guide](./docs/guides/CONNECTING_TO_AICORE.md) and the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/http-destinations).
160171

161172
### _"There's a vulnerability warning `CVE-2021-41251`?"_
162173

core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sap.ai.sdk</groupId>
66
<artifactId>sdk-parent</artifactId>
7-
<version>1.3.0-SNAPSHOT</version>
7+
<version>1.4.0-SNAPSHOT</version>
88
</parent>
99
<artifactId>core</artifactId>
1010
<name>AI Core client</name>

docs/guides/CONNECTING_TO_AICORE.md

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- [Providing a Service Binding Locally](#providing-a-service-binding-locally)
77
- [Using the `AICORE_SERVICE_KEY` Environment Variable](#using-the-aicore_service_key-environment-variable)
88
- [Using a Destination from the BTP Destination Service](#using-a-destination-from-the-btp-destination-service)
9+
- [Creating a Custom Destination](#creating-a-custom-destination)
910

1011

1112
The AI SDK uses the [`Destination` concept of the SAP Cloud SDK](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service) to connect to AI Core.
@@ -152,4 +153,23 @@ new DeploymentApi(aiCoreService);
152153
> The `destination` obtained from BTP destination service will expire once the contained OAuth2 token expires.
153154
> Please run the above code for each request to ensure the destination is up-to-date.
154155
> Destinations are cached by default, so this does not come with a performance penalty.
155-
> To learn more, see the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).
156+
> To learn more, see the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).
157+
158+
## Creating a Custom Destination
159+
160+
If the above options are not suitable for your use case (e.g. because you are obtaining the credentials in a completely different way), you can also use a custom-built destination:
161+
162+
```java
163+
var destination = OAuth2DestinationBuilder
164+
.forTargetUrl("https://<ai-api-url>")
165+
.withTokenEndpoint("https://<xsuaa-url>/oauth/token")
166+
.withClient(new ClientCertificate("<cert>", "<key>", "<clientid>"), OnBehalfOf.TECHNICAL_USER_PROVIDER)
167+
.build();
168+
169+
AiCoreService aiCoreService = new AiCoreService().withBaseDestination(destination);
170+
```
171+
172+
The above example assumes you are using a client certificate for authentication and have stored the relevant credentials somewhere.
173+
You are free to use X509 certificates (also via the Zero Trust Identity Service) or a client secret.
174+
175+
For more details, refer to the [SAP Cloud SDK documentation](https://sap.github.io/cloud-sdk/docs/java/features/connectivity/destination-service).

docs/guides/ORCHESTRATION_CHAT_COMPLETION.md

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- [Data Masking](#data-masking)
1313
- [Grounding](#grounding)
1414
- [Stream chat completion](#stream-chat-completion)
15+
- [Add images and multiple text inputs to a message](#add-images-and-multiple-text-inputs-to-a-message)
16+
- [Set a Response Format](#set-a-response-format)
1517
- [Set Model Parameters](#set-model-parameters)
1618
- [Using a Configuration from AI Launchpad](#using-a-configuration-from-ai-launchpad)
1719

@@ -300,6 +302,73 @@ Note, that only user and system messages are supported for multiple text inputs.
300302
Please find [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java).
301303

302304

305+
## Set a Response Format
306+
307+
It is possible to set the response format for the chat completion. Available options are using `JSON_OBJECT`, `JSON_SCHEMA`, and `TEXT`, where `TEXT` is the default behavior.
308+
309+
### JSON_OBJECT
310+
311+
Setting the response format to `JSON_OBJECT` tells the AI to respond with JSON, i.e., the response from the AI will be a string consisting of a valid JSON. This does, however, not guarantee that the response adheres to a specific structure (other than being valid JSON).
312+
313+
```java
314+
var template = Message.user("What is 'apple' in German?");
315+
var templatingConfig =
316+
Template.create()
317+
.template(List.of(template.createChatMessage()))
318+
.responseFormat(
319+
ResponseFormatJsonObject.create()
320+
.type(ResponseFormatJsonObject.TypeEnum.JSON_OBJECT));
321+
var configWithTemplate = llmWithImageSupportConfig.withTemplateConfig(templatingConfig);
322+
323+
var prompt =
324+
new OrchestrationPrompt(
325+
Message.system(
326+
"You are a language translator. Answer using the following JSON format: {\"language\": ..., \"translation\": ...}"));
327+
var response = client.chatCompletion(prompt, configWithTemplate).getContent();
328+
```
329+
Note, that it is necessary to tell the AI model to actually return a JSON object in the prompt. The result might not adhere exactly to the given JSON format, but it will be a JSON object.
330+
331+
332+
### JSON_SCHEMA
333+
334+
If you want the response to not only consist of valid JSON but additionally adhere to a specific JSON schema, you can use `JSON_SCHEMA`. in order to do that, add a JSON schema to the configuration as shown below and the response will adhere to the given schema.
335+
336+
```java
337+
var template = Message.user("Whats '%s' in German?".formatted(word));
338+
var schema =
339+
Map.of(
340+
"type",
341+
"object",
342+
"properties",
343+
Map.of(
344+
"language", Map.of("type", "string"),
345+
"translation", Map.of("type", "string")),
346+
"required",
347+
List.of("language", "translation"),
348+
"additionalProperties",
349+
false);
350+
351+
// Note, that we plan to add more convenient ways to add a JSON schema in the future.
352+
var templatingConfig =
353+
Template.create()
354+
.template(List.of(template.createChatMessage()))
355+
.responseFormat(
356+
ResponseFormatJsonSchema.create()
357+
.type(ResponseFormatJsonSchema.TypeEnum.JSON_SCHEMA)
358+
.jsonSchema(
359+
ResponseFormatJsonSchemaJsonSchema.create()
360+
.name("translation_response")
361+
.schema(schema)
362+
.strict(true)
363+
.description("Output schema for language translation.")));
364+
var configWithTemplate = llmWithImageSupportConfig.withTemplateConfig(templatingConfig);
365+
366+
var prompt = new OrchestrationPrompt(Message.system("You are a language translator."));
367+
var response = client.chatCompletion(prompt, configWithTemplate).getContent();
368+
```
369+
370+
Please find [an example in our Spring Boot application](../../sample-code/spring-app/src/main/java/com/sap/ai/sdk/app/services/OrchestrationService.java)
371+
303372
## Set model parameters
304373

305374
Change your LLM configuration to add model parameters:

docs/release-notes/release-notes-0-to-14.md

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
## 1.3.0 - February 13, 2025
2+
3+
[All Release Changes](https://github.com/SAP/ai-sdk-java/releases/tag/rel%2F1.3.0)
4+
5+
### 🔧 Compatibility Notes
6+
7+
- `Message.content()` returns a `ContentItem` now instead of a `String`. Use `((TextItem) Message.content().items().get(0)).text()` if the corresponding `ContentItem` is a `TextItem` and the string representation is needed.
8+
9+
### ✨ New Functionality
10+
11+
- Upgrade to release 2502a of AI Core.
12+
- Orchestration:
13+
- [Add `LlamaGuardFilter`](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#chat-completion-filter).
14+
- [Convenient methods to create messages containing images and multiple text inputs](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#add-images-and-multiple-text-inputs-to-a-message)
15+
- [Enable setting the response format](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#set-a-response-format)
16+
17+
118
## 1.2.0 - January 30, 2025
219

320
[All Release Changes](https://github.com/SAP/ai-sdk-java/releases/tag/rel%2F1.2.0)
@@ -11,8 +28,8 @@
1128
### ✨ New Functionality
1229

1330
- New Orchestration features:
14-
- [Spring AI integration](../guides/SPRING_AI_INTEGRATION.md)
15-
- [Add Grounding configuration convenience](../guides/ORCHESTRATION_CHAT_COMPLETION.md#grounding)
31+
- [Spring AI integration](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/SPRING_AI_INTEGRATION.md)
32+
- [Add Grounding configuration convenience](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#grounding)
1633
- Images are now supported as input in newly introduced `MultiChatMessage`.
1734
- `MultiChatMessage` also allows for multiple content items (text or image) in one object.
1835
- Grounding input can be masked with `DPIConfig`.

docs/release-notes/release_notes.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,11 @@
88

99
### 🔧 Compatibility Notes
1010

11-
- `Message.content()` returns a `ContentItem` now instead of a `String`. Use `((TextItem) Message.content().items().get(0)).text()` if the corresponding `ContentItem` is a `TextItem` and the string representation is needed.
11+
- The constructors `UserMessage(MessageContent)` and `SystemMessage(MessageContent)` are removed. Use `Message.user(String)`, `Message.user(ImageItem)`, or `Message.system(String)` instead.
1212

1313
### ✨ New Functionality
1414

15-
- Upgrade to release 2502a of AI Core.
16-
- Orchestration:
17-
- [Add `LlamaGuardFilter`](../guides/ORCHESTRATION_CHAT_COMPLETION.md#chat-completion-filter).
18-
- [Convenient methods to create messages containing images and multiple text inputs](../guides/ORCHESTRATION_CHAT_COMPLETION.md#add-images-and-multiple-text-inputs-to-a-message)
15+
-
1916

2017
### 📈 Improvements
2118

foundation-models/openai/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>com.sap.ai.sdk</groupId>
66
<artifactId>sdk-parent</artifactId>
7-
<version>1.3.0-SNAPSHOT</version>
7+
<version>1.4.0-SNAPSHOT</version>
88
<relativePath>../../pom.xml</relativePath>
99
</parent>
1010
<groupId>com.sap.ai.sdk.foundationmodels</groupId>

0 commit comments

Comments
 (0)