generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: [Orchestration] Allow for streaming configuration convenience API #561
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
newtork
wants to merge
11
commits into
main
Choose a base branch
from
orchestration/output-filter-streaming-options
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
9546f8f
Initial
newtork 220af51
Add test
newtork c7d29dc
Add release note
newtork ea27ee0
Add external link to javadoc
newtork c1cdb3c
Merge remote-tracking branch 'origin/main' into orchestration/output-…
newtork cc5932a
Fix PMD
newtork 2d5c359
Merge remote-tracking branch 'origin/main' into orchestration/output-…
newtork f1b2d5e
Initial convenience class
newtork 3f6a7b3
Initial convenience class
newtork f5f376f
Disable default stream
newtork 2dcbd3b
Update release note
newtork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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; | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. | ||
* | ||
|
@@ -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. | ||
* | ||
|
@@ -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() | ||
|
@@ -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. | ||
* | ||
|
55 changes: 55 additions & 0 deletions
55
orchestration/src/main/java/com/sap/ai/sdk/orchestration/OrchestrationStreamConfig.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.