Модели зрения принимают изображения вместе с текстом, чтобы модель могла описывать, классифицировать и отвечать на вопросы о том, что она видит.
Быстрый старт
shell
ollama run gemma4 ./image.png whats in this image?Использование через API Ollama
Укажите массив 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)
```