Skip to content

A hands-on, structured guide to Ollama covering local LLM usage, LangChain integration, REST APIs, tool calling, Ollama Cloud, and advanced experiments with models like Gemma 3 (4B),

Notifications You must be signed in to change notification settings

rajshekharbind/Ollama-Model-Complete--Learning

Repository files navigation

Ollama – Complete Learning

A hands-on, structured guide to Ollama covering local LLM usage, LangChain integration, REST APIs, tool calling, Ollama Cloud, and advanced experiments with models like Gemma 3 (4B), including vision and multimodal workflows.


πŸ“Œ What is Ollama?

Ollama is a platform that allows you to run, manage, and experiment with large language models (LLMs) locally and in the cloud. It provides a simple CLI, REST API, and library support to work with modern open-source models like LLaMA, Gemma, Qwen, Mistral, and more.

Key idea: Local-first AI with optional cloud scalability.


🧠 Why Use Ollama?

  • πŸš€ Run LLMs locally (privacy + speed)
  • πŸ”’ No data leaves your machine (local mode)
  • 🧩 Easy integration with Python, LangChain, REST APIs
  • πŸ› οΈ Built-in support for tool calling & function execution
  • ☁️ Ollama Cloud for scalable inference
  • πŸ§ͺ Perfect for learning, experimentation, and R&D

πŸ“‚ Project Structure

.
β”œβ”€β”€ Ollama.ipynb                    # Core Ollama usage & CLI experiments
β”œβ”€β”€ Ollama using Rest API.ipynb     # REST API calls (generate, chat, models)
β”œβ”€β”€ Ollama Using LangChain.ipynb    # LangChain + Ollama integration
β”œβ”€β”€ Tool Calling.ipynb              # Function / tool calling with Ollama
β”œβ”€β”€ Ollama Cloud.ipynb              # Cloud-based inference concepts
β”œβ”€β”€ Modelfile.txt                   # Custom model configuration
β”œβ”€β”€ Ollama Short notes.docx         # Quick theory notes
β”œβ”€β”€ README.md                       # This documentation

βš™οΈ Ollama Core Concepts

🧾 Common Ollama Commands

πŸ”Ή Ollama CLI Commands

# Check Ollama version
ollama --version

# List available models
ollama list

# Pull a model
ollama pull gemma3:4b

# Run a model interactively
ollama run gemma3:4b

# Run with a prompt
ollama run gemma3:4b "Explain LLMs in simple words"

# Remove a model
ollama rm gemma3:4b

πŸ”Ή Ollama REST API (curl examples)

# Generate text
curl http://localhost:11434/api/generate \
  -d '{"model": "gemma3:4b", "prompt": "What is GenAI?"}'

# Chat API
curl http://localhost:11434/api/chat \
  -d '{"model": "gemma3:4b", "messages": [{"role": "user", "content": "Hello"}]}'

# List models via API
curl http://localhost:11434/api/tags

πŸ”Ή Python (Ollama Library)

from ollama import chat

response = chat(
    model="gemma3:4b",
    messages=[{"role": "user", "content": "Explain tool calling"}]
)
print(response["message"]["content"])

πŸ”Ή LangChain + Ollama

from langchain_community.llms import Ollama

llm = Ollama(model="gemma3:4b")
print(llm.invoke("What is RAG?"))

πŸ”Ή Tool Calling (Conceptual Command)

  • Define tools (functions)
  • Pass tool schema to model
  • Model decides when to call tools

Used for:

  • Calculations
  • API calls
  • Database queries

πŸ”Ή Ollama Cloud (Conceptual Commands)

Prompt β†’ Cloud Endpoint β†’ GPU Inference β†’ Response

Used when:

  • Large models (30B+)
  • High traffic apps
  • Production workloads

1️⃣ Ollama CLI & Library

  • Pull models (ollama pull gemma3:4b)
  • Run models locally (ollama run gemma3:4b)
  • Manage models (list, delete, update)
  • Python library for programmatic access

Benefit: Simple developer experience with production-ready models.


2️⃣ Ollama REST API

Ollama exposes a local REST server:

  • /api/generate
  • /api/chat
  • /api/tags (list models)

Use cases:

  • Backend integration
  • Web apps
  • Microservices

Benefits:

  • Language agnostic
  • Easy to scale
  • Works with Docker & cloud infra

3️⃣ Ollama with LangChain

LangChain enables:

  • Prompt templates
  • Chains & agents
  • Memory
  • Tool usage

Workflow:

User β†’ LangChain β†’ Ollama Model β†’ Response

Benefits:

  • Build RAG pipelines
  • AI agents
  • Conversational memory

πŸ› οΈ Tool Calling with Ollama

Tool calling allows models to:

  • Call Python functions
  • Execute APIs
  • Perform structured reasoning

Examples:

  • Calculator tools
  • Database queries
  • File operations
  • External API calls

Why it matters:

Turns LLMs into AI agents, not just chatbots.


☁️ Ollama Cloud – How Large Models Work in Cloud

How Cloud LLMs Work

  1. User sends prompt
  2. Request hits cloud inference server
  3. Model runs on GPU/TPU
  4. Response streamed back

Benefits of Cloud Models

  • ⚑ High performance GPUs
  • πŸ“ˆ Auto scaling
  • 🧠 Large models (70B+)
  • πŸ”„ No local hardware dependency

Local vs Cloud

Feature Local Ollama Ollama Cloud
Privacy βœ… High ⚠️ Medium
Cost βœ… Low πŸ’° Usage based
Speed ⚑ Fast (small models) πŸš€ Fast (large models)
Offline βœ… Yes ❌ No

πŸ§ͺ Model Experiments – Gemma 3 (4B)

Why Gemma 3 (4B)?

  • Lightweight
  • Fast inference
  • High-quality reasoning
  • Ideal for laptops

Experiments Covered

  • Text generation
  • Instruction following
  • Tool calling compatibility
  • Vision & multimodal prompts (image β†’ text)

πŸ–ΌοΈ Vision & Image β†’ Text (Multimodal)

Supported workflows:

  • Image captioning
  • OCR-like text extraction
  • Visual reasoning

Use cases:

  • Document processing
  • Image understanding
  • AI assistants with vision

πŸ€– Model Capability Matrix

Feature Gemma 3 LLaMA Qwen Mistral
Tool Calling βœ… βœ… βœ… ⚠️
Vision βœ… ❌ ⚠️ ❌
Cloud Support βœ… βœ… βœ… βœ…
RAG Friendly βœ… βœ… βœ… βœ…

πŸ“š Learning Path (Recommended)

Beginner

  1. Ollama CLI basics
  2. Pull & run models
  3. Simple text generation

Intermediate

  1. REST API usage
  2. LangChain integration
  3. Prompt engineering

Advanced

  1. Tool calling
  2. Vision models
  3. RAG pipelines
  4. Cloud deployment

🎯 Benefits of This Setup

  • Learn LLMs practically
  • Build production-ready AI apps
  • No vendor lock-in
  • Works locally & in cloud
  • Ideal for students & professionals

πŸš€ Future Extensions

  • RAG with vector databases
  • Multi-agent systems
  • Fine-tuning custom models
  • Production deployment (Docker, Kubernetes)

Happy Building πŸš€

About

A hands-on, structured guide to Ollama covering local LLM usage, LangChain integration, REST APIs, tool calling, Ollama Cloud, and advanced experiments with models like Gemma 3 (4B),

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published