Skip to content

Commit bc0f64a

Browse files
Alex's review comments
1 parent afa6f9f commit bc0f64a

File tree

5 files changed

+41
-50
lines changed

5 files changed

+41
-50
lines changed

docs/release-notes/release_notes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
- Orchestration supports images as input in newly introduced `MultiChatMessage`.
1818
- `MultiChatMessage` also allows for multiple content items (text or image) in one object.
1919
- Grounding input can be masked with `DPIConfig`.
20-
- [Integrated the Orchestration client in Spring AI.](../guides/ORCHESTRATION_CHAT_COMPLETION.md#spring-ai-integration)
20+
- [Integrate the Orchestration client in Spring AI.](../guides/ORCHESTRATION_CHAT_COMPLETION.md#spring-ai-integration)
2121

2222
### 📈 Improvements
2323

orchestration/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<dependency>
5858
<groupId>org.springframework.ai</groupId>
5959
<artifactId>spring-ai-core</artifactId>
60+
<optional>true</optional>
6061
</dependency>
6162
<dependency>
6263
<groupId>org.apache.httpcomponents.core5</groupId>

orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatModel.java

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

3+
import com.google.common.annotations.Beta;
34
import com.sap.ai.sdk.orchestration.AssistantMessage;
45
import com.sap.ai.sdk.orchestration.OrchestrationClient;
56
import com.sap.ai.sdk.orchestration.OrchestrationPrompt;
@@ -17,13 +18,22 @@
1718
import org.springframework.ai.chat.model.ChatResponse;
1819
import org.springframework.ai.chat.prompt.Prompt;
1920

20-
/** Spring AI integration for the orchestration service. */
21+
/**
22+
* Spring AI integration for the orchestration service.
23+
*
24+
* @since 1.2.0
25+
*/
26+
@Beta
2127
@Slf4j
2228
@RequiredArgsConstructor
2329
public class OrchestrationChatModel implements ChatModel {
2430
@Nonnull private OrchestrationClient client;
2531

26-
/** Default constructor. */
32+
/**
33+
* Default constructor.
34+
*
35+
* @since 1.2.0
36+
*/
2737
public OrchestrationChatModel() {
2838
this.client = new OrchestrationClient();
2939
}
@@ -32,8 +42,7 @@ public OrchestrationChatModel() {
3242
@Override
3343
public ChatResponse call(@Nonnull final Prompt prompt) {
3444

35-
if (prompt.getOptions() != null
36-
&& prompt.getOptions() instanceof OrchestrationChatOptions options) {
45+
if (prompt.getOptions() instanceof OrchestrationChatOptions options) {
3746

3847
val orchestrationPrompt = toOrchestrationPrompt(prompt);
3948
val response = client.chatCompletion(orchestrationPrompt, options.getConfig());
@@ -49,8 +58,6 @@ private OrchestrationPrompt toOrchestrationPrompt(@Nonnull final Prompt prompt)
4958
return new OrchestrationPrompt(Map.of(), messages);
5059
}
5160

52-
// endregion
53-
5461
@Nonnull
5562
private static com.sap.ai.sdk.orchestration.Message[] toOrchestrationMessages(
5663
@Nonnull final List<Message> messages) {

orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatOptions.java

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.TEMPERATURE;
77
import static com.sap.ai.sdk.orchestration.OrchestrationAiModel.Parameter.TOP_P;
88

9+
import com.google.common.annotations.Beta;
910
import com.sap.ai.sdk.orchestration.OrchestrationModuleConfig;
1011
import com.sap.ai.sdk.orchestration.model.LLMModuleConfig;
11-
import java.util.ArrayList;
12-
import java.util.LinkedHashMap;
1312
import java.util.List;
13+
import java.util.Map;
1414
import java.util.Objects;
1515
import javax.annotation.Nonnull;
1616
import javax.annotation.Nullable;
@@ -21,7 +21,12 @@
2121
import lombok.val;
2222
import org.springframework.ai.chat.prompt.ChatOptions;
2323

24-
/** Configuration to be used for orchestration requests. */
24+
/**
25+
* Configuration to be used for orchestration requests.
26+
*
27+
* @since 1.2.0
28+
*/
29+
@Beta
2530
@Data
2631
@Getter(AccessLevel.NONE)
2732
@Setter(AccessLevel.NONE)
@@ -73,10 +78,6 @@ public Double getFrequencyPenalty() {
7378
return getLlmConfigParam(FREQUENCY_PENALTY.getName());
7479
}
7580

76-
private void setFrequencyPenalty(@Nonnull final Double frequencyPenalty) {
77-
setLlmConfigParam(FREQUENCY_PENALTY.getName(), frequencyPenalty);
78-
}
79-
8081
/**
8182
* Returns the maximum number of tokens to use for the chat.
8283
*
@@ -88,10 +89,6 @@ public Integer getMaxTokens() {
8889
return getLlmConfigParam(MAX_TOKENS.getName());
8990
}
9091

91-
private void setMaxTokens(@Nonnull final Integer maxTokens) {
92-
setLlmConfigParam(MAX_TOKENS.getName(), maxTokens);
93-
}
94-
9592
/**
9693
* Returns the presence penalty to use for the chat.
9794
*
@@ -103,10 +100,6 @@ public Double getPresencePenalty() {
103100
return getLlmConfigParam(PRESENCE_PENALTY.getName());
104101
}
105102

106-
private void setPresencePenalty(@Nonnull final Double presencePenalty) {
107-
setLlmConfigParam(PRESENCE_PENALTY.getName(), presencePenalty);
108-
}
109-
110103
/**
111104
* Returns the stop sequences to use for the chat.
112105
*
@@ -118,10 +111,6 @@ public List<String> getStopSequences() {
118111
return getLlmConfigParam("stop_sequences");
119112
}
120113

121-
private void setStopSequences(@Nonnull final List<String> stopSequences) {
122-
setLlmConfigParam("stop_sequences", stopSequences);
123-
}
124-
125114
/**
126115
* Returns the temperature to use for the chat.
127116
*
@@ -133,10 +122,6 @@ public Double getTemperature() {
133122
return getLlmConfigParam(TEMPERATURE.getName());
134123
}
135124

136-
private void setTemperature(@Nonnull final Double temperature) {
137-
setLlmConfigParam(TEMPERATURE.getName(), temperature);
138-
}
139-
140125
/**
141126
* Returns the top K to use for the chat.
142127
*
@@ -148,10 +133,6 @@ public Integer getTopK() {
148133
return getLlmConfigParam("top_k");
149134
}
150135

151-
private void setTopK(@Nonnull final Integer topK) {
152-
setLlmConfigParam("top_k", topK);
153-
}
154-
155136
/**
156137
* Returns the top P to use for the chat.
157138
*
@@ -163,10 +144,6 @@ public Double getTopP() {
163144
return getLlmConfigParam(TOP_P.getName());
164145
}
165146

166-
private void setTopP(@Nonnull final Double topP) {
167-
setLlmConfigParam(TOP_P.getName(), topP);
168-
}
169-
170147
/**
171148
* Returns a copy of this {@link OrchestrationChatOptions}.
172149
*
@@ -180,41 +157,41 @@ public <T extends ChatOptions> T copy() {
180157
copy.setModel(this.getModel());
181158
copy.setModelVersion(this.getModelVersion());
182159
if (getFrequencyPenalty() != null) {
183-
copy.setFrequencyPenalty(this.getFrequencyPenalty());
160+
copy.setLlmConfigParam(FREQUENCY_PENALTY.getName(), getFrequencyPenalty());
184161
}
185162
if (getMaxTokens() != null) {
186-
copy.setMaxTokens(this.getMaxTokens());
163+
copy.setLlmConfigParam(MAX_TOKENS.getName(), getMaxTokens());
187164
}
188165
if (getPresencePenalty() != null) {
189-
copy.setPresencePenalty(this.getPresencePenalty());
166+
copy.setLlmConfigParam(PRESENCE_PENALTY.getName(), getPresencePenalty());
190167
}
191168
if (getStopSequences() != null) {
192-
copy.setStopSequences(new ArrayList<>(this.getStopSequences()));
169+
copy.setLlmConfigParam("stop_sequences", getStopSequences());
193170
}
194171
if (getTemperature() != null) {
195-
copy.setTemperature(this.getTemperature());
172+
copy.setLlmConfigParam(TEMPERATURE.getName(), getTemperature());
196173
}
197174
if (getTopK() != null) {
198-
copy.setTopK(this.getTopK());
175+
copy.setLlmConfigParam("top_k", getTopK());
199176
}
200177
if (getTopP() != null) {
201-
copy.setTopP(this.getTopP());
178+
copy.setLlmConfigParam(TOP_P.getName(), getTopP());
202179
}
203180
return (T) copy;
204181
}
205182

206183
@SuppressWarnings("unchecked")
207184
@Nullable
208185
private <T> T getLlmConfigParam(@Nonnull final String param) {
209-
if (getLlmConfigNonNull().getModelParams() instanceof LinkedHashMap) {
210-
return ((LinkedHashMap<String, T>) getLlmConfigNonNull().getModelParams()).get(param);
186+
if (getLlmConfigNonNull().getModelParams() instanceof Map) {
187+
return ((Map<String, T>) getLlmConfigNonNull().getModelParams()).get(param);
211188
}
212189
return null;
213190
}
214191

215192
@SuppressWarnings("unchecked")
216-
private <T> void setLlmConfigParam(@Nonnull final String param, @Nonnull final T value) {
217-
((LinkedHashMap<String, T>) getLlmConfigNonNull().getModelParams()).put(param, value);
193+
private void setLlmConfigParam(@Nonnull final String param, @Nonnull final Object value) {
194+
((Map<String, Object>) getLlmConfigNonNull().getModelParams()).put(param, value);
218195
}
219196

220197
@Nonnull

orchestration/src/main/java/com/sap/ai/sdk/orchestration/spring/OrchestrationChatResponse.java

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

3+
import com.google.common.annotations.Beta;
34
import com.sap.ai.sdk.orchestration.model.CompletionPostResponse;
45
import com.sap.ai.sdk.orchestration.model.LLMChoice;
56
import com.sap.ai.sdk.orchestration.model.LLMModuleResultSynchronous;
@@ -17,7 +18,12 @@
1718
import org.springframework.ai.chat.model.ChatResponse;
1819
import org.springframework.ai.chat.model.Generation;
1920

20-
/** Response from the orchestration service in a Spring AI {@link ChatResponse}. */
21+
/**
22+
* Response from the orchestration service in a Spring AI {@link ChatResponse}.
23+
*
24+
* @since 1.2.0
25+
*/
26+
@Beta
2127
@Value
2228
@EqualsAndHashCode(callSuper = true)
2329
public class OrchestrationChatResponse extends ChatResponse {

0 commit comments

Comments
 (0)