Skip to content

Commit 8aed9af

Browse files
authored
chore: Orchestration spec update for config by reference (#596)
* generation * apply fix * add release note on breaking change
1 parent 4f0c83b commit 8aed9af

10 files changed

+1624
-311
lines changed

docs/release_notes.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
### 🔧 Compatibility Notes
1010

1111
- Breaking change:
12-
- two fields in `OrchestrationModuleConfig` changed:
12+
- `CompletionPostRequest` is now an interface instead of a class.
13+
For all previous use-cases, it should be substitutable with the new class `CompletionRequestConfiguration`.
14+
- `OrchestrationClient.toCompletionPostRequest()` now returns `CompletionRequestConfiguration`.
15+
- `OrchestrationClient.streamChatCompletionDeltas()` takes `CompletionRequestConfiguration` as an input now.
16+
- Two fields in `OrchestrationModuleConfig` changed:
1317
- `inputTranslationConfig` is now of type `SAPDocumentTranslationInput`
1418
- `outputTranslationConfig` is now of type `SAPDocumentTranslationOutput`
15-
- when using `OrchestrationModuleConfig.withInputTranslationConfig()` and `OrchestrationModuleConfig.withOutputTranslationConfig()` consider the following diff:
19+
- When using `OrchestrationModuleConfig.withInputTranslationConfig()` and `OrchestrationModuleConfig.withOutputTranslationConfig()` consider the following diff:
1620
```diff
1721
var config = new OrchestrationModuleConfig("some prompt");
1822
config

orchestration/src/main/java/com/sap/ai/sdk/orchestration/ConfigToRequestTransformer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.sap.ai.sdk.orchestration;
22

33
import com.sap.ai.sdk.orchestration.model.ChatMessage;
4-
import com.sap.ai.sdk.orchestration.model.CompletionPostRequest;
4+
import com.sap.ai.sdk.orchestration.model.CompletionRequestConfiguration;
55
import com.sap.ai.sdk.orchestration.model.ModuleConfigs;
66
import com.sap.ai.sdk.orchestration.model.OrchestrationConfig;
77
import com.sap.ai.sdk.orchestration.model.PromptTemplatingModuleConfig;
@@ -21,7 +21,7 @@
2121
@NoArgsConstructor(access = AccessLevel.NONE)
2222
final class ConfigToRequestTransformer {
2323
@Nonnull
24-
static CompletionPostRequest toCompletionPostRequest(
24+
static CompletionRequestConfiguration toCompletionPostRequest(
2525
@Nonnull final OrchestrationPrompt prompt, @Nonnull final OrchestrationModuleConfig config) {
2626
val template = toTemplateModuleConfig(prompt, config.getTemplateConfig());
2727

@@ -38,7 +38,7 @@ static CompletionPostRequest toCompletionPostRequest(
3838

3939
val moduleConfigs = toModuleConfigs(configCopy);
4040

41-
return CompletionPostRequest.create()
41+
return CompletionRequestConfiguration.create()
4242
.config(OrchestrationConfig.create().modules(moduleConfigs))
4343
.placeholderValues(prompt.getTemplateParameters())
4444
.messagesHistory(messageHistory);

orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.sap.ai.sdk.core.AiCoreService;
1111
import com.sap.ai.sdk.orchestration.model.CompletionPostRequest;
1212
import com.sap.ai.sdk.orchestration.model.CompletionPostResponse;
13+
import com.sap.ai.sdk.orchestration.model.CompletionRequestConfiguration;
1314
import com.sap.ai.sdk.orchestration.model.EmbeddingsPostRequest;
1415
import com.sap.ai.sdk.orchestration.model.EmbeddingsPostResponse;
1516
import com.sap.ai.sdk.orchestration.model.GlobalStreamOptions;
@@ -76,7 +77,7 @@ public OrchestrationClient(@Nonnull final HttpDestination destination) {
7677
* @return The low-level request data object to send to orchestration.
7778
*/
7879
@Nonnull
79-
public static CompletionPostRequest toCompletionPostRequest(
80+
public static CompletionRequestConfiguration toCompletionPostRequest(
8081
@Nonnull final OrchestrationPrompt prompt, @Nonnull final OrchestrationModuleConfig config) {
8182
return ConfigToRequestTransformer.toCompletionPostRequest(prompt, config);
8283
}
@@ -218,7 +219,7 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig(
218219
*/
219220
@Nonnull
220221
public Stream<OrchestrationChatCompletionDelta> streamChatCompletionDeltas(
221-
@Nonnull final CompletionPostRequest request) throws OrchestrationClientException {
222+
@Nonnull final CompletionRequestConfiguration request) throws OrchestrationClientException {
222223
request.getConfig().setStream(GlobalStreamOptions.create().enabled(true).delimiters(null));
223224

224225
return executor.stream(COMPLETION_ENDPOINT, request, customHeaders);

orchestration/src/main/java/com/sap/ai/sdk/orchestration/model/CompletionPostRequest.java

Lines changed: 9 additions & 286 deletions
Original file line numberDiff line numberDiff line change
@@ -11,291 +11,14 @@
1111

1212
package com.sap.ai.sdk.orchestration.model;
1313

14-
import com.fasterxml.jackson.annotation.JsonAnyGetter;
15-
import com.fasterxml.jackson.annotation.JsonAnySetter;
16-
import com.fasterxml.jackson.annotation.JsonIgnore;
17-
import com.fasterxml.jackson.annotation.JsonProperty;
18-
import java.util.ArrayList;
19-
import java.util.HashMap;
20-
import java.util.LinkedHashMap;
21-
import java.util.List;
22-
import java.util.Map;
23-
import java.util.NoSuchElementException;
24-
import java.util.Objects;
25-
import java.util.Set;
26-
import javax.annotation.Nonnull;
27-
import javax.annotation.Nullable;
14+
import com.fasterxml.jackson.annotation.JsonSubTypes;
15+
import com.fasterxml.jackson.annotation.JsonTypeInfo;
2816

2917
/** CompletionPostRequest */
30-
// CHECKSTYLE:OFF
31-
public class CompletionPostRequest
32-
// CHECKSTYLE:ON
33-
{
34-
@JsonProperty("config")
35-
private OrchestrationConfig config;
36-
37-
@JsonProperty("placeholder_values")
38-
private Map<String, String> placeholderValues = new HashMap<>();
39-
40-
@JsonProperty("messages_history")
41-
private List<ChatMessage> messagesHistory;
42-
43-
@JsonAnySetter @JsonAnyGetter
44-
private final Map<String, Object> cloudSdkCustomFields = new LinkedHashMap<>();
45-
46-
/** Default constructor for CompletionPostRequest. */
47-
protected CompletionPostRequest() {}
48-
49-
/**
50-
* Set the config of this {@link CompletionPostRequest} instance and return the same instance.
51-
*
52-
* @param config The config of this {@link CompletionPostRequest}
53-
* @return The same instance of this {@link CompletionPostRequest} class
54-
*/
55-
@Nonnull
56-
public CompletionPostRequest config(@Nonnull final OrchestrationConfig config) {
57-
this.config = config;
58-
return this;
59-
}
60-
61-
/**
62-
* Get config
63-
*
64-
* @return config The config of this {@link CompletionPostRequest} instance.
65-
*/
66-
@Nonnull
67-
public OrchestrationConfig getConfig() {
68-
return config;
69-
}
70-
71-
/**
72-
* Set the config of this {@link CompletionPostRequest} instance.
73-
*
74-
* @param config The config of this {@link CompletionPostRequest}
75-
*/
76-
public void setConfig(@Nonnull final OrchestrationConfig config) {
77-
this.config = config;
78-
}
79-
80-
/**
81-
* Set the placeholderValues of this {@link CompletionPostRequest} instance and return the same
82-
* instance.
83-
*
84-
* @param placeholderValues The placeholderValues of this {@link CompletionPostRequest}
85-
* @return The same instance of this {@link CompletionPostRequest} class
86-
*/
87-
@Nonnull
88-
public CompletionPostRequest placeholderValues(
89-
@Nullable final Map<String, String> placeholderValues) {
90-
this.placeholderValues = placeholderValues;
91-
return this;
92-
}
93-
94-
/**
95-
* Put one placeholderValues instance to this {@link CompletionPostRequest} instance.
96-
*
97-
* @param key The String key of this placeholderValues instance
98-
* @param placeholderValuesItem The placeholderValues that should be added under the given key
99-
* @return The same instance of type {@link CompletionPostRequest}
100-
*/
101-
@Nonnull
102-
public CompletionPostRequest putplaceholderValuesItem(
103-
@Nonnull final String key, @Nonnull final String placeholderValuesItem) {
104-
if (this.placeholderValues == null) {
105-
this.placeholderValues = new HashMap<>();
106-
}
107-
this.placeholderValues.put(key, placeholderValuesItem);
108-
return this;
109-
}
110-
111-
/**
112-
* Get placeholderValues
113-
*
114-
* @return placeholderValues The placeholderValues of this {@link CompletionPostRequest} instance.
115-
*/
116-
@Nonnull
117-
public Map<String, String> getPlaceholderValues() {
118-
return placeholderValues;
119-
}
120-
121-
/**
122-
* Set the placeholderValues of this {@link CompletionPostRequest} instance.
123-
*
124-
* @param placeholderValues The placeholderValues of this {@link CompletionPostRequest}
125-
*/
126-
public void setPlaceholderValues(@Nullable final Map<String, String> placeholderValues) {
127-
this.placeholderValues = placeholderValues;
128-
}
129-
130-
/**
131-
* Set the messagesHistory of this {@link CompletionPostRequest} instance and return the same
132-
* instance.
133-
*
134-
* @param messagesHistory History of chat messages. Can be used to provide system and assistant
135-
* messages to set the context of the conversation. Will be merged with the template message
136-
* @return The same instance of this {@link CompletionPostRequest} class
137-
*/
138-
@Nonnull
139-
public CompletionPostRequest messagesHistory(@Nullable final List<ChatMessage> messagesHistory) {
140-
this.messagesHistory = messagesHistory;
141-
return this;
142-
}
143-
144-
/**
145-
* Add one messagesHistory instance to this {@link CompletionPostRequest}.
146-
*
147-
* @param messagesHistoryItem The messagesHistory that should be added
148-
* @return The same instance of type {@link CompletionPostRequest}
149-
*/
150-
@Nonnull
151-
public CompletionPostRequest addMessagesHistoryItem(
152-
@Nonnull final ChatMessage messagesHistoryItem) {
153-
if (this.messagesHistory == null) {
154-
this.messagesHistory = new ArrayList<>();
155-
}
156-
this.messagesHistory.add(messagesHistoryItem);
157-
return this;
158-
}
159-
160-
/**
161-
* History of chat messages. Can be used to provide system and assistant messages to set the
162-
* context of the conversation. Will be merged with the template message
163-
*
164-
* @return messagesHistory The messagesHistory of this {@link CompletionPostRequest} instance.
165-
*/
166-
@Nonnull
167-
public List<ChatMessage> getMessagesHistory() {
168-
return messagesHistory;
169-
}
170-
171-
/**
172-
* Set the messagesHistory of this {@link CompletionPostRequest} instance.
173-
*
174-
* @param messagesHistory History of chat messages. Can be used to provide system and assistant
175-
* messages to set the context of the conversation. Will be merged with the template message
176-
*/
177-
public void setMessagesHistory(@Nullable final List<ChatMessage> messagesHistory) {
178-
this.messagesHistory = messagesHistory;
179-
}
180-
181-
/**
182-
* Get the names of the unrecognizable properties of the {@link CompletionPostRequest}.
183-
*
184-
* @return The set of properties names
185-
*/
186-
@JsonIgnore
187-
@Nonnull
188-
public Set<String> getCustomFieldNames() {
189-
return cloudSdkCustomFields.keySet();
190-
}
191-
192-
/**
193-
* Get the value of an unrecognizable property of this {@link CompletionPostRequest} instance.
194-
*
195-
* @deprecated Use {@link #toMap()} instead.
196-
* @param name The name of the property
197-
* @return The value of the property
198-
* @throws NoSuchElementException If no property with the given name could be found.
199-
*/
200-
@Nullable
201-
@Deprecated
202-
public Object getCustomField(@Nonnull final String name) throws NoSuchElementException {
203-
if (!cloudSdkCustomFields.containsKey(name)) {
204-
throw new NoSuchElementException(
205-
"CompletionPostRequest has no field with name '" + name + "'.");
206-
}
207-
return cloudSdkCustomFields.get(name);
208-
}
209-
210-
/**
211-
* Get the value of all properties of this {@link CompletionPostRequest} instance including
212-
* unrecognized properties.
213-
*
214-
* @return The map of all properties
215-
*/
216-
@JsonIgnore
217-
@Nonnull
218-
public Map<String, Object> toMap() {
219-
final Map<String, Object> declaredFields = new LinkedHashMap<>(cloudSdkCustomFields);
220-
if (config != null) declaredFields.put("config", config);
221-
if (placeholderValues != null) declaredFields.put("placeholderValues", placeholderValues);
222-
if (messagesHistory != null) declaredFields.put("messagesHistory", messagesHistory);
223-
return declaredFields;
224-
}
225-
226-
/**
227-
* Set an unrecognizable property of this {@link CompletionPostRequest} instance. If the map
228-
* previously contained a mapping for the key, the old value is replaced by the specified value.
229-
*
230-
* @param customFieldName The name of the property
231-
* @param customFieldValue The value of the property
232-
*/
233-
@JsonIgnore
234-
public void setCustomField(@Nonnull String customFieldName, @Nullable Object customFieldValue) {
235-
cloudSdkCustomFields.put(customFieldName, customFieldValue);
236-
}
237-
238-
@Override
239-
public boolean equals(@Nullable final java.lang.Object o) {
240-
if (this == o) {
241-
return true;
242-
}
243-
if (o == null || getClass() != o.getClass()) {
244-
return false;
245-
}
246-
final CompletionPostRequest completionPostRequest = (CompletionPostRequest) o;
247-
return Objects.equals(this.cloudSdkCustomFields, completionPostRequest.cloudSdkCustomFields)
248-
&& Objects.equals(this.config, completionPostRequest.config)
249-
&& Objects.equals(this.placeholderValues, completionPostRequest.placeholderValues)
250-
&& Objects.equals(this.messagesHistory, completionPostRequest.messagesHistory);
251-
}
252-
253-
@Override
254-
public int hashCode() {
255-
return Objects.hash(config, placeholderValues, messagesHistory, cloudSdkCustomFields);
256-
}
257-
258-
@Override
259-
@Nonnull
260-
public String toString() {
261-
final StringBuilder sb = new StringBuilder();
262-
sb.append("class CompletionPostRequest {\n");
263-
sb.append(" config: ").append(toIndentedString(config)).append("\n");
264-
sb.append(" placeholderValues: ").append(toIndentedString(placeholderValues)).append("\n");
265-
sb.append(" messagesHistory: ").append(toIndentedString(messagesHistory)).append("\n");
266-
cloudSdkCustomFields.forEach(
267-
(k, v) ->
268-
sb.append(" ").append(k).append(": ").append(toIndentedString(v)).append("\n"));
269-
sb.append("}");
270-
return sb.toString();
271-
}
272-
273-
/**
274-
* Convert the given object to string with each line indented by 4 spaces (except the first line).
275-
*/
276-
private String toIndentedString(final java.lang.Object o) {
277-
if (o == null) {
278-
return "null";
279-
}
280-
return o.toString().replace("\n", "\n ");
281-
}
282-
283-
/**
284-
* Create a type-safe, fluent-api builder object to construct a new {@link CompletionPostRequest}
285-
* instance with all required arguments.
286-
*/
287-
public static Builder create() {
288-
return (config) -> new CompletionPostRequest().config(config);
289-
}
290-
291-
/** Builder helper class. */
292-
public interface Builder {
293-
/**
294-
* Set the config of this {@link CompletionPostRequest} instance.
295-
*
296-
* @param config The config of this {@link CompletionPostRequest}
297-
* @return The CompletionPostRequest instance.
298-
*/
299-
CompletionPostRequest config(@Nonnull final OrchestrationConfig config);
300-
}
301-
}
18+
@JsonTypeInfo(use = JsonTypeInfo.Id.DEDUCTION)
19+
@JsonSubTypes({
20+
@JsonSubTypes.Type(value = CompletionRequestConfiguration.class),
21+
@JsonSubTypes.Type(value = CompletionRequestConfigurationReferenceById.class),
22+
@JsonSubTypes.Type(value = CompletionRequestConfigurationReferenceByNameScenarioVersion.class),
23+
})
24+
public interface CompletionPostRequest {}

0 commit comments

Comments
 (0)