Spring AI with Llama #2 — Core Concepts: Tokens, Context Window, Prompt & Temperature (Java)

Why does the same question give you a different answer every time? And why is one reply two sentences and the next six paragraphs? In Chapter 2 of Spring AI with Llama, we go under the hood: tokens, the context window, prompts/messages, and temperature — the four concepts that separate developers who fight the AI from those who control it. Then we put them to work: two new endpoints on the SmartHR Assistant — /hr/ask/precise for short, deterministic policy answers, and /hr/ask/creative for open-ended brainstorming — both tuned with Spring AI's ChatOptions. Everything runs 100% locally with Ollama and Llama 3.2. No OpenAI account, no API keys, no cloud bills. ⏱️ What you'll learn in this chapter: • What a token actually is (and why 128K tokens ≈ a whole novel) • The context window — the shared budget for input + output • How a Prompt is really a list of Messages (System, User, Assistant) • How temperature controls randomness — and which value to use when • Capping response length with maxTokens • Building /ask/precise (temp 0.0) and /ask/creative (temp 0.9) with ChatOptions 🔗 RESOURCES 💻 Source code (all chapters, GitHub): https://github.com/balajich/spring-ai... 📝 Written notes / tutorial for this chapter: https://prompttoapps.com/tutorials/sp... 🧠 Test yourself — Chapter 2 quiz: https://prompttoapps.com/quiz/#spring... ▶️ WATCH THE SERIES IN ORDER Series Introduction:    • Spring AI with Llama — Build Local AI Apps...   Chapter 1 — Hello, Spring AI!:    • Spring AI with Llama #1 — Hello Spring AI:...   Chapter 2 — Core Concepts: (you are here) 🧰 Tech stack: Spring Boot 4.1 • Spring AI 2.0 • Java 25 • Ollama • Llama 3.2 Built and tested on Java 25.0.3, Maven 3.9.16, Ollama 0.31.1.

Don't learn AI Agents without Learning these Fundamentals
▶︎

Don't learn AI Agents without Learning these Fundamentals

Spring AI with Llama #4 — Prompt Engineering: Stop Hardcoding Prompts
▶︎

Spring AI with Llama #4 — Prompt Engineering: Stop Hardcoding Prompts

Resilience4j Session 4  Preventing cascading of failures in REST API using Circuit Breaker
▶︎

Resilience4j Session 4 Preventing cascading of failures in REST API using Circuit Breaker

Spring AI with Llama #3 — Comparing Models
▶︎

Spring AI with Llama #3 — Comparing Models

I Gave My AI Agent Memory (It Remembers Everything Now) | Agentic AI Ep.5
▶︎

I Gave My AI Agent Memory (It Remembers Everything Now) | Agentic AI Ep.5

Spring Cloud Session 5 Microservices Documentation
▶︎

Spring Cloud Session 5 Microservices Documentation

MORNING PRAYER | Surrender Your Family to God with Faith and Walk this Day in His Peace and Prote...
▶︎

MORNING PRAYER | Surrender Your Family to God with Faith and Walk this Day in His Peace and Prote...

MCP vs API Explained: Do You Really Need MCP?
▶︎

MCP vs API Explained: Do You Really Need MCP?

The LLM Interview Series #1:  What exactly is the KV Cache?
▶︎

The LLM Interview Series #1: What exactly is the KV Cache?

Musica para trabajar activo y alegre - Música Alegre para en Tiendas, Cafés | Deep House Mix 2026
▶︎

Musica para trabajar activo y alegre - Música Alegre para en Tiendas, Cafés | Deep House Mix 2026

Harnesses in AI: A Deep Dive — Tejas Kumar, IBM
▶︎

Harnesses in AI: A Deep Dive — Tejas Kumar, IBM

CHOSEN ONE!! YOUR IDENTITY REVEAL JUST SHOOK THE INTERNET... AND THEIR MINDS
▶︎

CHOSEN ONE!! YOUR IDENTITY REVEAL JUST SHOOK THE INTERNET... AND THEIR MINDS

Spring Cloud Session-7 Centralized Configuration
▶︎

Spring Cloud Session-7 Centralized Configuration

System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra
▶︎

System Design Explained: APIs, Databases, Caching, CDNs, Load Balancing & Production Infra

How AI agents & Claude skills work (Clearly Explained)
▶︎

How AI agents & Claude skills work (Clearly Explained)

Resilience4j  Session 1 Limit of number of requests to RESTAPI using ratelimiter
▶︎

Resilience4j Session 1 Limit of number of requests to RESTAPI using ratelimiter

Spring Cloud Session 3 Inter Microservice Communication Synchronous
▶︎

Spring Cloud Session 3 Inter Microservice Communication Synchronous

The Most Important Conversation in AI Right Now
▶︎

The Most Important Conversation in AI Right Now

Resilience4j Session 7  Monitoring CircuitBreaker Events with Prometheus and visualizing them in Gra
▶︎

Resilience4j Session 7 Monitoring CircuitBreaker Events with Prometheus and visualizing them in Gra

Resilience4j Session 5  Preventing cascading of slowness in REST API using Circuit Breaker
▶︎

Resilience4j Session 5 Preventing cascading of slowness in REST API using Circuit Breaker