Skip to content

Commit efe05e1

Browse files
Shorter
1 parent bc0f64a commit efe05e1

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

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

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -154,29 +154,17 @@ public Double getTopP() {
154154
@Override
155155
public <T extends ChatOptions> T copy() {
156156
val copy = new OrchestrationChatOptions(config);
157+
157158
copy.setModel(this.getModel());
158159
copy.setModelVersion(this.getModelVersion());
159-
if (getFrequencyPenalty() != null) {
160-
copy.setLlmConfigParam(FREQUENCY_PENALTY.getName(), getFrequencyPenalty());
161-
}
162-
if (getMaxTokens() != null) {
163-
copy.setLlmConfigParam(MAX_TOKENS.getName(), getMaxTokens());
164-
}
165-
if (getPresencePenalty() != null) {
166-
copy.setLlmConfigParam(PRESENCE_PENALTY.getName(), getPresencePenalty());
167-
}
168-
if (getStopSequences() != null) {
169-
copy.setLlmConfigParam("stop_sequences", getStopSequences());
170-
}
171-
if (getTemperature() != null) {
172-
copy.setLlmConfigParam(TEMPERATURE.getName(), getTemperature());
173-
}
174-
if (getTopK() != null) {
175-
copy.setLlmConfigParam("top_k", getTopK());
176-
}
177-
if (getTopP() != null) {
178-
copy.setLlmConfigParam(TOP_P.getName(), getTopP());
179-
}
160+
setLlmConfigParam(copy, FREQUENCY_PENALTY.getName(), getFrequencyPenalty());
161+
setLlmConfigParam(copy, MAX_TOKENS.getName(), getMaxTokens());
162+
setLlmConfigParam(copy, PRESENCE_PENALTY.getName(), getPresencePenalty());
163+
setLlmConfigParam(copy, "stop_sequences", getStopSequences());
164+
setLlmConfigParam(copy, TEMPERATURE.getName(), getTemperature());
165+
setLlmConfigParam(copy, "top_k", getTopK());
166+
setLlmConfigParam(copy, TOP_P.getName(), getTopP());
167+
180168
return (T) copy;
181169
}
182170

@@ -190,8 +178,10 @@ private <T> T getLlmConfigParam(@Nonnull final String param) {
190178
}
191179

192180
@SuppressWarnings("unchecked")
193-
private void setLlmConfigParam(@Nonnull final String param, @Nonnull final Object value) {
194-
((Map<String, Object>) getLlmConfigNonNull().getModelParams()).put(param, value);
181+
private void setLlmConfigParam(OrchestrationChatOptions copy, String param, Object value) {
182+
if (value != null) {
183+
((Map<String, Object>) copy.getLlmConfigNonNull().getModelParams()).put(param, value);
184+
}
195185
}
196186

197187
@Nonnull

0 commit comments

Comments
 (0)