Các mô hình thị giác chấp nhận hình ảnh cùng với văn bản để mô hình có thể mô tả, phân loại và trả lời các câu hỏi về những gì nó nhìn thấy.
Bắt đầu nhanh
shell
ollama run gemma4 ./image.png whats in this image?Sử dụng với API của Ollama
Cung cấp một mảng images. Các SDK chấp nhận đường dẫn tệp, URL hoặc byte thô trong khi API REST mong đợi dữ liệu hình ảnh được mã hóa base64.
cURL
```shell
# 1. Tải xuống một hình ảnh mẫu
curl -L -o test.jpg "https://upload.wikimedia.org/wikipedia/commons/3/3a/Cat03.jpg"
# 2. Mã hóa hình ảnh
IMG=$(base64 < test.jpg | tr -d '\n')
# 3. Gửi đến 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
# import Path từ pathlib
# Truyền đường dẫn đến hình ảnh
path = input('Please enter the path to the image: ')
# Bạn cũng có thể truyền dữ liệu hình ảnh được mã hóa base64
# img = base64.b64encode(Path(path).read_bytes()).decode()
# hoặc các byte thô
# 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)
```