generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 8
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
feat: Orchestration Grounding convenience #293
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
986924e
Orchestration Grounding convenience
CharlesDuboisSAP 50f0f45
Added docs and release notes
CharlesDuboisSAP ec28d01
Removed someId
CharlesDuboisSAP e0cd777
Alex likes functional interfaces
CharlesDuboisSAP 078df19
final
CharlesDuboisSAP 2b090de
final
CharlesDuboisSAP d594557
less params
CharlesDuboisSAP beaeeff
link
CharlesDuboisSAP ecfb112
fix tests
CharlesDuboisSAP 7b839a6
Merge branch 'main' into grounding
CharlesDuboisSAP d27b9e0
Added better filters API
CharlesDuboisSAP 8ab0ddd
Apply suggestions from code review
CharlesDuboisSAP d072452
Better api usage in service
CharlesDuboisSAP 8ca2f66
Alex's comment
CharlesDuboisSAP 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
There are no files selected for viewing
This file contains 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 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
93 changes: 93 additions & 0 deletions
93
orchestration/src/main/java/com/sap/ai/sdk/orchestration/Grounding.java
This file contains 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,93 @@ | ||
package com.sap.ai.sdk.orchestration; | ||
|
||
import com.google.common.annotations.Beta; | ||
import com.sap.ai.sdk.orchestration.model.DataRepositoryType; | ||
import com.sap.ai.sdk.orchestration.model.DocumentGroundingFilter; | ||
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig; | ||
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig.TypeEnum; | ||
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfig; | ||
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfigConfigFiltersInner; | ||
import java.util.List; | ||
import java.util.Map; | ||
import javax.annotation.Nonnull; | ||
import lombok.Setter; | ||
import lombok.experimental.Accessors; | ||
import lombok.val; | ||
|
||
/** | ||
* Grounding integrates external, contextually relevant, domain-specific, or real-time data into AI | ||
* processes. This data supplements the natural language processing capabilities of pre-trained | ||
* models, which are trained on general material. | ||
* | ||
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP AI | ||
* Core: Orchestration - Grounding</a> | ||
*/ | ||
@Beta | ||
@Accessors(fluent = true) | ||
public class Grounding implements GroundingProvider { | ||
|
||
@Nonnull | ||
private List<GroundingModuleConfigConfigFiltersInner> filters = | ||
List.of( | ||
DocumentGroundingFilter.create().id("").dataRepositoryType(DataRepositoryType.VECTOR)); | ||
|
||
@Setter(onMethod_ = {@Nonnull}) | ||
private TypeEnum documentGroundingService = TypeEnum.DOCUMENT_GROUNDING_SERVICE; | ||
|
||
/** | ||
* Create a new default grounding provider. | ||
* | ||
* <p>It is by default a document grounding service with a vector data repository. | ||
* | ||
* @return The grounding provider. | ||
*/ | ||
@Nonnull | ||
public static Grounding create() { | ||
return new Grounding(); | ||
} | ||
|
||
/** | ||
* Set filters for grounding. | ||
* | ||
* @param filters List of filters to set. | ||
* @return The modified grounding configuration. | ||
*/ | ||
@Nonnull | ||
public Grounding filters(@Nonnull final GroundingModuleConfigConfigFiltersInner... filters) { | ||
if (filters.length != 0) { | ||
this.filters = List.of(filters); | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Create a prompt with grounding parameters included in the message. | ||
* | ||
* <p>It uses the inputParams {@code userMessage} for the user message and {@code | ||
* groundingContext} for the grounding context. | ||
* | ||
* @param message The user message. | ||
* @return The prompt with grounding. | ||
*/ | ||
@Nonnull | ||
public OrchestrationPrompt createGroundingPrompt(@Nonnull final String message) { | ||
return new OrchestrationPrompt( | ||
Map.of("userMessage", message), | ||
Message.user( | ||
"{{?userMessage}} Use the following information as additional context: {{?groundingContext}}")); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public GroundingModuleConfig createConfig() { | ||
val groundingConfigConfig = | ||
GroundingModuleConfigConfig.create() | ||
.inputParams(List.of("userMessage")) | ||
.outputParam("groundingContext") | ||
.filters(filters); | ||
|
||
return GroundingModuleConfig.create() | ||
.type(documentGroundingService) | ||
.config(groundingConfigConfig); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
orchestration/src/main/java/com/sap/ai/sdk/orchestration/GroundingProvider.java
This file contains 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,22 @@ | ||
package com.sap.ai.sdk.orchestration; | ||
|
||
import com.sap.ai.sdk.orchestration.model.GroundingModuleConfig; | ||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Interface for grounding configurations. | ||
* | ||
* @link <a href="https://help.sap.com/docs/sap-ai-core/sap-ai-core-service-guide/grounding">SAP AI | ||
* Core: Orchestration - Grounding</a> | ||
*/ | ||
@FunctionalInterface | ||
public interface GroundingProvider { | ||
CharlesDuboisSAP marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Create a grounding configuration. | ||
* | ||
* @return the grounding configuration | ||
*/ | ||
@Nonnull | ||
GroundingModuleConfig createConfig(); | ||
} |
This file contains 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 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 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
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.
(Minor/Comment)
According to spec this identifier shall be unique per request.
Multiple filters are possible per requset.
See spec
With the proposed convenience API we are
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.
Therefore:
Would allow for setting multiple
filter
onGrounding
then for1..*
?Or will you keep the cardinality
1
?Is
0
filters an option we have to consider?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.
I modified the API to allow 1+ filters.
0 filters is not allowed because we have to specify the repository type