Powered by Blogger.

How to create an AI chatbot using Spring AI and a Web HTML page.

1 comment :
Spring AI is an open-source application framework designed to easily integrate Artificial Intelligence (AI) features into Spring Boot applications. It functions as a standard middleware layer; rather than training or building AI models from scratch, it enables developers to seamlessly connect their enterprise code with existing AI models. Below, we outline the step-by-step process for configuring and developing a chatbot.
First, you need to select an LLM (Large Language Model) that Spring AI will use to communicate:
 
Step 1:We will use the standalone Ollama LLM model. To do this, install Ollama on your system (download via https://ollama.com/download/windows) and then download a free model from https://ollama.com/search.
CMD:
1. widows CMD:     
                            irm https://ollama.com/install.ps1 | iex
2. mocOS CMD:  
                            curl -fsSL https://ollama.com/install.sh | sh
3. Linux CMD:  
                           curl -fsSL https://ollama.com/install.sh | sh

Check Ollama Run using URL: http://localhost:11434/
Step 2:
In this step, we configure the Spring Boot AI application using Spring Initializr (https://start.spring.io/); we have previously covered how to perform this configuration. Here, we will explain the coding process step-by-step. 
Step 2.1: Check the dependencies in the `pom.xml` file and ensure they match your project setup.
 

Step 2.2: 
We create a REST controller named `ChatClientController.java`. Here, we will see how to implement the LLM packages and classes, and we will also use `@CrossOrigin` to facilitate the design of the web UI.

Step 2.3: We will configure the LLM model settings within the `application.properties` file.
 

spring.application.name=aiChatclient
server.port=8081
spring.ai.ollama.base-url=http://localhost:11434
spring.ai.ollama.chat.options.model=codellama:latest
spring.ai.ollama.chat.options.num-predict=256
spring.ai.ollama.chat.options.temperature=0.2


Step 3:
Finally, we create the web page (`indexAI_CHAT.html`) and integrate the REST controller with the web UI.
 
Output:


Step-by-step development video: