Fix Geminie GenerativeModel handling between calls

Resolves #560
This commit is contained in:
Christian Tzolov
2024-04-07 21:57:04 +02:00
parent 2b421a49ff
commit e268975a80
4 changed files with 19 additions and 5 deletions

View File

@@ -78,8 +78,6 @@ public class VertexAiGeminiChatClient
private final GenerationConfig generationConfig;
private GenerativeModel generativeModel;
public enum GeminiMessageType {
USER("user"),
@@ -140,7 +138,6 @@ public class VertexAiGeminiChatClient
this.vertexAI = vertexAI;
this.defaultOptions = options;
this.generationConfig = toGenerationConfig(options);
this.generativeModel = new GenerativeModel(options.getModel(), vertexAI);
}
// https://cloud.google.com/vertex-ai/docs/generative-ai/model-reference/gemini
@@ -204,7 +201,8 @@ public class VertexAiGeminiChatClient
Set<String> functionsForThisRequest = new HashSet<>();
GenerationConfig generationConfig = this.generationConfig;
GenerativeModel generativeModel = this.generativeModel;
GenerativeModel generativeModel = new GenerativeModel(this.defaultOptions.getModel(), this.vertexAI);
VertexAiGeminiChatOptions updatedRuntimeOptions = null;

View File

@@ -146,7 +146,7 @@ public class VertexAiGeminiChatClientFunctionCallingIT {
public void functionCallTestInferredOpenApiSchemaStream() {
UserMessage userMessage = new UserMessage(
"What's the weather like in San Francisco, in Paris and in Tokyo? Use Multi-turn function calling.");
"What's the weather like in San Francisco, in Paris and in Tokyo, Japan? Use Multi-turn function calling. Provide answer for all requested locations.");
List<Message> messages = new ArrayList<>(List.of(userMessage));

View File

@@ -83,6 +83,13 @@ class FunctionCallWithFunctionBeanIT {
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
response = chatClient
.call(new Prompt(List.of(systemMessage, userMessage), VertexAiGeminiChatOptions.builder().build()));
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getContent()).doesNotContain("30", "10", "15");
});
}

View File

@@ -77,6 +77,15 @@ public class FunctionCallWithPromptFunctionIT {
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
// Verify that no function call is made.
response = chatClient
.call(new Prompt(List.of(systemMessage, userMessage), VertexAiGeminiChatOptions.builder().build()));
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getContent()).doesNotContain("30", "10", "15");
});
}