Skip to content

Commit

Permalink
Add support for Ollama (locally running Mistral AI)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandreroman committed Jun 4, 2024
1 parent 0a40011 commit d66dabe
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-mistral-ai-spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.ai</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 3 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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}

0 comments on commit d66dabe

Please sign in to comment.