Modele wizyjne akceptują obrazy obok tekstu, dzięki czemu model może opisywać, klasyfikować i odpowiadać na pytania dotyczące tego, co widzi.
Szybki start
shell
ollama run gemma4 ./image.png whats in this image?Użycie z API Ollamy
Podaj tablicę images. SDK-y akceptują ścieżki do plików, adresy URL lub surowe bajty, podczas gdy API REST oczekuje danych obrazu zakodowanych w base64.
cURL
```shell
# 1. Pobierz przykładowy obraz
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"
# 2. Zakoduj obraz
IMG=$(base64 < test.jpg | tr -d '\n')
# 3. Wyślij go do Ollamy
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
# Podaj ścieżkę do obrazu
path = input('Please enter the path to the image: ')
# Możesz również podać dane obrazu zakodowane w base64
# img = base64.b64encode(Path(path).read_bytes()).decode()
# lub surowe bajty
# 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)
```