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.
This commit is contained in:
Christian Tzolov
2024-03-04 13:58:49 +01:00
parent 3a59587357
commit 8701cccfab

View File

@@ -64,7 +64,9 @@ public class VertexAiGeminiAutoConfiguration {
@Bean
@ConditionalOnMissingBean
public VertexAiGeminiChatClient vertexAiGeminiChat(VertexAI vertexAi, VertexAiGeminiChatProperties chatProperties,
List<FunctionCallback> toolFunctionCallbacks, FunctionCallbackContext functionCallbackContext) {
List<FunctionCallback> toolFunctionCallbacks, ApplicationContext context) {
FunctionCallbackContext functionCallbackContext = springAiFunctionManager(context);
if (!CollectionUtils.isEmpty(toolFunctionCallbacks)) {
chatProperties.getOptions().getFunctionCallbacks().addAll(toolFunctionCallbacks);
@@ -73,9 +75,11 @@ public class VertexAiGeminiAutoConfiguration {
return new VertexAiGeminiChatClient(vertexAi, chatProperties.getOptions(), functionCallbackContext);
}
@Bean
@ConditionalOnMissingBean
public FunctionCallbackContext springAiFunctionManager(ApplicationContext context) {
/**
* Because of the OPEN_API_SCHEMA type, the FunctionCallbackContext instance must
* different from the other JSON schema types.
*/
private FunctionCallbackContext springAiFunctionManager(ApplicationContext context) {
FunctionCallbackContext manager = new FunctionCallbackContext();
manager.setSchemaType(SchemaType.OPEN_API_SCHEMA);
manager.setApplicationContext(context);