I'm working through the tutorial here - which has code here.
When I run the Spring Boot application I get:
No qualifying bean of type '.springframework.ai.ollama.OllamaChatModel' available
When I look at the class source for OllamaChatModel
- it is not annotated as a bean - and so wouldn't be picked up in component scan.
This code appears to assume it is a bean:
My question is: Did OllamaChatModel stop being a Spring Bean?
I'm working through the tutorial here - which has code here.
When I run the Spring Boot application I get:
No qualifying bean of type '.springframework.ai.ollama.OllamaChatModel' available
When I look at the class source for OllamaChatModel
- it is not annotated as a bean - and so wouldn't be picked up in component scan.
This code appears to assume it is a bean:
My question is: Did OllamaChatModel stop being a Spring Bean?
Share Improve this question edited Jan 23 at 10:18 Arvind Kumar Avinash 79.6k10 gold badges92 silver badges135 bronze badges asked Jan 18 at 3:51 hawkeyehawkeye 35.8k35 gold badges159 silver badges314 bronze badges1 Answer
Reset to default 2My question is: Did OllamaChatModel stop being a Spring Bean?
No, it is very much there. Check OllamaChatModel
documentation to learn more about this class. Also, I recommend you check What in the world are Spring beans?.
I have shown its usage as a Spring Bean in the following tested code.
Prerequisites
- Create a Spring Boot project with Spring Web, Thymeleaf and Ollama dependencies.
- Make sure Ollama is running in your system. You can confirm it by accessing http://localhost:11434/ in your browser. When it is running, the page will show: Ollama is running. If it is not running, start a model e.g.
ollama run mistral:latest
.
Template
<!--askme.html-->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.">
<body>
<form th:action="@{/askMe}" method="post">
Question:
<input type="text" name="question" placeholder="Type your question here..."
th:value="${question}" required />
<button type="submit">Answer</button>
</form>
<div th:if="${answer}">
<p>Answer: <span th:text="${answer}"></span></p>
</div>
</body>
</html>
Controller
import .springframework.beans.factory.annotation.Autowired;
import .springframework.stereotype.Controller;
import .springframework.ui.Model;
import .springframework.web.bind.annotation.*;
@Controller
public class AskMeController {
@Autowired
private AskMeService service;
@GetMapping("/showAskMe")
public String showAskMe() {
return "askme";
}
@PostMapping("/askMe")
public String askMe(String question, Model model) {
model.addAttribute("question", question);
model.addAttribute("answer", service.getAnswer(question));
return "askme";
}
}
Service
import .springframework.ai.ollama.OllamaChatModel;
import .springframework.beans.factory.annotation.Autowired;
import .springframework.stereotype.Service;
@Service
public class AskMeService {
@Autowired
private OllamaChatModel ollamaChatModel;
public String getAnswer(String question) {
return ollamaChatModel.call(question);
}
}
Test
Start the application and access http://localhost:8080/showAskMe in your browser.