-
Notifications
You must be signed in to change notification settings - Fork 1.4k
fix:toolcall return string #2885
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
base: main
Are you sure you want to change the base?
fix:toolcall return string #2885
Conversation
Signed-off-by: Cui-xf <cui_xf293@qq.com>
@@ -58,6 +58,10 @@ public String convert(@Nullable Object result, @Nullable Type returnType) { | |||
final var imgB64 = Base64.getEncoder().encodeToString(buf.toByteArray()); | |||
return JsonParser.toJson(Map.of("mimeType", "image/png", "data", imgB64)); | |||
} | |||
else if (result instanceof String stringResult) { |
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.
the current assumption is that if is not a rendered image, we assume it is json (also a string) in this current PR, the json conversion in the else statement will never be accessed. Can you explain more of the surrounding use case that motivated you to make this change? adding to DefaultToolCallResultConverterTests
?
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.
Also wondering why JsonParser.toJson(result);
doesn't use Type returnType
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.
any thoughts @tzolov ?
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.
the current assumption is that if is not a rendered image, we assume it is json (also a string) in this current PR, the json conversion in the else statement will never be accessed. Can you explain more of the surrounding use case that motivated you to make this change? adding to
DefaultToolCallResultConverterTests
?
Hey, thanks for the review!
I noticed that when I use the org.springframework.ai.tool.annotation.Tool annotation and the method returns a String, the result gets escaped (see screenshot below). I’m not really sure if this is the expected behavior, or if there’s any doc about it.
If this is actually, I will to close the PR.
Thanks!


Signed-off-by: Cui-xf cui_xf293@qq.com
Thank you for taking time to contribute this pull request!
You might have already read the [contributor guide][1], but as a reminder, please make sure to:
main
branch and squash your commits