langchain4j / langchain4j

Java version of LangChain
https://docs.langchain4j.dev
Apache License 2.0
3.89k stars 740 forks source link

[FEATURE] Add harm block threshold param to Vertex AI Gemini Chat Model #1182

Closed kstanisz closed 17 hours ago

kstanisz commented 1 month ago

Sometimes using Google Vertex Ai Gemini model there is a failure:

java.lang.IllegalArgumentException: The response is blocked due to safety reason. at com.google.cloud.vertexai.generativeai.ResponseHandler.checkFinishReason(ResponseHandler.java:187) ~[google-cloud-vertexai-1.3.0.jar:1.3.0] at com.google.cloud.vertexai.generativeai.ResponseHandler.getContent(ResponseHandler.java:85) ~[google-cloud-vertexai-1.3.0.jar:1.3.0] at dev.langchain4j.model.vertexai.VertexAiGeminiChatModel.generate(VertexAiGeminiChatModel.java:140) ~[langchain4j-vertex-ai-gemini-0.31.0.jar:na] at dev.langchain4j.service.DefaultAiServices$1.invoke(DefaultAiServices.java:189) ~[langchain4j-0.31.0.jar:na] at jdk.proxy2/jdk.proxy2.$Proxy98.sendMessage(Unknown Source) ~[na:na]

There should be an option to configure safety settings for Gemini model.

In VertexAiGeminiChatModel.class we create GenerativeModel which has a safetySettings param to configure.

langchain4j commented 1 month ago

cc @glaforge

langchain4j commented 17 hours ago

Implemented in https://github.com/langchain4j/langchain4j/pull/1278