generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 15
feat: Spring AI🍃Tool Calling #320
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
Merged
The head ref may contain hidden characters: "spring-ai\u{1F343}tools"
Merged
Changes from all commits
Commits
Show all changes
43 commits
Select commit
Hold shift + click to select a range
11131f7
Spring AI functions
CharlesDuboisSAP 2ee2f1e
Merge branch 'main' into spring-ai🍃tools
CharlesDuboisSAP 214c93e
Test function callback
CharlesDuboisSAP c683e6c
Remove test
CharlesDuboisSAP 8b4b3a4
Merge branch 'refs/heads/main' into spring-ai🍃tools
CharlesDuboisSAP 94c42d4
First tool call
CharlesDuboisSAP 7b56d90
Best effort
CharlesDuboisSAP 90764de
TODO
CharlesDuboisSAP 4ca4a36
Formatting
bot-sdk-js eb8bc27
Fix test
CharlesDuboisSAP f5ad10b
Removed TODO
CharlesDuboisSAP 10826e0
Checkstyle
CharlesDuboisSAP 9cfc138
lombok
CharlesDuboisSAP 3b97b98
List of tool calls supported
CharlesDuboisSAP d9ab6f0
Unit test wip
CharlesDuboisSAP 2979bb0
Unit test almost
CharlesDuboisSAP 83491e4
Unit test finished
CharlesDuboisSAP 7d1ba19
Green
CharlesDuboisSAP ee3543e
Formatting
bot-sdk-js 7a9c30f
Green
CharlesDuboisSAP bb616a9
Merge remote-tracking branch 'origin/spring-ai🍃tools' into spring-ai🍃…
CharlesDuboisSAP c71ac25
new ToolCall class
CharlesDuboisSAP 93c5ae5
Added documentation and release notes
CharlesDuboisSAP 9e607f3
Replaced ToolCall class with existing ResponseMessageToolCall
CharlesDuboisSAP 804caf6
Merge branch 'main' into spring-ai🍃tools
CharlesDuboisSAP 8e61635
Tool call wip
CharlesDuboisSAP 8736660
Spring AI 1.0.0-M6
CharlesDuboisSAP 51ca4ec
Merge branch 'main' into spring-ai🍃tools
CharlesDuboisSAP 7f84ab8
Reduced options class size
CharlesDuboisSAP f6c7de0
Added tests
CharlesDuboisSAP 614a017
Updated release notes
CharlesDuboisSAP 9d8b240
Replaced FunctionCallbacks with ToolCallbacks
CharlesDuboisSAP 0af197c
Merge branch 'main' into spring-ai🍃tools
CharlesDuboisSAP 4e39550
Updated docs
CharlesDuboisSAP 0e23fbe
Updated docs
CharlesDuboisSAP 91ba977
Removed useless code
CharlesDuboisSAP b970740
Removed whitespace
CharlesDuboisSAP 9a34cd0
Added deprecation notice
CharlesDuboisSAP be45cd3
Update orchestration/src/main/java/com/sap/ai/sdk/orchestration/sprin…
CharlesDuboisSAP 7bafe92
composition for toolCallingManager
CharlesDuboisSAP f382f10
since 1.4.0
CharlesDuboisSAP 35fc5c5
dependencies
CharlesDuboisSAP de64374
make fields final again
a-d 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,20 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| import com.google.common.annotations.Beta; | ||
| import com.sap.ai.sdk.orchestration.model.ChatMessage; | ||
| import com.sap.ai.sdk.orchestration.model.ResponseMessageToolCall; | ||
| import com.sap.ai.sdk.orchestration.model.SingleChatMessage; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
| import javax.annotation.Nullable; | ||
| import lombok.Getter; | ||
| import lombok.Value; | ||
| import lombok.experimental.Accessors; | ||
| import lombok.val; | ||
|
|
||
| /** Represents a chat message as 'assistant' to the orchestration service. */ | ||
| @Value | ||
| @Getter | ||
| @Accessors(fluent = true) | ||
| public class AssistantMessage implements Message { | ||
|
|
||
|
|
@@ -20,12 +26,38 @@ public class AssistantMessage implements Message { | |
| @Getter(onMethod_ = @Beta) | ||
| MessageContent content; | ||
|
|
||
| /** Tool call if there is any. */ | ||
| @Nullable List<ResponseMessageToolCall> toolCalls; | ||
|
|
||
| /** | ||
| * Creates a new assistant message with the given single message. | ||
| * | ||
| * @param singleMessage the single message. | ||
| */ | ||
| public AssistantMessage(@Nonnull final String singleMessage) { | ||
| content = new MessageContent(List.of(new TextItem(singleMessage))); | ||
| toolCalls = null; | ||
| } | ||
|
|
||
| /** | ||
| * Creates a new assistant message with the given tool calls. | ||
| * | ||
| * @param toolCalls list of tool call objects | ||
| */ | ||
| public AssistantMessage(@Nonnull final List<ResponseMessageToolCall> toolCalls) { | ||
| content = new MessageContent(List.of()); | ||
| this.toolCalls = toolCalls; | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public ChatMessage createChatMessage() { | ||
| if (toolCalls() != null) { | ||
| // content shouldn't be required for tool calls 🤷 | ||
|
Contributor
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. (Minor) Please remove emoji |
||
| val message = SingleChatMessage.create().role(role).content(""); | ||
| message.setCustomField("tool_calls", toolCalls); | ||
| return message; | ||
| } | ||
| return Message.super.createChatMessage(); | ||
| } | ||
| } | ||
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
39 changes: 39 additions & 0 deletions
39
orchestration/src/main/java/com/sap/ai/sdk/orchestration/ToolMessage.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,39 @@ | ||
| package com.sap.ai.sdk.orchestration; | ||
|
|
||
| import com.sap.ai.sdk.orchestration.model.ChatMessage; | ||
| import com.sap.ai.sdk.orchestration.model.SingleChatMessage; | ||
| import java.util.List; | ||
| import javax.annotation.Nonnull; | ||
| import lombok.Value; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| /** | ||
| * Represents a chat message as 'tool' to the orchestration service. | ||
| * | ||
| * @since 1.4.0 | ||
| */ | ||
| @Value | ||
| @Accessors(fluent = true) | ||
| public class ToolMessage implements Message { | ||
CharlesDuboisSAP marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** The role of the assistant. */ | ||
| @Nonnull String role = "tool"; | ||
|
|
||
| @Nonnull String id; | ||
|
|
||
| @Nonnull String content; | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public MessageContent content() { | ||
| return new MessageContent(List.of(new TextItem(content))); | ||
| } | ||
|
|
||
| @Nonnull | ||
| @Override | ||
| public ChatMessage createChatMessage() { | ||
| final SingleChatMessage message = SingleChatMessage.create().role(role()).content(content); | ||
| message.setCustomField("tool_call_id", id); | ||
| return message; | ||
| } | ||
| } | ||
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
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.
Uh oh!
There was an error while loading. Please reload this page.