Ollama (로컬 모델)
LLMs를 완전한 프라이버시로 로컬에서 실행하세요 - API 키 없이, 인터넷 없이, 비용 없이.
개요
┌─────────────────────────────────────────────────────────────────────┐
│ Ollama Local Setup │
├─────────────────────────────────────────────────────────────────────┤
│ │
│ Your Machine │
│ ┌─────────────────────────────────────────────────────────────┐ │
│ │ │ │
│ │ ┌──────────────┐ ┌──────────────┐ │ │
│ │ │ ADK-Rust │ ───▶ │ Ollama │ │ │
│ │ │ Agent │ │ Server │ │ │
│ │ └──────────────┘ └──────┬───────┘ │ │
│ │ │ │ │
│ │ ┌──────▼───────┐ │ │
│ │ │ Local LLM │ │ │
│ │ │ (llama3.2) │ │ │
│ │ └──────────────┘ │ │
│ │ │ │
│ └─────────────────────────────────────────────────────────────┘ │
│ │
│ 🔒 100% Private - Data never leaves your machine │
│ │
└─────────────────────────────────────────────────────────────────────┘
왜 Ollama?
| 장점 | 설명 |
|---|---|
| 🆓 무료 | API 비용이 전혀 없습니다. |
| 🔒 비공개 | 데이터는 사용자 기기에 보관됩니다 |
| 📴 오프라인 | 인터넷 없이 작동 |
| 🎛️ 제어 | 어떤 모델이든 선택하고 설정을 사용자 지정 |
| ⚡ 빠름 | 네트워크 지연 없음 |
1단계: Ollama 설치
macOS
brew install ollama
Linux
curl -fsSL https://ollama.com/install.sh | sh
Windows
ollama.com에서 다운로드
2단계: 서버 시작
ollama serve
다음과 같이 표시되어야 합니다:
Couldn't find '/Users/you/.ollama/id_ed25519'. Generating new private key.
Your new public key is: ssh-ed25519 AAAA...
time=2024-01-05T12:00:00.000Z level=INFO source=server.go msg="Listening on 127.0.0.1:11434"
3단계: 모델 가져오기
새 터미널에서:
# Recommended starter model (3B parameters, fast)
ollama pull llama3.2:3b
# Other popular models
ollama pull qwen3.6:35b-a3b # Latest Qwen — 73.4% SWE-bench, MoE 35B/3B active
ollama pull qwen3.5 # Strong multilingual and coding
ollama pull qwen3-coder:30b # Code-focused with tool calling
ollama pull mistral:7b # Good for code
ollama pull deepseek-r1:14b # Reasoning model
ollama pull devstral:24b # Optimized for coding
ollama pull gemma3:9b # Google's efficient model
ollama pull codellama:13b # Code generation
4단계: 프로젝트에 추가
[dependencies]
adk-model = { version = "2.0.0", features = ["ollama"] }
5단계: 코드에서 사용
use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
// No API key needed!
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;
let agent = LlmAgentBuilder::new("local_assistant")
.instruction("You are a helpful assistant running locally.")
.model(Arc::new(model))
.build()?;
// Use the agent...
Ok(())
}
완전한 작동 예시
use adk_rust::prelude::*;
use adk_rust::Launcher;
use std::sync::Arc;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
dotenvy::dotenv().ok();
// No API key needed!
let model = OllamaModel::new(OllamaConfig::new("llama3.2"))?;
let agent = LlmAgentBuilder::new("ollama_assistant")
.description("Ollama-powered local assistant")
.instruction("You are a helpful assistant running locally via Ollama. Be concise.")
.model(Arc::new(model))
.build()?;
// Run interactive session
Launcher::new(Arc::new(agent)).run().await?;
Ok(())
}
Cargo.toml
[dependencies]
adk-rust = { version = "2.0.0", features = ["ollama"] }
tokio = { version = "1", features = ["full"] }
dotenvy = "0.15"
anyhow = "1.0"
구성 옵션
use adk_model::ollama::{OllamaModel, OllamaConfig};
let config = OllamaConfig::new("llama3.2")
.with_base_url("http://localhost:11434") // Custom server URL
.with_temperature(0.7) // Creativity (0.0-1.0)
.with_max_tokens(2048); // Max response length
let model = OllamaModel::new(config)?;
권장 모델
| 모델 | 크기 | 필요한 RAM | 최적 용도 |
|---|---|---|---|
llama3.2:3b | 3B | 4GB | 빠르고 범용적인 |
llama3.1:8b | 8B | 8GB | 인기 있는 균형 모델 |
qwen3.6:35b-a3b | 35B (3B active) | 24GB | 최고의 agentic coding — 73.4% SWE-bench |
qwen3.5 | 다양함 | 다양함 | 강력한 다국어 및 코딩 |
qwen3-coder:30b | 30B | 19GB | 코드 중심의 툴 호출 |
qwen2.5:7b | 7B | 8GB | 훌륭한 도구 호출, 경량 |
mistral:7b | 7B | 8GB | 코드 및 추론 |
mistral-nemo:12b | 12B | 12GB | 향상된 Mistral (128K context) |
deepseek-r1:14b | 14B | 16GB | 정제된 추론 |
deepseek-r1:32b | 32B | 32GB | 더 큰 추론 모델 |
gemma3:9b | 9B | 10GB | Google의 효율적인 오픈 모델 |
devstral:24b | 24B | 24GB | 코딩에 최적화됨 |
codellama:13b | 13B | 16GB | Code generation |
llama3.3:70b | 70B | 48GB | 최고 품질 |
모델 선택
- 제한된 RAM (8GB)? →
llama3.2:3b - 최고의 에이전트 코딩? →
qwen3.6:35b-a3b(24GB, MoE — 3B만 활성) - 도구 호출이 필요한가요? →
qwen3.5또는qwen3-coder:30b - 코드 작성? →
devstral:24b또는qwen3-coder:30b - 추론이 필요한가요? →
deepseek-r1:14b또는deepseek-r1:32b - 최고 품질? →
llama3.3:70b(48GB+ RAM 필요)
Ollama를 사용한 도구 호출
Ollama는 호환되는 모델과 함께 함수 호출을 지원합니다:
use adk_model::ollama::{OllamaModel, OllamaConfig};
use adk_agent::LlmAgentBuilder;
use adk_tool::FunctionTool;
use std::sync::Arc;
// qwen2.5 has excellent tool calling support
let model = OllamaModel::new(OllamaConfig::new("qwen2.5:7b"))?;
let weather_tool = Arc::new(FunctionTool::new(
"get_weather",
"Get weather for a location",
|_ctx, args| async move {
let location = args.get("location").and_then(|v| v.as_str()).unwrap_or("unknown");
Ok(serde_json::json!({
"location": location,
"temperature": "72°F",
"condition": "Sunny"
}))
},
));
let agent = LlmAgentBuilder::new("weather_assistant")
.instruction("Help users check the weather.")
.model(Arc::new(model))
.tool(weather_tool)
.build()?;
참고: 도구 호출은 로컬 모델과의 안정성을 위해 비스트리밍 모드를 사용합니다.
예시 출력
👤 User: Hello! What can you do?
🤖 Ollama (llama3.2): Hello! I'm a local AI assistant running on your
machine. I can help with:
- Answering questions
- Writing and editing text
- Explaining concepts
- Basic coding help
All completely private - nothing leaves your computer!
문제 해결
"연결 거부됨"
# Make sure Ollama is running
ollama serve
"모델을 찾을 수 없음"
# Pull the model first
ollama pull llama3.2
느린 응답
- 더 작은 모델 사용 (
llama3.1:70b대신llama3.2) - RAM 확보를 위해 다른 애플리케이션 닫기
- 가능하다면 GPU 가속 고려
사용 가능한 모델 확인
ollama list
예제 실행
cargo check -p adk-rust --no-default-features --features ollama
이 Provider를 사용하는 Agent를 시작하기 전에 ollama serve를 실행하고 모델을 가져오세요.
관련 항목
- Model Providers - 클라우드 기반 LLM Provider
- Local Models (mistral.rs) - 네이티브 Rust 추론
이전: ← Model Providers | 다음: Local Models (mistral.rs) →