-
Notifications
You must be signed in to change notification settings - Fork 59
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
Add Spring Boot Project Starter for Google Gemini API model - ChatLangauge, Streaming model and Embedding Model #74
base: main
Are you sure you want to change the base?
Conversation
@langchain4j hey can you please have a look at this |
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.
@Suhas-Koheda thanks a lot!
.topP(chatModelProperties.getTopP()) | ||
.topK(chatModelProperties.getTopK()) | ||
.maxOutputTokens(chatModelProperties.getMaxOutputTokens()) | ||
.responseFormat(ResponseFormat.JSON) |
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.
why is it json?
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.
Hi. Related to your question. AutoConfig it's not injecting logging properties and json format from the properties -> https://docs.langchain4j.dev/tutorials/logging/ is not working when this AutoConfig is used. I will wait until this PR is merged to create a PR to avoid conflicts or If you want to add this configuration in this PR. Whatever you consider better.
Thank you!
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.
Hey! can you provide me with some references
As i did not find the logging used in other starters
Or maybe i overlooked
Thank you!
@franglopez
langchain4j-google-ai-gemini/src/main/java/dev/langchain4j/googleaigemini/AutoConfig.java
Outdated
Show resolved
Hide resolved
...ain4j-google-ai-gemini/src/main/java/dev/langchain4j/googleaigemini/ChatModelProperties.java
Outdated
Show resolved
Hide resolved
.../src/test/java/dev/langchain4j/googleaigemini/Langchain4jGoogleAiGeminiApplicationTests.java
Outdated
Show resolved
Hide resolved
langchain4j-google-ai-gemini/src/main/resources/application.properties.local
Outdated
Show resolved
Hide resolved
@langchain4j also in the timeout values i had doubt At present i have hardcoded used 60 secs |
@Suhas-Koheda you can see how timeouts are handled in OpenAI starter here, the same for .logRequests(chatModelProperties.logRequests()). |
@Suhas-Koheda |
Yeah sure I'll take care of it! |
@ddobrin hey for the response format i have kept the type of prop as ResponseFormat only which is user defined - not a primitive type? |
…urces/application.properties
@langchain4j |
@Suhas-Koheda on a 📱 let me come back to it at the beginning of the week |
@Suhas-Koheda I would love to include your PR in this release (today), but there are still some issues left (please see my comments above). Since this is an independent module, we can release it a bit later separately, once this PR is ready. |
@langchain4j |
@langchain4j hey i have written the NPE checks can you please have a look over this |
return defaultMap; | ||
} | ||
return Map.of( | ||
safetySetting.geminiHarmCategory(), |
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.
Are these settings supposed to have only a single key-value pair?
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 safety settings builder takes the map of geminiharmcategory as key and geminiharmblockthreshold as value
No it can take any number of values
It changes them into list
But for a single model thre would be only one harmcategory and blockthreshold right?
If that's not the case we can write such that the harmcategory and blockthreshold takes comma separated values and we manually convert then into map in the autoconfig?
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.
private Map<GeminiHarmCategory,GeminiHarmBlockThreshold> checkSafetySettingForNull(GeminiSafetySetting safetySetting) {
if(safetySetting==null){
Map<GeminiHarmCategory,GeminiHarmBlockThreshold> defaultMap= new HashMap<>();
defaultMap.put(HARM_CATEGORY_CIVIC_INTEGRITY,HARM_BLOCK_THRESHOLD_UNSPECIFIED);
return defaultMap;
}
Map<GeminiHarmCategory,GeminiHarmBlockThreshold> userMap= new HashMap<>();
safetySetting.geminiHarmCategory().forEach(category -> userMap.put(category,safetySetting.geminiHarmBlockThreshold().get(safetySetting.geminiHarmCategory().indexOf(category))));
return userMap;
}
this can be done if there are multiple GeminiHarmCategory and GeminiHarmBlockThreshold
and the test cases run properly too
the code is ready to be commited
thank you!
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.
Hi @ddobrin, could you please help with the review?
It seems to me that current logic in checkSafetySettingForNull
is not correct. If settings are not specified, defaultMap.put(HARM_CATEGORY_CIVIC_INTEGRITY,HARM_BLOCK_THRESHOLD_UNSPECIFIED);
is set (is it correct?). Also, chatModelProperties
can have only a single setting...
@Suhas-Koheda I guess ChatModelProperties
should have a Map<GeminiHarmCategory, GeminiHarmBlockThreshold> safetySettings
instead of GeminiSafetySetting safetySetting
.
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.
Or List<GeminiSafetySetting> safetySettings
, the same way as it is in the BaseGeminiChatModel
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 safety filters settings, with their defaults, are available at his link
For flash and pro 1.5 the "default" block method is "SEVERITY" with the threshold by default at "BLOCK_MEDIUM_AND_ABOVE".
The HARM_CATEGORY_CIVIC_INTEGRITY filter is off by default.
Can I suggest that you do not set a value at all in
private GeminiMode checkGeminiModeForNull(GeminiFunctionCallingConfig geminiFunctionCallingConfig)
?
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.
To simplify, you can use the GeminiSafetySetting class which has a pair of <category, threshold?
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.
Just in case: I would not duplicate the default settings for Gemini in LC4j code. If user did not configure anything explicitly, we should not set the defaults, but let Gemini backend do it
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.
Hey i have a doubt
Like we are writing the safety settings in builder right
How can we leave it empty or such?
Probably there isn't any function in the backend with withSafetySettings() as such!
I am not sure of what to do
Like we should include safetysettings in builder pattern but pass null value since the user did not configure any in settings
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.
Yes, agreed.
If the user does not specify any settings, then none are to be set.
Gemini has a default set which it will use if no other setting is modifying those defaults.
Link above just shows you the settings and why civic integrity should not be set
You can just change the condition when safetySettings is null or empty
@langchain4j hey! :-) |
@langchain4j this logic looks perfect to me now! |
Let me have a look tomorrow |
@ddobrin |
Hi @Suhas-Koheda The test code runs as is, and, if safetySettings are not set, it passes, so that part is solved. While looking at the code and running it, you can see that there is no test which would address the use case when a user wishes to actually set in the configuration the safetySettings, which would close the testing for this area. Do you want to add a test as well for setting actual values? |
Hi @Suhas-Koheda I'll share some code here, as non-intrusive as possible, and you can consider merging it to your code, as you see fit: Added a new test:
Changed in ChatModelProperties the settings to be plain Strings: Last, in AutoConfig:
The small conversion method maps the Strings to the actual enums:
|
@ddobrin yeah sure the map conversion would help |
@ddobrin |
Thank you for making the changes @Suhas-Koheda. Nice to add the individual properties to the tests. The only small thing you might wish to adjust is L.58 in the AutoConfigIT test, as the test is not running correctly due to: should be "setting" instead of "settings" |
@ddobrin |
Just small things:
|
I have run all the tests with gemini 2 flash exp model and works for me fine! Please mention if there are any other things! |
@Suhas-Koheda - yes, any change to get a deterministic text works for 17,711 vs 17711 The tests failing on the model are the streamingChatModel() tests |
@ddobrin |
Looks good @Suhas-Koheda |
@langchain4j can you have a look over this! |
Closes langchain4j/langchain4j#2103