Skip to main content

Overview

ChatOllama provides integration with locally running Ollama models, enabling completely private and offline browser automation without sending data to external APIs.

Basic Usage

Prerequisites

  1. Install Ollama: Download from ollama.com
  2. Pull a model: ollama pull llama3.2
  3. Start Ollama: It runs automatically after installation

Configuration

Required Parameters

str
required
Ollama model name. Popular options:
  • llama3.2: Fast and capable
  • llama3.2:70b: More powerful
  • qwen2.5-coder:32b: Great for web tasks
  • mistral: Alternative option
  • codellama: Coding focused

Client Parameters

str
default:"None"
Ollama server URL. Defaults to http://localhost:11434.
float
default:"None"
Request timeout in seconds.
dict
default:"None"
Additional parameters for the Ollama client.
Options
default:"None"
Ollama-specific options for model behavior.Common options:
  • temperature: Sampling temperature
  • num_predict: Max tokens to generate
  • top_k: Top-K sampling
  • top_p: Top-P sampling
  • repeat_penalty: Repetition penalty

Advanced Usage

Custom Ollama Host

With Ollama Options

Structured Output

Custom Timeout for Large Models

Using Dictionary Options

Setup Guide

macOS

Linux

Windows

  1. Download installer from ollama.com
  2. Run installer
  3. Open terminal and run: ollama pull llama3.2

Docker

Error Handling

Properties

provider

Returns the provider name: "ollama"

name

Returns the model name.

Methods

get_client()

Returns an OllamaAsyncClient instance.

ainvoke()

Asynchronously invoke the model with messages.

Parameters

  • messages (list[BaseMessage]): List of messages
  • output_format (type[T] | None): Optional Pydantic model for structured output

Returns

ChatInvokeCompletion[T] | ChatInvokeCompletion[str] with:
  • completion: Response content (string or structured output)
  • usage: Currently None for Ollama (not tracked)
Ollama does not currently provide token usage information in responses.

For Speed

  • llama3.2 (8B): Fast, good quality
  • qwen2.5-coder (7B): Great for web tasks
  • mistral (7B): Balanced performance

For Quality

  • llama3.2:70b: Best quality, slower
  • qwen2.5-coder:32b: Excellent for browser automation
  • mixtral:8x7b: High quality mixture of experts

For Resource-Constrained

  • llama3.2:3b: Very fast on CPU
  • phi3: Microsoft’s efficient model
  • tinyllama: Minimal resource usage

Performance Tips

  1. GPU Acceleration: Ollama automatically uses GPU if available
  2. Model Size: Smaller models are faster but less capable
  3. num_predict: Limit output tokens for faster responses
  4. Preload Models: Models load faster after first use

Troubleshooting

Ollama Not Running

Model Not Found

Connection Refused

Slow Performance

Benefits of Ollama

  1. Privacy: All data stays on your machine
  2. No API Costs: Free to use
  3. Offline Capable: Works without internet
  4. Fast: Low latency on local hardware
  5. Customizable: Full control over models and parameters

Limitations

  1. No Usage Tracking: Token counts not available
  2. Hardware Dependent: Performance varies by hardware
  3. Model Quality: May not match GPT-4 or Claude for complex tasks
  4. Setup Required: Need to install and manage Ollama