Skip to content

Commit 3f6a7b3

Browse files
committed
Initial convenience class
1 parent f1b2d5e commit 3f6a7b3

File tree

4 files changed

+43
-8
lines changed

4 files changed

+43
-8
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig(
219219
@Nonnull
220220
public Stream<OrchestrationChatCompletionDelta> streamChatCompletionDeltas(
221221
@Nonnull final CompletionPostRequest request) throws OrchestrationClientException {
222-
request.getConfig().setStream(GlobalStreamOptions.create().enabled(true).delimiters(null));
222+
val config = request.getConfig();
223+
val stream = config.getStream();
224+
if (stream == null) {
225+
config.setStream(GlobalStreamOptions.create().enabled(true).delimiters(null));
226+
} else {
227+
stream.enabled(true);
228+
}
223229

224230
return executor.stream(COMPLETION_ENDPOINT, request, customHeaders);
225231
}

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,27 +24,32 @@ public class OrchestrationStreamConfig {
2424
* Number of characters that should be additionally sent to content filtering services from
2525
* previous chunks as additional context.
2626
*/
27-
@Nullable Integer overlap;
27+
@Nullable Integer filterOverlap;
2828

2929
/** Size of the chunks the response will be split into when streaming. */
30-
@Nullable Integer chunkSize = null;
30+
@Nullable Integer chunkSize;
3131

3232
/** List of delimiters to use for chunking the response when streaming. */
33-
@Nullable List<String> delimiters = null;
33+
@Nullable List<String> delimiters;
34+
35+
/** Default constructor for OrchestrationStreamConfig. */
36+
public OrchestrationStreamConfig() {
37+
this(null, null, null);
38+
}
3439

3540
@Nullable
3641
FilteringStreamOptions createFilteringStreamOptions() {
37-
return overlap == null ? null : FilteringStreamOptions.create().overlap(overlap);
42+
return filterOverlap == null ? null : FilteringStreamOptions.create().overlap(filterOverlap);
3843
}
3944

4045
@Nullable
4146
GlobalStreamOptions createGlobalStreamOptions() {
4247
if (chunkSize == null && delimiters == null) {
4348
return null;
4449
}
45-
val opts = GlobalStreamOptions.create();
50+
val opts = GlobalStreamOptions.create().enabled(true);
4651
Optional.ofNullable(chunkSize).ifPresent(opts::setChunkSize);
47-
Optional.ofNullable(delimiters).ifPresent(d -> opts.setDelimiters(List.copyOf(d)));
52+
opts.setDelimiters(delimiters == null ? null : List.copyOf(delimiters));
4853
return opts;
4954
}
5055
}

orchestration/src/test/java/com/sap/ai/sdk/orchestration/OrchestrationUnitTest.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,28 @@ void filteringLooseStream() throws IOException {
481481
verify(postRequestedFor(anyUrl()).withRequestBody(equalToJson(request, true, false)));
482482
}
483483

484+
@Test
485+
void convenienceConfig() {
486+
final var azureFilter = new AzureContentFilter().hate(ALLOW_SAFE_LOW_MEDIUM);
487+
488+
OrchestrationModuleConfig myConfig =
489+
config
490+
.withOutputFiltering(azureFilter)
491+
.withOutputFilteringStreamOptions(FilteringStreamOptions.create().overlap(1_000));
492+
OrchestrationModuleConfig myConfig2 =
493+
config
494+
.withOutputFiltering(azureFilter)
495+
.withStreamConfig(new OrchestrationStreamConfig().withFilterOverlap(1_000));
496+
assertThat(myConfig).isEqualTo(myConfig2);
497+
498+
OrchestrationModuleConfig myConfig3 =
499+
config
500+
.withOutputFiltering(azureFilter)
501+
.withStreamConfig(
502+
new OrchestrationStreamConfig().withFilterOverlap(1_000).withChunkSize(10));
503+
assertThat(myConfig2).isNotEqualTo(myConfig3);
504+
}
505+
484506
@Test
485507
void inputFilteringStrict() {
486508
stubFor(

orchestration/src/test/resources/filteringLooseRequestStream.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
"top_p": 1,
1313
"n": 1
1414
},
15-
"version": "latest"
15+
"version": "latest",
16+
"timeout" : 600,
17+
"max_retries" : 2
1618
},
1719
"prompt": {
1820
"template": [

0 commit comments

Comments
 (0)