1 Ollama

Ollama is an open-source tool that enables large language models (LLMs), such as deepseek-r1, gemma3, qwen3, and others, to run on your local computer. It greatly simplifies the complex installation and configuration process for LLMs, making it easy for both users with a technical background and those without any to experience these powerful models.

1.1 Key Features

The main features of Ollama are as follows:

  • Simple and Easy to Use:You only need to download and install Ollama, and then use simple command lines to pull and run models. It bundles all dependencies and configurations, saving a lot of hassle.

  • Local Execution:All computations are performed on your computer, which means your data is completely private. You don’t have to worry about data being uploaded to the cloud, which is very important for privacy-conscious users.

  • Support for Multiple Models:Ollama has a very rich model library and supports a variety of mainstream open-source models. You can visit its official website or use the command “ollama list” in the terminal to view all available models.

  • Good Compatibility:Ollama supports macOS, Linux, and Windows.

  • API:Ollama also provides easy-to-use APIs. Developers can utilize the APIs to integrate local models into their own applications, which provides great convenience for building local AI applications.

  • Model Customization:You can create your own models by modifying the model file (Modelfile), such as merging different models or fine-tuning based on a base model.

1.2 Getting Started

Go to the Ollama download page and select the corresponding Ollama version based on your operating system.

ollama-download

Ollama provides a graphical user interface, allowing users to easily perform operations such as asking questions and replacing models. For example, in the image below, you just need to enter the question you want to ask in the text box and send it, and after a short wait, you can see Ollama’s output answer.

q_and_a

Note: The duration of “a short wait” mainly depends on your computer’s hardware configuration and the size of the selected LLM. Higher hardware configurations and smaller models lead to faster output speeds from Ollama; conversely, it will be slower. If you want to replace the model you are currently using with a smaller one, just click the area highlighted in red in the image below.

change_m

The optional models provided by Ollama, along with information such as their size/parameters, will be explained in the next subsection.

1.3 Optional Models

Ollama offers a large number of mainstream LLMs to choose from, and this support list continues to grow as model versions are updated. See this page for details.

m_list

The Ollama supported model list page shows the download volume for each model (reflecting its popularity) and the parameter version (generally, a smaller number of parameters means a smaller model size). Clicking on a specific model allows you to enter its details page for more information.

1.4 LM Studio

LM Studio is another tool that can run LLMs locally. It offers free and paid versions and is often compared with Ollama. I will not introduce it in detail here; those interested can look it up themselves.

lm_studio

2 Spring AI

Ollama provides an HTTP protocol API interface, which facilitates integration with external programs. Below, I will use Java + Spring as an example for illustration:

The Spring framework provides a project specifically for AI—Spring AI. It is an application framework for artificial intelligence, whose goal is to apply the design principles of the Spring ecosystem ( such as portability and modular design) to the field of AI and promote the use of POJOs (Plain Old Java Objects) as application building blocks in the AI domain.

spring_ai

2.1 Generating a Maven Project

Generate a sample project on the Spring initializr page. Note to include the Ollama dependency and the Spring Web dependency.

spring_ai_ollama

After the project is generated, you can see that “spring-ai-bom” (the latest version is 1.0.3) and “spring-ai-starter-model-ollama” have been included in the “pom.xml” file.

spring_pom

2.2 Integrating Ollama

Create a new “@RestController” to demonstrate calling the Ollama interface. The specific code is as follows:

import java.util.Map;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.prompt.ChatOptions;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.chat.prompt.PromptTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/chat")
public class ChatController {
	
    public ChatController(ChatClient.Builder chatClientBuilder, ChatMemory chatMemory) {
        this.chatClient = chatClientBuilder
        		// Choose a model
        		.defaultOptions(ChatOptions.builder().model("gemma3:1b").build())
                .build();
    }

    @GetMapping("/{tool}")
    String evaluateTools(@PathVariable("tool") String tool) {
    	// Prompt template
        PromptTemplate pt = new PromptTemplate("""
                工具{tool}好用吗?
                """);
        // set parameters
        Prompt p = pt.create(Map.of("tool", tool));

        return this.chatClient.prompt(p)
                .call()
                .content();
    }

    /**
     * attribute(s)
     */
	private ChatClient chatClient;
}

In the constructor ChatController, the model used, gemma3, with 1b parameters, is specified via:

ChatOptions.builder().model("gemma3:1b").build()

“PromptTemplate” sets the prompt template, which contains the variable {tool}. This variable is specified by {tool} in the accessed URL path and is passed into the prompt template via a Map type.

After starting this Spring AI application, accessing http://127.0.0.1:8080/chat/Ollama will show output similar to the following:

spring_ai_output

At this point, the simplest Spring AI + Ollama local LLM program is complete. spring-ai-starter-model-ollama encapsulates many details; interested users can view its GitHub

3 Summary

Ollama makes running LLMs on a local computer simpler than ever for ordinary users. Whether you want to protect your privacy, use AI without an internet connection, or simply want to experience the latest open-source models, Ollama is an excellent choice. Spring AI, on the other hand, allows programmers focused on engineering development to more easily experience the joy of integrating AI capabilities into their programs.