Ollama

김소희·2025년 11월 17일

로고에 라마가 있는 올라마 🦙

Ollama는 로컬(Local) 환경에서 대형 언어 모델(LLM, Large Language Model)
직접 실행·관리할 수 있도록 도와주는 툴(도구) 이다.

즉, OpenAI나 Anthropic 같은 클라우드 기반 LLM API에 의존하지 않고,
사용자의 PC나 서버에 원하는 모델을 내려받아 오프라인으로 실행할 수 있다.
플랫폼 + 프레임워크 성격을 가지며 다음과 같은 기능을 지원한다:

  • 모델 다운로드 및 관리
  • 모델 실행 및 설정
  • 명령 기반(커맨드라인) 활용

🦙 Ollama는 LLM이 아니다!

이것은 모델이 아니라 실행 환경일 뿐이므로 원하는 모델을 검색해서 알맞은 용량인 모델을 다운로드 한 뒤에 cmd에서 ollama pull 모델로 다운로드 받고 ollama -v 명령어로 확인 가능하다.

예시 명령어:

ollama pull llama3
ollama run llama3
ollama -v   # 버전 확인

⚠️ 한계점

로컬 모델은 학습 시점이 고정되어 있기 때문에
오늘의 날씨, 최신 제품 정보, 실시간 데이터 분석
최근 정보 기반의 질문에는 정확하지 않을 수 있다.


올라마 홈페이지

다운로드 및 설치가 완료되면,
아래와 같은 Ollama 실행 프로그램(UI)이 표시되고 정상적으로 실행된다.

이후에는 명령 프롬프트(cmd)에서 원하는 모델을 다운로드하여 사용할 수 있다.


스프링에서 ollam 사용하기

build.gradle

dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.springframework.ai:spring-ai-starter-model-ollama'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

properties

# 톰캣 포트 변경
server.port=8050

# 기본 챗 모델 공급자 ollama 로 설정
spring.ai.model.chat=ollama
# ollama 서버의 앤드 포인트 
spring.ai.ollama.base-url=http://localhost:11434

# 사용할 로콜 모델의 이름
spring.ai.ollama.chat.options.model=gemma3
# 0.0 직관적 ... 1.0 창의적
spring.ai.ollama.chat.options.temperature=0.7

# 모델이 없을 때만 자동으로 다운로드 (pull)
spring.ai.ollama.init.pull-model-strategy=when-missing
# 모델 초기화 시 최대 대기 시간
spring.ai.ollama.init.timeout=60s
# 실패시 재시도 횟수 
spring.ai.ollama.init.max-retries=1

service

package com.example.demo.service;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.stereotype.Service;

@Service
public class OllamaChatService {
	private final ChatClient chatClient;
	
	public OllamaChatService(ChatClient.Builder builder) {
		this.chatClient = builder.build();
	}
	
	public String getQuestion() {
		return chatClient.prompt("거울아 거울아 세상에서 누가 가장 예쁘니?").call().content();
	}
	
}

main

package com.example.demo;

import com.example.demo.service.OllamaChatService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

@SpringBootApplication
public class SpringAi3Application {

	 public static void main(String[] args) {
	        ConfigurableApplicationContext context = SpringApplication.run(SpringAi3Application.class, args);

	        OllamaChatService ollamaChatService = context.getBean(OllamaChatService.class);
	        String response = ollamaChatService.getQuestion();
	        System.out.println("결과 : \n " + response);
	    }

}

올라마를 실행하면서 스프링을 돌리면,

profile
백엔드 개발자의 노트

0개의 댓글