diff --git a/pom.xml b/pom.xml index a188449..fea5178 100644 --- a/pom.xml +++ b/pom.xml @@ -33,6 +33,10 @@ org.springframework.ai spring-ai-mistral-ai-spring-boot-starter + + org.springframework.ai + spring-ai-ollama-spring-boot-starter + org.springframework.ai diff --git a/src/main/java/com/broadcom/tanzu/demos/springai101/OllamaConfig.java b/src/main/java/com/broadcom/tanzu/demos/springai101/OllamaConfig.java new file mode 100644 index 0000000..8c65c43 --- /dev/null +++ b/src/main/java/com/broadcom/tanzu/demos/springai101/OllamaConfig.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2024 Broadcom, Inc. or its affiliates + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.broadcom.tanzu.demos.springai101; + +import org.springframework.ai.chat.client.ChatClient; +import org.springframework.ai.embedding.EmbeddingModel; +import org.springframework.ai.ollama.OllamaChatModel; +import org.springframework.ai.ollama.OllamaEmbeddingModel; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; + +@Configuration(proxyBeanMethods = false) +@ConditionalOnProperty(name = "app.ai-provider", havingValue = "ollama") +class OllamaConfig { + @Bean + ChatClient.Builder chatClientBuilder(OllamaChatModel ollamaChatModel) { + return ChatClient.builder(ollamaChatModel); + } + + @Bean + @Primary + EmbeddingModel embeddingModel(OllamaEmbeddingModel ollamaEmbeddingModel) { + return ollamaEmbeddingModel; + } +} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index a0ec865..f5879bd 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -32,5 +32,8 @@ spring.ai.mistralai.api-key=${MISTRALAI_API_KEY} spring.ai.mistralai.chat.options.temperature=0 spring.ai.mistralai.chat.options.model=open-mixtral-8x22b +# Ollama configuration. +spring.ai.ollama.chat.model=mistral + # OpenWeatherMap configuration. openweathermap.api-key=${OPENWEATHERMAP_API_KEY}