Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

### ✨ New Functionality

-
- [Orchestration] For streaming, add convenience configuration AOU for output-filter-overlap, chunk-size, and delimiters via `OrchestrationModuleConfig#withStreamConfig`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is AOU? Those release notes are not clear.


### 📈 Improvements

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ static CompletionPostRequest toCompletionPostRequest(

val moduleConfigs = toModuleConfigs(configCopy);

val reqConfig =
OrchestrationConfig.create().modules(moduleConfigs).stream(config.getGlobalStreamOptions());

return CompletionPostRequest.create()
.config(OrchestrationConfig.create().modules(moduleConfigs))
.config(reqConfig)
.placeholderValues(prompt.getTemplateParameters())
.messagesHistory(messageHistory);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,13 @@ public OrchestrationChatResponse executeRequestFromJsonModuleConfig(
@Nonnull
public Stream<OrchestrationChatCompletionDelta> streamChatCompletionDeltas(
@Nonnull final CompletionPostRequest request) throws OrchestrationClientException {
request.getConfig().setStream(GlobalStreamOptions.create().enabled(true).delimiters(null));
val config = request.getConfig();
val stream = config.getStream();
if (stream == null) {
config.setStream(GlobalStreamOptions.create().enabled(true).delimiters(null));
} else {
stream.enabled(true);
}

return executor.stream(COMPLETION_ENDPOINT, request, customHeaders);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.google.common.annotations.Beta;
import com.sap.ai.sdk.orchestration.model.FilteringModuleConfig;
import com.sap.ai.sdk.orchestration.model.FilteringStreamOptions;
import com.sap.ai.sdk.orchestration.model.GlobalStreamOptions;
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig;
import com.sap.ai.sdk.orchestration.model.InputFilteringConfig;
import com.sap.ai.sdk.orchestration.model.LLMModelDetails;
Expand All @@ -17,6 +19,7 @@
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Value;
import lombok.With;
Expand Down Expand Up @@ -100,6 +103,18 @@ public class OrchestrationModuleConfig {

@Nullable SAPDocumentTranslation outputTranslationConfig;

/** Configuration of optional streaming options for output filtering. */
@With(AccessLevel.NONE) // may be exposed to public in the future
@Getter(AccessLevel.PACKAGE)
@Nullable
FilteringStreamOptions outputFilteringStreamOptions;

/** Configuration of optional streaming options for output filtering. */
@With(AccessLevel.PRIVATE) // may be exposed to public in the future
@Getter(AccessLevel.PACKAGE)
@Nullable
GlobalStreamOptions globalStreamOptions;
Comment on lines +112 to +116
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong Javadoc? It is the same as the param above


/**
* Creates a new configuration with the given LLM configuration.
*
Expand All @@ -115,6 +130,19 @@ public OrchestrationModuleConfig withLlmConfig(@Nonnull final OrchestrationAiMod
return withLlmConfig(aiModel.createConfig());
}

/**
* Creates a new configuration with the given stream configuration.
*
* @param config The stream configuration to use.
* @return A new configuration with the given stream configuration.
*/
@Nonnull
public OrchestrationModuleConfig withStreamConfig(
@Nonnull final OrchestrationStreamConfig config) {
return this.withOutputFilteringStreamOptions(config.createFilteringStreamOptions())
.withGlobalStreamOptions(config.createGlobalStreamOptions());
}

/**
* Creates a new configuration with the given Data Masking configuration.
*
Expand Down Expand Up @@ -203,7 +231,10 @@ public OrchestrationModuleConfig withOutputFiltering(
.map(ContentFilter::createOutputFilterConfig)
.toList();

final var outputFilter = OutputFilteringConfig.create().filters(filterConfigs);
final var outputFilter =
OutputFilteringConfig.create()
.filters(filterConfigs)
.streamOptions(outputFilteringStreamOptions);

final var newFilteringConfig =
FilteringModuleConfig.create()
Expand All @@ -213,6 +244,33 @@ public OrchestrationModuleConfig withOutputFiltering(
return this.withFilteringConfig(newFilteringConfig);
}

/**
* Creates a new configuration with the given output filtering stream options.
*
* @see <a
* href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/streaming">Orchestration
* documentation on streaming.</a>
* @param outputFilteringStreamOptions The output filtering stream options to use.
* @return A new configuration with the given output filtering stream options.
*/
@Nonnull
OrchestrationModuleConfig withOutputFilteringStreamOptions(
@Nullable final FilteringStreamOptions outputFilteringStreamOptions) {
if (filteringConfig != null && filteringConfig.getOutput() != null) {
filteringConfig.getOutput().setStreamOptions(outputFilteringStreamOptions);
}
return new OrchestrationModuleConfig(
this.llmConfig,
this.templateConfig,
this.maskingConfig,
this.filteringConfig,
this.groundingConfig,
this.inputTranslationConfig,
this.outputTranslationConfig,
outputFilteringStreamOptions,
this.globalStreamOptions);
}

/**
* Creates a new configuration with the given grounding configuration.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.sap.ai.sdk.orchestration;

import com.sap.ai.sdk.orchestration.model.FilteringStreamOptions;
import com.sap.ai.sdk.orchestration.model.GlobalStreamOptions;
import java.util.List;
import java.util.Optional;
import javax.annotation.Nullable;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Value;
import lombok.With;
import lombok.val;

/**
* Configuration for orchestration streaming options.
*
* @since 1.12.0
*/
@Value
@With
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class OrchestrationStreamConfig {
/**
* Number of characters that should be additionally sent to content filtering services from
* previous chunks as additional context.
*/
@Nullable Integer filterOverlap;

/** Size of the chunks the response will be split into when streaming. */
@Nullable Integer chunkSize;

/** List of delimiters to use for chunking the response when streaming. */
@Nullable List<String> delimiters;

/** Default constructor for OrchestrationStreamConfig. */
public OrchestrationStreamConfig() {
this(null, null, null);
}

@Nullable
FilteringStreamOptions createFilteringStreamOptions() {
return filterOverlap == null ? null : FilteringStreamOptions.create().overlap(filterOverlap);
}

@Nullable
GlobalStreamOptions createGlobalStreamOptions() {
if (chunkSize == null && delimiters == null) {
return null;
}
val opts = GlobalStreamOptions.create();
Optional.ofNullable(chunkSize).ifPresent(opts::setChunkSize);
opts.setDelimiters(delimiters == null ? null : List.copyOf(delimiters));
return opts;
}
}
Loading
Loading