The Gemini model provides the responseMimeType
parameter, as documented in the Gemini Model Reference.
However, when I attempting to call the Gemini model using Spring AI, there is no direct option to set this parameter. To work around this, I used reflection in my project:
val chatModel = VertexAiGeminiChatModel(
VertexAI(System.getenv("GEMINI_PROJECT_ID"), System.getenv("GEMINI_LOCATION"))
)
val generationConfig = GenerationConfig.newBuilder()
.setResponseMimeType("application/json") // responseMimeType 을 설정할 수 없어서. 직접 접근하여 설정하였다.
.setTemperature(0.8f)
.build()
val generationConfigField = VertexAiGeminiChatModel::class.java.getDeclaredField("generationConfig")
generationConfigField.isAccessible = true
generationConfigField.set(chatModel, generationConfig)
Therefore, it would be beneficial if the responseMimeType
parameter was officially supported. The model generated by default in VertexAiGeminiChatModel
is GEMINI_1_5_PRO
, so this option is available from this version onwards, so it should be added as needed.
Comment From: markpollack
Thanks! Important feature indeed. I updated the docs. Merged in bc55bc7196f9d02115c32fa1d831b85d7c35e86f