-
Notifications
You must be signed in to change notification settings - Fork 21
feat: [Orchestration] reasoning content #939
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
n-o-u-r-h-a-n
wants to merge
10
commits into
main
Choose a base branch
from
reasoning-content
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
10 commits
Select commit
Hold shift + click to select a range
a1e9160
full implementation
n-o-u-r-h-a-n 6390559
Merge branch 'main' into reasoning-content
n-o-u-r-h-a-n 8c74197
adding ReasoningItem convenience record and changing files accordingly.
n-o-u-r-h-a-n d0385d9
Merge branch 'main' into reasoning-content
n-o-u-r-h-a-n f2201da
removing redundant getters
n-o-u-r-h-a-n 3c2c626
Merge remote-tracking branch 'origin/reasoning-content' into reasonin…
n-o-u-r-h-a-n e85d7a0
returning string - not exposing signature
n-o-u-r-h-a-n 0204cbe
Merge branch 'main' into reasoning-content
n-o-u-r-h-a-n cafb667
removing public API streamReasoning from OrchestrationClient.java
n-o-u-r-h-a-n aba4b03
Merge remote-tracking branch 'origin/reasoning-content' into reasonin…
n-o-u-r-h-a-n 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 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
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
56 changes: 56 additions & 0 deletions
56
orchestration/src/main/java/com/sap/ai/sdk/orchestration/ReasoningAccumulator.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,56 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| import com.sap.ai.sdk.orchestration.model.ReasoningBlock; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Accumulates reasoning ({@code reasoning_content}) text across the chunks of a streaming | ||
| * orchestration response, merging the pieces of each block by their position. | ||
| * | ||
| * @see <a href="https://help.sap.com/docs/sap-ai-core/generative-ai/reasoning">SAP AI Core: | ||
| * Orchestration - Reasoning</a> | ||
| */ | ||
| public class ReasoningAccumulator { | ||
|
|
||
| private final List<StringBuilder> contentByIndex = new ArrayList<>(); | ||
|
|
||
| /** | ||
| * Consume the reasoning content carried by a single stream chunk. | ||
| * | ||
| * @param delta the streaming delta. | ||
| */ | ||
| public void accept(@Nonnull final OrchestrationChatCompletionDelta delta) { | ||
| final List<ReasoningBlock> chunk = rawReasoning(delta); | ||
| for (int i = 0; i < chunk.size(); i++) { | ||
| while (contentByIndex.size() <= i) { | ||
| contentByIndex.add(new StringBuilder()); | ||
| } | ||
| final String content = chunk.get(i).getContent(); | ||
| if (!content.isEmpty()) { | ||
| contentByIndex.get(i).append(content); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Assemble the fully accumulated reasoning text, one entry per reasoning block. | ||
| * | ||
| * @return the assembled reasoning text, in the order it appeared in the stream. | ||
| */ | ||
| @Nonnull | ||
| public List<String> assemble() { | ||
| return contentByIndex.stream().map(StringBuilder::toString).toList(); | ||
| } | ||
|
|
||
| @Nonnull | ||
| private static List<ReasoningBlock> rawReasoning( | ||
| @Nonnull final OrchestrationChatCompletionDelta delta) { | ||
| final var choices = delta.getFinalResult().getChoices(); | ||
| if (!choices.isEmpty() && choices.get(0).getIndex() == 0) { | ||
| return choices.get(0).getDelta().getReasoningContent(); | ||
| } | ||
| return List.of(); | ||
| } | ||
| } |
41 changes: 41 additions & 0 deletions
41
orchestration/src/main/java/com/sap/ai/sdk/orchestration/ReasoningEffort.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,41 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| import javax.annotation.Nonnull; | ||
|
|
||
| /** | ||
| * Reasoning effort levels for the harmonized {@code reasoning_effort} model parameter. | ||
| * | ||
| * <p>Not all reasoning-capable models support the full range of values. Where a model does not | ||
| * support a given effort, orchestration transparently maps it to the closest equivalent. | ||
| * | ||
| * @see <a href="https://help.sap.com/docs/sap-ai-core/generative-ai/reasoning">SAP AI Core: | ||
| * Orchestration - Reasoning</a> | ||
| */ | ||
| public enum ReasoningEffort { | ||
| /** Minimal reasoning effort. */ | ||
| MINIMAL("minimal"), | ||
| /** Low reasoning effort. */ | ||
| LOW("low"), | ||
| /** Medium reasoning effort. */ | ||
| MEDIUM("medium"), | ||
| /** High reasoning effort. */ | ||
| HIGH("high"), | ||
| /** Disable reasoning when the model supports doing so. */ | ||
| NONE("none"); | ||
|
|
||
| private final String value; | ||
|
|
||
| ReasoningEffort(@Nonnull final String value) { | ||
| this.value = value; | ||
| } | ||
|
|
||
| /** | ||
| * Wire string sent as the value of the {@code reasoning_effort} model parameter. | ||
| * | ||
| * @return the wire value. | ||
| */ | ||
| @Nonnull | ||
| public String getValue() { | ||
| return value; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.