Skip to content

Vision-Modelle akzeptieren Bilder zusammen mit Text, sodass das Modell beschreiben, klassifizieren und Fragen zu dem beantworten kann, was es sieht.

Schnellstart

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

Verwendung mit der Ollama-API

Stellen Sie ein images-Array bereit. SDKs akzeptieren Dateipfade, URLs oder Roh-Bytes, während die REST API base64-kodierte Bilddaten erwartet.

cURL

```shell
# 1. Laden Sie ein Beispielbild herunter
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"

# 2. Kodieren Sie das Bild
IMG=$(base64 < test.jpg | tr -d '\n')

# 3. Senden Sie es an 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

# Geben Sie den Pfad zum Bild an
path = input('Please enter the path to the image: ')

# Sie können auch base64-kodierte Bilddaten übergeben
# img = base64.b64encode(Path(path).read_bytes()).decode()
# oder die Roh-Bytes
# 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)
```