Ollama Run Model
Ollama runs models using the `ollama run` command.
For example, to run Llama 3.2 and converse with it, you can use the following command:
```bash
ollama run llama3.2
Executing this command will download the `llama3.2` model if it is not already installed:
!(#)
Once the download completes, enter the following command in your terminal to load the `llama3.2` model and start interacting:
```bash
writing manifest success >>> Hello >>> Can you speak Chinese? Yes, I can converse in Chinese. What topics or questions would you like to explore?
To end the conversation, type `/bye` or press Ctrl+D.
You can use `ollama list` to view the installed models:
| NAME | ID | SIZE | MODIFIED |
|---------------|---------------|------------|------------------|
| llama3.2 | baf6a787fdff | 1.3 GB | 4 minutes ago |
The models supported by Ollama are available at: [https://ollama.com/library](https://ollama.com/library)
!(#)
The table below lists some download commands for various models:
| Model | Parameters | Size | Download Command |
|-------------------|--------------|-------------|----------------------------|
| Llama 3.3 | 70B | 43GB | `ollama run llama3.3` |
| Llama 3.2 | 3B | 2.0GB | `ollama run llama3.2` |
| Llama 3.2 | 1B | 1.3GB | `ollama run llama3.2:1b` |
| Llama 3.2 Vision | 11B | 7.9GB | `ollama run llama3.2-vision`|
| Llama 3.2 Vision | 90B | 55GB | `ollama run llama3.2-vision:90b`|
| Llama 3.1 | 8B | 4.7GB | `ollama run llama3.1` |
| Llama 3.1 | 405B | 231GB | `ollama run llama3.1:405b` |
| Phi 4 | 14B | 9.1GB | `ollama run phi4` |
| Phi 3 Mini | 3.8B | 2.3GB | `ollama run phi3` |
| Gemma 2 | 2B | 1.6GB | `ollama run gemma2:2b` |
| Gemma 2 | 9B | 5.5GB | `ollama run gemma2` |
| Gemma 2 | 27B | 16GB | `ollama run gemma2:27b` |
| Mistral | 7B | 4.1GB | `ollama run mistral` |
| Moondream 2 | 1.4B | 829MB | `ollama run moondream` |
| Neural Chat | 7B | 4.1GB | `ollama run neural-chat` |
| Starling | 7B | 4.1GB | `ollama run starling-lm` |
| Code Llama | 7B | 3.8GB | `ollama run codellama` |
| Llama 2 Uncensored| 7B | 3.8GB | `ollama run llama2-uncensored`|
| LLaVA | 7B | 4.5GB | `ollama run llava` |
| Solar | 10.7B | 6.1GB | `ollama run solar` |
* * *
## Using Models via Python SDK
If you wish to integrate Ollama into your Python code, you can utilize Ollama's Python SDK to load and run models.
### 1. Install the Python SDK
First, install the Ollama Python SDK by running the following command in your terminal:
```bash
pip install ollama
### 2. Write a Python Script
Next, you can use Python code to load and interact with the model.
Here is a simple Python script example demonstrating how to generate text using the `llama3.2` model:
## Example
```python
import ollama
response = ollama.generate(
model="llama3.2", # Model name
prompt="Who are you?" # Prompt text
)
print(response)
### 3. Run the Python Script
Run your Python script in the terminal:
```bash
python test.py
You will see the response returned by the model based on your input.
### 4. Conversational Mode
## Example
```python
from ollama import chat
response = chat(
model="llama3.2",
messages=[
{"role": "user", "content": "Why is the sky blue?"}
]
)
print(response.message.content)
This code engages in a conversation with the model and prints out its reply.
### 5. Streaming Responses
## Example
```python
from ollama import chat
stream = chat(
model="llama3.2",
messages=[{"role": "user", "content": "Why is the sky blue?"}],
stream=True
)
for chunk in stream:
print(chunk, end="", flush=True)
This code receives responses from the model in a streaming fashion, which is suitable for handling large amounts of data.
YouTip