Ollama
AI bot 중의 하나인 Ollama의 설치 및 간단한 사용법에 대해서 설명드립니다.
Ollama는 무료 이면서 API를 제공함으로 사내 자체 구축이나 간단한 서비스 테스트용으로 사용하기 적합합니다.
또한 다양한 모델을 사용함으로서 그때 그때 필요시 모델을 교체하여 사용함으로서 확장이 좋습니다.
다운로드
기본 명령어
명령어 | 설명 |
---|---|
ollama run [모델명] |
해당 모델을 로컬에서 실행 (대화 시작) |
ollama list |
다운로드된 모델 목록 확인 |
ollama pull [모델명] |
모델 다운로드 (예: mistral , llama3 ) |
ollama create [이름] -f Modelfile |
커스텀 모델 생성 |
ollama show [모델명] |
해당 모델의 상세 정보 확인 |
ollama delete [모델명] |
모델 삭제 |
ollama serve |
Ollama API 서버 실행 (기본 포트: 11434 ) |
ollama help |
전체 명령어 목록 보기 |
LIST
ollama에 세팅된 model 확인
ollama list
PULL
만약 필요한 model이 없을 경우 model을 가져오면 된다.
아래 링크를 클릭하면 pull 가능한 다양한 모델들을 확인할 수 있습니다. Ollama Library
ollama pull nomic-embed-text
RUN
ollama run [model 명]
ollama run gemma3
>>> Send a message (/? for help)
ollama 가 실행되면 command line이 활성화 된다. 이곳에서 채팅을 하게 되면 됩다.
API
ollama 가 세팅 되면 REST API를 기본포트(11434)로 제공합니다.
http://localhost:11434/
주요 API
HTTP | 엔드포인트 | 설명 |
---|---|---|
POST |
/api/generate |
LLM 응답 생성 |
POST |
/api/embeddings |
텍스트 임베딩 벡터 생성 |
GET |
/api/tags |
설치된 모델 목록 가져오기 |
POST |
/api/pull |
모델 다운로드 (pull) |
DELETE |
/api/delete |
모델 삭제 |
예제
1. 텍스트 응답 (Generate)
- 요청
POST /api/generate
Content-Type: application/json
{
"model": "mistral",
"prompt": "라라벨에서 SEO 설정은 어떻게 하나요?",
"stream": false
}
- 응답
{
"response": "라라벨에서는 config/views.php 파일에서..."
}
2. 텍스트 임베딩 (Embedding)
- 요청
POST /api/embeddings
Content-Type: application/json
{
"model": "nomic-embed-text",
"prompt": "배송은 얼마나 걸리나요?"
}
- 응답
{
"embedding": [0.1234, -0.4523, ...]
}
3. 모델 리스트
- 요청
GET /api/tags
- 응답
{
"models": [
{
"name": "mistral",
"modified_at": "2024-06-01T12:00:00Z",
"size": 4385600000
}
]
}
4. 모델 다운로드
- 요청
POST /api/pull
Content-Type: application/json
{
"name": "mistral"
}
5. 모델 삭제
- 요청
DELETE /api/delete
Content-Type: application/json
{
"name": "mistral"
}
Node.js 예제
const axios = require('axios');
async function askOllama(question) {
const res = await axios.post('http://localhost:11434/api/generate', {
model: 'mistral',
prompt: question,
stream: false
});
console.log('답변:', res.data.response);
}
askOllama('Ollama는 어떤 구조인가요?');