Add GEMINI_PRO_1_5_PRO and GEMINI_PRO_1_5_FLASH and update geminie maven BOM to 26.39.0

Also fix few Ollama docs and  code formatting issue.
This commit is contained in:
Christian Tzolov
2024-05-16 15:35:00 +02:00
parent 549c480489
commit 1b1daa7ee7
10 changed files with 43 additions and 21 deletions

View File

@@ -87,6 +87,7 @@ public class OllamaChatClient implements ChatClient, StreamingChatClient {
/**
* @deprecated Use {@link OllamaOptions} constructor instead.
*/
@Deprecated
public OllamaChatClient withDefaultOptions(OllamaOptions options) {
this.defaultOptions = options;
return this;

View File

@@ -66,6 +66,11 @@ public class OllamaEmbeddingClient extends AbstractEmbeddingClient {
this.ollamaApi = ollamaApi;
}
public OllamaEmbeddingClient(OllamaApi ollamaApi, OllamaOptions defaultOptions) {
this.ollamaApi = ollamaApi;
this.defaultOptions = defaultOptions;
}
/**
* @deprecated Use {@link OllamaOptions#setModel} instead.
*/
@@ -75,6 +80,10 @@ public class OllamaEmbeddingClient extends AbstractEmbeddingClient {
return this;
}
/**
* @deprecated Use {@link OllamaOptions} constructor instead.
*/
@Deprecated
public OllamaEmbeddingClient withDefaultOptions(OllamaOptions options) {
this.defaultOptions = options;
return this;

View File

@@ -25,8 +25,8 @@ import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.ollama.OllamaContainer;
import org.springframework.ai.chat.ChatResponse;
import org.springframework.ai.chat.messages.Media;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.prompt.Prompt;
@@ -38,7 +38,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.MimeTypeUtils;
import org.testcontainers.ollama.OllamaContainer;
import static org.assertj.core.api.Assertions.assertThat;

View File

@@ -30,7 +30,7 @@ import static org.assertj.core.api.Assertions.assertThat;
*/
public class OllamaChatRequestTests {
OllamaChatClient client = new OllamaChatClient(new OllamaApi()).withDefaultOptions(
OllamaChatClient client = new OllamaChatClient(new OllamaApi(),
new OllamaOptions().withModel("MODEL_NAME").withTopK(99).withTemperature(66.6f).withNumGPU(1));
@Test
@@ -105,8 +105,8 @@ public class OllamaChatRequestTests {
@Test
public void createRequestWithDefaultOptionsModelOverride() {
OllamaChatClient client2 = new OllamaChatClient(new OllamaApi())
.withDefaultOptions(new OllamaOptions().withModel("DEFAULT_OPTIONS_MODEL"));
OllamaChatClient client2 = new OllamaChatClient(new OllamaApi(),
new OllamaOptions().withModel("DEFAULT_OPTIONS_MODEL"));
var request = client2.ollamaChatRequest(new Prompt("Test message content"), true);

View File

@@ -99,7 +99,11 @@ public class VertexAiGeminiChatClient
GEMINI_PRO_VISION("gemini-pro-vision"),
GEMINI_PRO("gemini-pro");
GEMINI_PRO("gemini-pro"),
GEMINI_PRO_1_5_PRO("gemini-1.5-pro-preview-0514"),
GEMINI_PRO_1_5_FLASH("gemini-1.5-flash-preview-0514");
ChatModel(String value) {
this.value = value;

View File

@@ -68,7 +68,7 @@ public class VertexAiGeminiChatClientFunctionCallingIT {
}
@Test
@Disabled("Google Vertex AI degraded support for parallel function calls")
// @Disabled("Google Vertex AI degraded support for parallel function calls")
public void functionCallExplicitOpenApiSchema() {
UserMessage userMessage = new UserMessage(
@@ -98,7 +98,8 @@ public class VertexAiGeminiChatClientFunctionCallingIT {
""";
var promptOptions = VertexAiGeminiChatOptions.builder()
.withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
// .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
.withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO.getValue())
.withFunctionCallbacks(List.of(FunctionCallbackWrapper.builder(new MockWeatherService())
.withName("get_current_weather")
.withDescription("Get the current weather in a given location")
@@ -125,7 +126,8 @@ public class VertexAiGeminiChatClientFunctionCallingIT {
List<Message> messages = new ArrayList<>(List.of(userMessage));
var promptOptions = VertexAiGeminiChatOptions.builder()
.withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
.withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO.getValue())
// .withModel(VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
.withFunctionCallbacks(List.of(
FunctionCallbackWrapper.builder(new MockWeatherService())
.withSchemaType(SchemaType.OPEN_API_SCHEMA)

View File

@@ -129,7 +129,7 @@
<jackson.version>2.16.1</jackson.version>
<djl.version>0.26.0</djl.version>
<onnxruntime.version>1.17.0</onnxruntime.version>
<com.google.cloud.version>26.37.0</com.google.cloud.version>
<com.google.cloud.version>26.39.0</com.google.cloud.version>
<qdrant.version>1.9.1</qdrant.version>
<spring-retry.version>2.0.5</spring-retry.version>
<ibm.sdk.version>9.20.0</ibm.sdk.version>

View File

@@ -249,8 +249,8 @@ Next, create an `OllamaChatClient` instance and use it to text generations reque
----
var ollamaApi = new OllamaApi();
var chatClient = new OllamaChatClient(ollamaApi).withModel(MODEL)
.withDefaultOptions(OllamaOptions.create()
var chatClient = new OllamaChatClient(ollamaApi,
OllamaOptions.create()
.withModel(OllamaOptions.DEFAULT_MODEL)
.withTemperature(0.9f));
@@ -274,6 +274,8 @@ image::ollama-chat-completion-api.jpg[OllamaApi Chat Completion API Diagram, 800
Here is a simple snippet showing how to use the API programmatically:
NOTE: The `OllamaApi` is low level api and is not recommended for direct use. Use the `OllamaChatClient` instead.
[source,java]
----
OllamaApi ollamaApi =

View File

@@ -57,9 +57,7 @@ public class OllamaAutoConfiguration {
@ConditionalOnProperty(prefix = OllamaChatProperties.CONFIG_PREFIX, name = "enabled", havingValue = "true",
matchIfMissing = true)
public OllamaChatClient ollamaChatClient(OllamaApi ollamaApi, OllamaChatProperties properties) {
return new OllamaChatClient(ollamaApi).withModel(properties.getModel())
.withDefaultOptions(properties.getOptions());
return new OllamaChatClient(ollamaApi, properties.getOptions());
}
@Bean
@@ -68,8 +66,7 @@ public class OllamaAutoConfiguration {
matchIfMissing = true)
public OllamaEmbeddingClient ollamaEmbeddingClient(OllamaApi ollamaApi, OllamaEmbeddingProperties properties) {
return new OllamaEmbeddingClient(ollamaApi).withModel(properties.getModel())
.withDefaultOptions(properties.getOptions());
return new OllamaEmbeddingClient(ollamaApi, properties.getOptions());
}
private static class PropertiesOllamaConnectionDetails implements OllamaConnectionDetails {

View File

@@ -54,9 +54,10 @@ class FunctionCallWithFunctionBeanIT {
@Test
void functionCallTest() {
contextRunner
.withPropertyValues("spring.ai.vertex.ai.gemini.chat.options.model="
+ VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
contextRunner.withPropertyValues("spring.ai.vertex.ai.gemini.chat.options.model="
// + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO.getValue())
+ VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_PRO.getValue())
// + VertexAiGeminiChatClient.ChatModel.GEMINI_PRO_1_5_FLASH.getValue())
.run(context -> {
VertexAiGeminiChatClient chatClient = context.getBean(VertexAiGeminiChatClient.class);
@@ -67,15 +68,22 @@ class FunctionCallWithFunctionBeanIT {
If the information was not fetched call the function again. Repeat at most 3 times.
""");
var userMessage = new UserMessage(
"What's the weather like in San Francisco, Paris and in Tokyo (Japan)?");
// "What's the weather like in San Francisco, Paris and in Tokyo?
// Please let me know how many function calls you've preformed.");
"What's the weather like in San Francisco, Paris and in Tokyo?");
ChatResponse response = chatClient.call(new Prompt(List.of(systemMessage, userMessage),
VertexAiGeminiChatOptions.builder().withFunction("weatherFunction").build()));
// ChatResponse response = chatClient.call(new
// Prompt(List.of(userMessage),
// VertexAiGeminiChatOptions.builder().withFunction("weatherFunction").build()));
logger.info("Response: {}", response);
assertThat(response.getResult().getOutput().getContent()).contains("30", "10", "15");
Thread.sleep(10000);
response = chatClient.call(new Prompt(List.of(systemMessage, userMessage),
VertexAiGeminiChatOptions.builder().withFunction("weatherFunction3").build()));