# Ollama & OpenWebUI Setup Guide: Run LLMs Locally with Ease

## Introduction

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742551937701/d09cd498-e42e-43db-8ddb-24ce9fadc966.png align="center")

Image source : [https://www.packetswitch.co.uk/](https://www.packetswitch.co.uk/)

Ollama is an open-source tool designed to help developers run and develop large language models (LLMs) locally on their machines. It enables efficient AI model execution without relying on cloud-based services, ensuring cost-effectiveness, privacy, and performance.

🔗 **Download Ollama**: [Ollama Official Website](https://ollama.com/download)

---

## Ollama Commands

### 1\. Running a Model:

```bash
$ ollama run <model-name>
```

* Checks if the model is available locally; if not, it pulls it from the Ollama model registry and run the model
    

### 2\. Starting the API Server:

```bash
$ ollama serve
```

* Runs the Ollama API on port **11434**.
    

### 3\. Verifying Model Integrity:

```bash
$ ollama check <model-name>
```

* Uses SHA-256 digest to confirm authenticity.
    

### 4\. Listing Available Models:

```bash
$ ollama list
```

* Displays the locally available models.
    

### 5\. Pulling a Model from the Registry:

```bash
$ ollama pull <model-name>
```

* Downloads a model from the Ollama registry.
    

### 6\. Pushing a Model to the Registry:

```bash
$ ollama push username:<model-name>
```

* Uploads a custom model to the Ollama registry.
    

### 7\. Creating a Custom Model:

```bash
$ ollama create my_custom_model -f ./Modelfile
```

* Builds a custom model based on the configuration in a **Modelfile**.
    

### 8\. Check avilable commands:

```bash
$ /?

Available Commands:
  /set            Set session variables
  /show           Show model information
  /load <model>   Load a session or model
  /save <model>   Save your current session
  /clear          Clear session context
  /bye            Exit
  /?, /help       Help for a command
  /? shortcuts    Help for keyboard shortcuts
```

---

## REST API Endpoints

Ollama provides REST API endpoints to interact with models programmatically.

### Ollama REST API endpoints :

```http
POST /api/generate   # Generates responses (supports streaming option).
POST /api/chat       # Chat Interaction - Handles chat-based interactions.
GET /api/models      # Returns a list of installed models.
POST /api/pull       # Pulls a model from the Ollama registry
POST /api/push.      # Uploads a locally built model to the Ollama registry.
GET /api/status.     # Returns the current status of the running Ollama API.
```

---

## Creating and Managing Custom Models

### Creating a Custom Image

To create a custom model, follow these steps:

1. Create a **Modelfile** with the necessary configurations:
    

```plaintext
FROM BASE_MODEL:TAG
PARAMETER temperature 0.2
SYSTEM "You are a helpful assistant."
MESSAGE "Welcome to Ollama!"
```

2. Build the model:
    

```bash
$ ollama create my_custom_model -f ./Modelfile
```

3. Pushing a Custom Model to the Registry
    

```bash
$ ollama push my_custom_model
```

* This command uploads the locally built model to the Ollama registry.
    

### Pulling a Model from the Ollama Registry

```bash
$ ollama pull username:my_custom_model
```

* Downloads and installs a model from the Ollama registry for local use.
    

---

## Using Ollama with Python

Ollama can be integrated with Python to generate AI-powered responses. Below is an example using the `requests` library:

```python
import ollama

response = ollama.generate(
    model="deepseek-r1",
    prompt="What is Deepseek?"
)

print(response["response"])
```

* This script sends a request to the Ollama API running locally, generates a response using the specified model, and prints the output.
    

---

## Setting Up OpenWebUI with Ollama

[OpenWebUI](https://github.com/OpenWebUI/OpenWebUI) is a user-friendly interface that enhances the experience of interacting with LLMs like Ollama.

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742552151631/0dbcea52-0b5f-4583-8fcc-5d7fdbdc68a2.png align="center")

### Running OpenWebUI with Docker

You can easily set up OpenWebUI using Docker with the following command:

```bash
$ docker run -d --name open-webui -p 3000:3000 -e OLLAMA_BASE_URL=http://localhost:11434 --restart always ghcr.io/open-webui/open-webui:main
```

* This runs OpenWebUI as a Docker container and connects it to your local Ollama instance.
    
* Access OpenWebUI at `http://localhost:3000`.
    

---

## Conclusion :

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1742552427461/50102451-7beb-4f5a-8a04-6bb3c953a9ae.webp align="center")

Ollama provides a powerful way to run LLMs locally, ensuring privacy, performance, and cost-effectiveness. With its easy-to-use CLI commands, REST API support, Python integration, and OpenWebUI interface, it’s a great tool for developers looking to build AI applications without relying on cloud-based services.

🚀 **Ready to explore Ollama?** Download it today and start running your own AI models locally!

Connect with me on Linkedin: [**Raghul M**](https://www.linkedin.com/in/m-raghul/)

[💬 Hav](https://www.linkedin.com/in/m-raghul/)e questions or feedback? Drop them in the comments below!
