Skip to content

Commit cec2591

Browse files
committed
Merge branch 'main' into orch-schema-convenience
2 parents d7c5039 + c1f67dc commit cec2591

File tree

90 files changed

+18513
-16
lines changed

Some content is hidden

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

90 files changed

+18513
-16
lines changed

.pipeline/checkstyle-suppressions.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@
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 TODOs -->
1314
<suppress files="OpenAiChatMessage.java" checks="TodoComment" lines="257,7" />
15+
<suppress files="ChatCompletionResponseMessage.java" checks="TodoComment" lines="53,34" />
16+
<suppress files="CreateChatCompletionRequest.java" checks="TodoComment" lines="73,47" />
1417
</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/release-notes/release-notes-0-to-14.md

Lines changed: 17 additions & 0 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)

docs/release-notes/release_notes.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +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`](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#chat-completion-filter).
18-
- [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)
19-
- [Enable setting the response format](https://github.com/SAP/ai-sdk-java/tree/main/docs/guides/ORCHESTRATION_CHAT_COMPLETION.md#set-a-response-format)
15+
-
2016

2117
### 📈 Improvements
2218

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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Copyright (c) 2025 SAP SE or an SAP affiliate company. All rights reserved.
3+
*/
4+
5+
/*
6+
* Azure OpenAI Service API
7+
* Azure OpenAI APIs for completions and search
8+
*
9+
* The version of the OpenAPI document: 2024-10-21
10+
*
11+
*
12+
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
13+
* https://openapi-generator.tech
14+
* Do not edit the class manually.
15+
*/
16+
17+
package com.sap.ai.sdk.foundationmodels.openai.generated.model;
18+
19+
import com.fasterxml.jackson.annotation.JsonAnyGetter;
20+
import com.fasterxml.jackson.annotation.JsonAnySetter;
21+
import com.fasterxml.jackson.annotation.JsonIgnore;
22+
import com.fasterxml.jackson.annotation.JsonProperty;
23+
import java.util.LinkedHashMap;
24+
import java.util.Map;
25+
import java.util.NoSuchElementException;
26+
import java.util.Objects;
27+
import java.util.Set;
28+
import javax.annotation.Nonnull;
29+
import javax.annotation.Nullable;
30+
31+
/**
32+
* Deprecated and replaced by &#x60;tool_calls&#x60;. The name and arguments of a function that
33+
* should be called, as generated by the model.
34+
*/
35+
// CHECKSTYLE:OFF
36+
@com.google.common.annotations.Beta
37+
public class ChatCompletionFunctionCall
38+
// CHECKSTYLE:ON
39+
{
40+
@JsonProperty("name")
41+
private String name;
42+
43+
@JsonProperty("arguments")
44+
private String arguments;
45+
46+
@JsonAnySetter @JsonAnyGetter
47+
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
48+
49+
/**
50+
* Set the name of this {@link ChatCompletionFunctionCall} instance and return the same instance.
51+
*
52+
* @param name The name of the function to call.
53+
* @return The same instance of this {@link ChatCompletionFunctionCall} class
54+
*/
55+
@Nonnull
56+
public ChatCompletionFunctionCall name(@Nonnull final String name) {
57+
this.name = name;
58+
return this;
59+
}
60+
61+
/**
62+
* The name of the function to call.
63+
*
64+
* @return name The name of this {@link ChatCompletionFunctionCall} instance.
65+
*/
66+
@Nonnull
67+
public String getName() {
68+
return name;
69+
}
70+
71+
/**
72+
* Set the name of this {@link ChatCompletionFunctionCall} instance.
73+
*
74+
* @param name The name of the function to call.
75+
*/
76+
public void setName(@Nonnull final String name) {
77+
this.name = name;
78+
}
79+
80+
/**
81+
* Set the arguments of this {@link ChatCompletionFunctionCall} instance and return the same
82+
* instance.
83+
*
84+
* @param arguments The arguments to call the function with, as generated by the model in JSON
85+
* format. Note that the model does not always generate valid JSON, and may hallucinate
86+
* parameters not defined by your function schema. Validate the arguments in your code before
87+
* calling your function.
88+
* @return The same instance of this {@link ChatCompletionFunctionCall} class
89+
*/
90+
@Nonnull
91+
public ChatCompletionFunctionCall arguments(@Nonnull final String arguments) {
92+
this.arguments = arguments;
93+
return this;
94+
}
95+
96+
/**
97+
* The arguments to call the function with, as generated by the model in JSON format. Note that
98+
* the model does not always generate valid JSON, and may hallucinate parameters not defined by
99+
* your function schema. Validate the arguments in your code before calling your function.
100+
*
101+
* @return arguments The arguments of this {@link ChatCompletionFunctionCall} instance.
102+
*/
103+
@Nonnull
104+
public String getArguments() {
105+
return arguments;
106+
}
107+
108+
/**
109+
* Set the arguments of this {@link ChatCompletionFunctionCall} instance.
110+
*
111+
* @param arguments The arguments to call the function with, as generated by the model in JSON
112+
* format. Note that the model does not always generate valid JSON, and may hallucinate
113+
* parameters not defined by your function schema. Validate the arguments in your code before
114+
* calling your function.
115+
*/
116+
public void setArguments(@Nonnull final String arguments) {
117+
this.arguments = arguments;
118+
}
119+
120+
/**
121+
* Get the names of the unrecognizable properties of the {@link ChatCompletionFunctionCall}.
122+
*
123+
* @return The set of properties names
124+
*/
125+
@JsonIgnore
126+
@Nonnull
127+
public Set<String> getCustomFieldNames() {
128+
return cloudSdkCustomFields.keySet();
129+
}
130+
131+
/**
132+
* Get the value of an unrecognizable property of this {@link ChatCompletionFunctionCall}
133+
* instance.
134+
*
135+
* @param name The name of the property
136+
* @return The value of the property
137+
* @throws NoSuchElementException If no property with the given name could be found.
138+
*/
139+
@Nullable
140+
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
141+
if (!cloudSdkCustomFields.containsKey(name)) {
142+
throw new NoSuchElementException(
143+
"ChatCompletionFunctionCall has no field with name '" + name + "'.");
144+
}
145+
return cloudSdkCustomFields.get(name);
146+
}
147+
148+
/**
149+
* Set an unrecognizable property of this {@link ChatCompletionFunctionCall} instance. If the map
150+
* previously contained a mapping for the key, the old value is replaced by the specified value.
151+
*
152+
* @param customFieldName The name of the property
153+
* @param customFieldValue The value of the property
154+
*/
155+
@JsonIgnore
156+
public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) {
157+
cloudSdkCustomFields.put(customFieldName, customFieldValue);
158+
}
159+
160+
@Override
161+
public boolean equals(@Nullable final Object o) {
162+
if (this == o) {
163+
return true;
164+
}
165+
if (o == null || getClass() != o.getClass()) {
166+
return false;
167+
}
168+
final ChatCompletionFunctionCall chatCompletionFunctionCall = (ChatCompletionFunctionCall) o;
169+
return Objects.equals(
170+
this.cloudSdkCustomFields, chatCompletionFunctionCall.cloudSdkCustomFields)
171+
&& Objects.equals(this.name, chatCompletionFunctionCall.name)
172+
&& Objects.equals(this.arguments, chatCompletionFunctionCall.arguments);
173+
}
174+
175+
@Override
176+
public int hashCode() {
177+
return Objects.hash(name, arguments, cloudSdkCustomFields);
178+
}
179+
180+
@Override
181+
@Nonnull
182+
public String toString() {
183+
final StringBuilder sb = new StringBuilder();
184+
sb.append("class ChatCompletionFunctionCall {\n");
185+
sb.append(" name: ").append(toIndentedString(name)).append("\n");
186+
sb.append(" arguments: ").append(toIndentedString(arguments)).append("\n");
187+
cloudSdkCustomFields.forEach(
188+
(k, v) ->
189+
sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
190+
sb.append("}");
191+
return sb.toString();
192+
}
193+
194+
/**
195+
* Convert the given object to string with each line indented by 4 spaces (except the first line).
196+
*/
197+
private String toIndentedString(final Object o) {
198+
if (o == null) {
199+
return "null";
200+
}
201+
return o.toString().replace("\n", "\n ");
202+
}
203+
}

0 commit comments

Comments
 (0)