Skip to content

दृष्टि मॉडल पाठ के साथ-साथ छवियों को स्वीकार करते हैं ताकि मॉडल जो कुछ देखता है उसका वर्णन, वर्गीकरण कर सके और उसके बारे में प्रश्नों के उत्तर दे सके।

शुरुआत करें

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

Ollama के API के साथ उपयोग

एक images सरणी प्रदान करें। SDK फ़ाइल पाथ, URL या रॉ बाइट्स को स्वीकार करते हैं जबकि REST API बेस64-एन्कोडेड छवि डेटा की अपेक्षा करता है।

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: ')

# आप बेस64-एन्कोडेड छवि डेटा भी प्रदान कर सकते हैं
# 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)
```