-
Notifications
You must be signed in to change notification settings - Fork 152
fix: Allow injecting ObjectMapper in FunctionTool, default to ObjectMapper (re. #473) #487
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?
Conversation
Summary of ChangesHello @vorburger, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly improves the Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
7d99d03
to
f628dc9
Compare
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.
Code Review
This pull request successfully refactors FunctionTool
to allow injecting a custom ObjectMapper
, which is a great step towards better flexibility and testability.
I've left a couple of comments on areas that could be improved for consistency and correctness:
- The
ObjectMapper
used for schema generation inFunctionCallingUtils
is still separate from the one injected intoFunctionTool
, which could lead to inconsistencies. - There's a potential bug in how
List
parameters are handled in thecallLive
method, which is different from the more robust implementation in thecall
method.
Addressing these points will make the FunctionTool
more robust, especially when dealing with custom types. Overall, this is a valuable change.
this.funcDeclaration = | ||
FunctionCallingUtils.buildFunctionDeclaration( | ||
this.func, ImmutableList.of("toolContext", "inputStream")); | ||
this.objectMapper = objectMapper; |
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.
While the runtime argument conversion now uses the injected objectMapper
, the function declaration schema is built using FunctionCallingUtils
, which has its own static, non-configurable ObjectMapper
. This can lead to inconsistencies if the injected objectMapper
has custom serializers, as the generated schema will not reflect them. This could cause mismatches between what the LLM expects and what the tool can handle at runtime. To ensure consistency, FunctionCallingUtils
should also be updated to use the same ObjectMapper
instance.
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.
TBD...
} | ||
|
||
private static List<Object> createList(List<Object> values, Class<?> type) { | ||
private List<Object> createList(List<Object> values, Class<?> type) { |
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 callLive
method, a caller of this function, has a potential bug. It obtains a java.lang.reflect.Type
and casts it directly to Class
before passing it here. This is unsafe and will cause a ClassCastException
if the type is a ParameterizedType
(e.g., for a List<Map<String, String>>
). The call
method contains the correct, more robust logic for handling this, which should be replicated in callLive
to prevent runtime errors.
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.
==> #489
Related to #473.
Intentionally just for
FunctionTool
, for now; but this should eventually really be done everywhere like this (IMHO).Alternative (and superior) to the initial #486 - but put on hold, until at least that basic version is merged (thus this is Draft).