This commit is contained in:
Christian Tzolov
2024-04-30 11:46:40 +03:00
parent b4194bda9d
commit 9cd01c59f6
2 changed files with 16 additions and 4 deletions

View File

@@ -351,13 +351,12 @@ public class VertexAiGeminiChatClient
final var tool = Tool.newBuilder();
final var functionDeclarations = this.resolveFunctionCallbacks(functionNames)
final List<FunctionDeclaration> 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);

View File

@@ -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<String, Integer> {