88import com .fasterxml .jackson .core .JsonProcessingException ;
99import com .fasterxml .jackson .databind .ObjectMapper ;
1010import com .fasterxml .jackson .datatype .jsr310 .JavaTimeModule ;
11+ import com .sap .ai .sdk .core .AiCoreDeployment ;
1112import com .sap .ai .sdk .core .AiCoreService ;
1213import com .sap .ai .sdk .orchestration .client .model .CompletionPostRequest ;
1314import com .sap .ai .sdk .orchestration .client .model .CompletionPostResponse ;
1819import io .vavr .NotImplementedError ;
1920import java .io .IOException ;
2021import java .util .NoSuchElementException ;
22+ import java .util .function .Supplier ;
2123import java .util .stream .Stream ;
2224import javax .annotation .Nonnull ;
23- import lombok .RequiredArgsConstructor ;
2425import lombok .experimental .Delegate ;
2526import lombok .extern .slf4j .Slf4j ;
2627import lombok .val ;
3637 * OrchestrationPrompt} will take precedence upon execution.
3738 */
3839@ Slf4j
39- @ RequiredArgsConstructor
4040public class OrchestrationClient implements OrchestrationConfig <OrchestrationClient > {
4141 static final ObjectMapper JACKSON ;
4242
@@ -55,13 +55,23 @@ public class OrchestrationClient implements OrchestrationConfig<OrchestrationCli
5555 private final DefaultOrchestrationConfig <OrchestrationClient > clientConfig =
5656 DefaultOrchestrationConfig .asDelegateFor (this );
5757
58- @ Nonnull private final AiCoreService service ;
58+ @ Nonnull private final Supplier < AiCoreDeployment > deployment ;
5959
6060 private interface IDelegate extends OrchestrationConfig <OrchestrationClient > {}
6161
6262 /** Default constructor. */
6363 public OrchestrationClient () {
64- service = new AiCoreService ();
64+ deployment = () -> new AiCoreService ().forDeploymentByScenario ("orchestration" );
65+ }
66+
67+ /**
68+ * Constructor with a custom deployment, allowing for a custom resource group or otherwise
69+ * specific deployment ID.
70+ *
71+ * @param deployment The specific {@link AiCoreDeployment} to use.
72+ */
73+ public OrchestrationClient (@ Nonnull final AiCoreDeployment deployment ) {
74+ this .deployment = () -> deployment ;
6575 }
6676
6777 /**
@@ -149,12 +159,14 @@ public Stream<String> streamChatCompletionDelta(@Nonnull final OrchestrationProm
149159 * }
150160 * }</pre>
151161 *
162+ * <p>Alternatively, you can call this method directly with a fully custom request object.
163+ *
152164 * @param request The request DTO to send to orchestration.
153165 * @return The response DTO from orchestration.
154166 * @throws OrchestrationClientException If the request fails.
155167 */
156168 @ Nonnull
157- protected CompletionPostResponse executeRequest (@ Nonnull final CompletionPostRequest request )
169+ public CompletionPostResponse executeRequest (@ Nonnull final CompletionPostRequest request )
158170 throws OrchestrationClientException {
159171 final BasicClassicHttpRequest postRequest = new HttpPost ("/completion" );
160172 try {
@@ -172,7 +184,7 @@ protected CompletionPostResponse executeRequest(@Nonnull final CompletionPostReq
172184 @ Nonnull
173185 CompletionPostResponse executeRequest (@ Nonnull final BasicClassicHttpRequest request ) {
174186 try {
175- val destination = service . forDeploymentByScenario ( "orchestration" ).destination ();
187+ val destination = deployment . get ( ).destination ();
176188 log .debug ("Using destination {} to connect to orchestration service" , destination );
177189 val client = ApacheHttpClient5Accessor .getHttpClient (destination );
178190 return client .execute (
0 commit comments