Skip to content

비전 모델은 텍스트와 함께 이미지를 입력받아, 모델이 이미지의 내용을 설명하고 분류하며 관련 질문에 답변할 수 있도록 합니다.

빠른 시작

shell
ollama run gemma4 ./image.png whats in this image?

Ollama API 사용법

images 배열을 제공하세요. SDK는 파일 경로, URL 또는 원시 바이트를 지원하는 반면, REST API는 base64로 인코딩된 이미지 데이터를 요구합니다.

cURL

```shell
# 1. 샘플 이미지 다운로드
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"

# 2. 이미지 인코딩
IMG=$(base64 < test.jpg | tr -d '\n')

# 3. Ollama로 전송
curl -X POST http://localhost:11434/api/chat \
-H "Content-Type: application/json" \
-d '{
    "model": "gemma4",
    "messages": [{
    "role": "user",
    "content": "What is in this image?",
    "images": ["'"$IMG"'"]
    }],
    "stream": false
}'
```

Python

```python
from ollama import chat
# from pathlib import Path

# 이미지 경로를 입력하세요
path = input('Please enter the path to the image: ')

# base64로 인코딩된 이미지 데이터도 입력할 수 있습니다
# img = base64.b64encode(Path(path).read_bytes()).decode()
# 또는 원시 바이트
# img = Path(path).read_bytes()

response = chat(
  model='gemma4',
  messages=[
    {
      'role': 'user',
      'content': 'What is in this image? Be concise.',
      'images': [path],
    }
  ],
)

print(response.message.content)
```

JavaScript

```javascript
import ollama from 'ollama'

const imagePath = '/absolute/path/to/image.jpg'
const response = await ollama.chat({
  model: 'gemma4',
  messages: [
    { role: 'user', content: 'What is in this image?', images: [imagePath] }
  ],
  stream: false,
})

console.log(response.message.content)
```