Skip to content

Commit 8701ccc

Browse files
committed
Improve VertexAiGeminiAutoConfiguration to allow function calling portability
VertexAiGeminiAutoConfiguration creates its own FunctionCallbackContext instance with schema type set to SchemaType.OPEN_API_SCHEMA. This ensures that one other (non OPEN_API_SCHEMA) FucntionCallbackContext Bean overrds it.
1 parent 3a59587 commit 8701ccc

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

spring-ai-spring-boot-autoconfigure/src/main/java/org/springframework/ai/autoconfigure/vertexai/gemini/VertexAiGeminiAutoConfiguration.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ public VertexAI vertexAi(VertexAiGeminiConnectionProperties connectionProperties
6464
@Bean
6565
@ConditionalOnMissingBean
6666
public VertexAiGeminiChatClient vertexAiGeminiChat(VertexAI vertexAi, VertexAiGeminiChatProperties chatProperties,
67-
List<FunctionCallback> toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext) {
67+
List<FunctionCallback> toolFunctionCallbacks, ApplicationContext context) {
68+
69+
FunctionCallbackContext functionCallbackContext = springAiFunctionManager(context);
6870

6971
if (!CollectionUtils.isEmpty(toolFunctionCallbacks)) {
7072
chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks);
@@ -73,9 +75,11 @@ public VertexAiGeminiChatClient vertexAiGeminiChat(VertexAI vertexAi, VertexAiGe
7375
return new VertexAiGeminiChatClient(vertexAi, chatProperties.getOptions(), functionCallbackContext);
7476
}
7577

76-
@Bean
77-
@ConditionalOnMissingBean
78-
public FunctionCallbackContext springAiFunctionManager(ApplicationContext context) {
78+
/**
79+
* Because of the OPEN_API_SCHEMA type, the FunctionCallbackContext instance must
80+
* different from the other JSON schema types.
81+
*/
82+
private FunctionCallbackContext springAiFunctionManager(ApplicationContext context) {
7983
FunctionCallbackContext manager = new FunctionCallbackContext();
8084
manager.setSchemaType(SchemaType.OPEN_API_SCHEMA);
8185
manager.setApplicationContext(context);

0 commit comments

Comments
 (0)