Run DeepSeek‑R1 Locally with Ollama and Call It from Spring Boot

Learn how to deploy the open‑source DeepSeek‑R1 model using Ollama on Linux or macOS, configure various model sizes, and integrate it into a Spring Boot application with Spring AI to build an API‑driven translation service, complete with code examples and testing.

Programmer DD
Programmer DD
Programmer DD
Run DeepSeek‑R1 Locally with Ollama and Call It from Spring Boot

Running deepseek‑r1 with Ollama

DeepSeek released the first‑generation open‑source inference model deepseek‑r1 , which offers performance comparable to OpenAI‑o1 at a very low cost. The article shows how to install Ollama and run the model locally.

Install Ollama (Linux): curl -fsSL https://ollama.com/install.sh | sh Run the model (example for 671b): ollama run deepseek-r1:671b If resources are limited, choose smaller variants such as 1.5b, 7b, 8b, 14b, 32b, or 70b:

ollama run deepseek-r1:1.5b<br/>ollama run deepseek-r1:7b<br/>ollama run deepseek-r1:8b<br/>ollama run deepseek-r1:14b<br/>ollama run deepseek-r1:32b<br/>ollama run deepseek-r1:70b

More information is available at the Ollama model library.

Integrating with Spring Boot and Spring AI

After starting the model with Ollama, create a Spring Boot project (e.g., via https://start.spring.io/) and add the spring-ai-ollama-spring-boot-starter dependency.

<dependency>
    <groupId>org.springframework.ai</groupId>
    <artifactId>spring-ai-ollama-spring-boot-starter</artifactId>
</dependency>

Configure Ollama connection in application.properties:

spring.ai.ollama.base-url=http://localhost:11434
spring.ai.ollama.chat.model=deepseek-r1:1.5b
spring.ai.ollama.base-url

: URL of the Ollama API service. spring.ai.ollama.chat.model: Model name to invoke.

Write a unit test to call the model, for example to translate text:

@SpringBootTest(classes = DemoApplication.class)
public class TestOllama {

    @Autowired
    private OllamaChatModel ollamaChatModel;

    @Test
    public void testChatModel() {
        String prompt = """
            You are a translation master proficient in Chinese and English. Translate the given text.
            """;
        String message = """
            Ollama now supports tool calling with popular models such as Llama 3.1.
            This enables a model to answer a given prompt using tool(s) it knows about,
            making it possible for models to perform more complex tasks or interact with the outside world.
            """;
        String result = ollamaChatModel.call(prompt + ":" + message);
        System.out.println(result);
    }
}

Run the test and observe the output, which includes a <think> section showing the model’s reasoning followed by the translated result:

Ollama now supports popular models such as Llama 3.1 for tool calling. This makes it possible for models to answer prompts using known tools, enabling more complex tasks or interaction with the outside world.

These steps demonstrate a complete workflow from deploying DeepSeek‑R1 locally with Ollama to exposing it via a Spring Boot API using Spring AI.

Spring BootAPIDeepSeekSpring AIOllama
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.