From 9cd01c59f63ac7ea843e25d898e983bac45be285 Mon Sep 17 00:00:00 2001 From: Christian Tzolov Date: Tue, 30 Apr 2024 11:46:40 +0300 Subject: [PATCH] temp --- .../gemini/VertexAiGeminiChatClient.java | 3 +-- ...rtexAiGeminiChatClientFunctionCallingIT.java | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java index 762407cd4..ad74073fa 100644 --- a/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java +++ b/models/spring-ai-vertex-ai-gemini/src/main/java/org/springframework/ai/vertexai/gemini/VertexAiGeminiChatClient.java @@ -351,13 +351,12 @@ public class VertexAiGeminiChatClient final var tool = Tool.newBuilder(); - final var functionDeclarations = this.resolveFunctionCallbacks(functionNames) + final List functionDeclarations = this.resolveFunctionCallbacks(functionNames) .stream() .map(functionCallback -> FunctionDeclaration.newBuilder() .setName(functionCallback.getName()) .setDescription(functionCallback.getDescription()) .setParameters(jsonToSchema(functionCallback.getInputTypeSchema())) - // .setParameters(toOpenApiSchema(functionCallback.getInputTypeSchema())) .build()) .toList(); tool.addAllFunctionDeclarations(functionDeclarations); diff --git a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java index 855bb09e6..980d6644c 100644 --- a/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java +++ b/models/spring-ai-vertex-ai-gemini/src/test/java/org/springframework/ai/vertexai/gemini/function/VertexAiGeminiChatClientFunctionCallingIT.java @@ -179,7 +179,8 @@ public class VertexAiGeminiChatClientFunctionCallingIT { } - //Gemini wants single tool with multiple function, instead multiple tools with single function + // Gemini wants single tool with multiple function, instead multiple tools with single + // function @Test public void canDeclareMultipleFunctions() { @@ -200,8 +201,12 @@ public class VertexAiGeminiChatClientFunctionCallingIT { .build(); var promptOptions = VertexAiGeminiChatOptions.builder() .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) - .withFunctionCallbacks(List.of(weatherFunction, theAnswer)) + .withFunctionCallbacks(List.of(weatherFunction)) .build(); + // var promptOptions = VertexAiGeminiChatOptions.builder() + // .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue()) + // .withFunctionCallbacks(List.of(weatherFunction, theAnswer)) + // .build(); ChatResponse response = vertexGeminiClient.call(new Prompt(messages, promptOptions)); @@ -210,6 +215,14 @@ public class VertexAiGeminiChatClientFunctionCallingIT { logger.info("Response: {}", responseString); assertNotNull(responseString); + response = vertexGeminiClient + .call(new Prompt("What is the answer of the ultimate question in life?", promptOptions)); + + responseString = response.getResult().getOutput().getContent(); + + logger.info("Response: {}", responseString); + assertNotNull(responseString); + } public static class TheAnswerMock implements Function {