11package com .sap .ai .sdk .orchestration .spring ;
22
3+ import static com .sap .ai .sdk .orchestration .ConfigToRequestTransformer .toModuleConfigs ;
34import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .FREQUENCY_PENALTY ;
45import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .MAX_TOKENS ;
56import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .PRESENCE_PENALTY ;
67import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .TEMPERATURE ;
78import static com .sap .ai .sdk .orchestration .OrchestrationAiModel .Parameter .TOP_P ;
9+ import static com .sap .ai .sdk .orchestration .OrchestrationJacksonConfiguration .getOrchestrationObjectMapper ;
810
11+ import com .fasterxml .jackson .core .JsonProcessingException ;
12+ import com .fasterxml .jackson .databind .ObjectMapper ;
913import com .google .common .annotations .Beta ;
1014import com .sap .ai .sdk .orchestration .OrchestrationModuleConfig ;
1115import com .sap .ai .sdk .orchestration .model .LLMModuleConfig ;
16+ import com .sap .ai .sdk .orchestration .model .ModuleConfigs ;
1217import java .util .List ;
1318import java .util .Map ;
1419import java .util .Objects ;
3237@ Setter (AccessLevel .NONE )
3338public class OrchestrationChatOptions implements ChatOptions {
3439
40+ private static final ObjectMapper JACKSON = getOrchestrationObjectMapper ();
41+
3542 @ Getter (AccessLevel .PUBLIC )
3643 @ Setter (AccessLevel .PUBLIC )
3744 @ Nonnull
@@ -49,10 +56,6 @@ public String getModel() {
4956 return getLlmConfigNonNull ().getModelName ();
5057 }
5158
52- private void setModel (@ Nonnull final String model ) {
53- getLlmConfigNonNull ().setModelName (model );
54- }
55-
5659 /**
5760 * Returns the model version to use for the chat. "latest" by default.
5861 *
@@ -63,10 +66,6 @@ public String getModelVersion() {
6366 return getLlmConfigNonNull ().getModelVersion ();
6467 }
6568
66- private void setModelVersion (@ Nonnull final String modelVersion ) {
67- getLlmConfigNonNull ().setModelVersion (modelVersion );
68- }
69-
7069 /**
7170 * Returns the frequency penalty to use for the chat.
7271 *
@@ -153,22 +152,24 @@ public Double getTopP() {
153152 @ Nonnull
154153 @ Override
155154 public <T extends ChatOptions > T copy () {
156- val copy = new OrchestrationChatOptions (config );
157-
158- copy .setModel (this .getModel ());
159- copy .setModelVersion (this .getModelVersion ());
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-
168- return (T ) copy ;
155+ try {
156+ val json = JACKSON .writeValueAsString (toModuleConfigs (config ));
157+ val copy = JACKSON .readValue (json , ModuleConfigs .class );
158+ val copyConfig =
159+ new OrchestrationModuleConfig ()
160+ .withTemplateConfig (copy .getTemplatingModuleConfig ())
161+ .withFilteringConfig (copy .getFilteringModuleConfig ())
162+ .withLlmConfig (copy .getLlmModuleConfig ())
163+ .withMaskingConfig (copy .getMaskingModuleConfig ())
164+ .withGroundingConfig (copy .getGroundingModuleConfig ());
165+ return (T ) new OrchestrationChatOptions (copyConfig );
166+
167+ } catch (JsonProcessingException e ) {
168+ throw new RuntimeException (e );
169+ }
169170 }
170171
171- @ SuppressWarnings ("unchecked" )
172+ @ SuppressWarnings ("unchecked" ) // getModelParams() returns Object, it should return Map
172173 @ Nullable
173174 private <T > T getLlmConfigParam (@ Nonnull final String param ) {
174175 if (getLlmConfigNonNull ().getModelParams () instanceof Map ) {
@@ -177,16 +178,6 @@ private <T> T getLlmConfigParam(@Nonnull final String param) {
177178 return null ;
178179 }
179180
180- @ SuppressWarnings ("unchecked" )
181- private void setLlmConfigParam (
182- @ Nonnull final OrchestrationChatOptions copy ,
183- @ Nonnull final String param ,
184- @ Nullable final Object value ) {
185- if (value != null ) {
186- ((Map <String , Object >) copy .getLlmConfigNonNull ().getModelParams ()).put (param , value );
187- }
188- }
189-
190181 @ Nonnull
191182 private LLMModuleConfig getLlmConfigNonNull () {
192183 return Objects .requireNonNull (
0 commit comments