-
Notifications
You must be signed in to change notification settings - Fork 276
New GoogleMapsTool tool to ground responses based on location
#534
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
Conversation
Summary of ChangesHello @glaforge, 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 introduces a significant enhancement by adding a 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
|
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 introduces a new GoogleMapsTool. My review focuses on improving the implementation of processLlmRequest for better safety and efficiency by handling an unsafe Optional access and reducing redundant object builds. I've also corrected an inaccurate code example in the Javadoc to ensure it reflects the correct API usage.
|
|
||
| GenerateContentConfig.Builder configBuilder = | ||
| llmRequestBuilder | ||
| .build() | ||
| .config() | ||
| .map(GenerateContentConfig::toBuilder) | ||
| .orElse(GenerateContentConfig.builder()); | ||
|
|
||
| List<Tool> existingTools = configBuilder.build().tools().orElse(ImmutableList.of()); | ||
| ImmutableList.Builder<Tool> updatedToolsBuilder = ImmutableList.builder(); | ||
| updatedToolsBuilder.addAll(existingTools); | ||
|
|
||
| String model = llmRequestBuilder.build().model().get(); | ||
| if (model != null && !model.startsWith("gemini-1")) { | ||
| updatedToolsBuilder.add(Tool.builder().googleMaps(GoogleMaps.builder().build()).build()); | ||
| configBuilder.tools(updatedToolsBuilder.build()); | ||
| } else { | ||
| return Completable.error( | ||
| new IllegalArgumentException("Google Maps tool is not supported for model " + model)); | ||
| } | ||
|
|
||
| llmRequestBuilder.config(configBuilder.build()); | ||
| return Completable.complete(); |
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 implementation of processLlmRequest can be improved for safety, efficiency, and readability.
- Unsafe
Optional.get(): On line 69,llmRequestBuilder.build().model().get()is unsafe and will throw aNoSuchElementExceptionif the model is not set in the request. It's better to useorElse(null)and handle the null case. - Inefficient
build()calls:llmRequestBuilder.build()is called multiple times (lines 60, 69). This is inefficient. The request should be built once and stored in a local variable. - Verbose logic: The logic for updating the tools list can be simplified to be more concise and readable.
Here is a suggested refactoring that addresses these points by replacing the method body:
LlmRequest llmRequest = llmRequestBuilder.build();
String model = llmRequest.model().orElse(null);
if (model == null || model.startsWith("gemini-1")) {
return Completable.error(
new IllegalArgumentException("Google Maps tool is not supported for model " + model));
}
GenerateContentConfig originalConfig =
llmRequest.config().orElseGet(() -> GenerateContentConfig.builder().build());
ImmutableList<Tool> updatedTools =
ImmutableList.<Tool>builder()
.addAll(originalConfig.tools().orElse(ImmutableList.of()))
.add(Tool.builder().googleMaps(GoogleMaps.builder().build()).build())
.build();
llmRequestBuilder.config(originalConfig.toBuilder().tools(updatedTools).build());
return Completable.complete();| ImmutableList.Builder<Tool> updatedToolsBuilder = ImmutableList.builder(); | ||
| updatedToolsBuilder.addAll(existingTools); | ||
|
|
||
| String model = llmRequestBuilder.build().model().get(); |
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'd say have the model().orElse(null) here if you're going to null check in the conditional anyways
8963038 to
b18e19f
Compare
…or Gemini 2 models
No description provided.