Prompt Chain

Generate and Test Code with Ollama

Two promptfoo examples for Ollama: comparing censored vs uncensored local models, and testing function calling.

Works with ollama

92
Spark score
out of 100
Updated 28 days ago
Version 0.121.18
Models

Add to Favorites

Why it matters

Leverage Ollama's capabilities to automate code generation, review, and debugging processes, streamlining your software development lifecycle.

Outcomes

What it gets done

01

Generate code snippets using Ollama.

02

Review generated code for quality and correctness.

03

Debug code with AI assistance.

04

Integrate Ollama into your existing development pipeline.

Install

Add it to your toolbox

Run in your project directory:

curl -fsSL https://spark.entire.vc/get/pfoo-ollama | bash

Steps

Steps in the chain

01
Install Ollama
02
Pull required models for comparison
03
Pull required models for function calling
04
Run model comparison evaluation
05
Run function calling evaluation
06
View evaluation results

Overview

Ollama

This promptfoo example set has two configs for Ollama: one compares censored versus standard local models on edge-case prompts, the other tests function/tool-calling on a small local model against an OpenAI-compatible format. Use it when evaluating locally-run Ollama models for behavior differences or tool-calling support with promptfoo.

What it does

This directory contains two promptfoo examples demonstrating different Ollama capabilities. The first, Model Comparison, compares different Ollama models (llama4:scout, llama2-uncensored) against OpenAI models using various prompts and assertions - testing uncensored versus standard models, controversial or edge-case questions, whether models refuse legitimate queries, and prompt format differences between Llama and OpenAI styles. The second, Function Calling, demonstrates Ollama's function calling using a tiny 1B-parameter model (llama3.2:1b), testing an OpenAI-compatible tool format with a weather API function example that extracts a location, validated with an is-valid-openai-tools-call assertion.

When to use - and when NOT to

Use this to bootstrap a promptfoo eval against locally-run Ollama models, either to compare model behavior (including uncensored vs standard models) or to test tool/function-calling support on a small local model. It assumes Ollama is already installed and running locally, and requires pulling the specific models used by each example (llama4:scout and llama2-uncensored for the comparison example; llama3.2:1b for the function-calling example) before running.

npx promptfoo@latest init --example ollama
cd ollama

Inputs and outputs

Run the comparison example with npx promptfoo@latest eval (or -c promptfooconfig.yaml explicitly); run the function-calling example with npx promptfoo@latest eval -c promptfooconfig.function-calling.yaml. A successful function-calling run reports a 100% pass rate across 3 test successes, with each test generating a tool call such as a get_current_weather function invoked with location and unit arguments. Supported function-calling models listed in the source include llama3.2:1b, llama3.2:3b, llama3.1, llama3.3, and qwen2.5. Results for either example can be viewed in an interactive web UI via npx promptfoo@latest view, showing side-by-side model outputs, pass/fail status per assertion, and token usage and latency metrics.

Integrations

The directory is structured with a promptfooconfig.yaml for the comparison example, a promptfooconfig.function-calling.yaml for the tool-calling example, a prompts/ folder holding Llama-style and OpenAI-style prompt formats, and a get_current_weather.yaml tool definition. Both examples can be customized: editing prompts, test questions, and assertions for the comparison config, or editing test cities, the tool definition, and target models for the function-calling config.

Who it's for

Developers evaluating locally-run Ollama models - comparing model behavior head-to-head, or validating function/tool-calling support on small models - who want ready-made promptfoo configs instead of writing eval scaffolding from scratch. The repository's own file listing shows the shape of the example: a README.md, the two config files, a prompts/ folder holding llama_prompt.txt and openai_prompt.json, a standalone prompts.txt with additional prompt examples, and get_current_weather.yaml defining the function-calling tool - a small, self-contained layout that is easy to copy into a new project and adapt.

Source README

ollama (Ollama Examples)

This directory contains examples demonstrating different capabilities of Ollama with promptfoo.

You can run this example with:

npx promptfoo@latest init --example ollama
cd ollama

Prerequisites

  1. Install Ollama
  2. Pull the required models:
### For comparison example (default)
ollama pull llama4:scout
ollama pull llama2-uncensored

### For function calling example
ollama pull llama3.2:1b

Available Examples

This directory contains two different Ollama examples:

1. Model Comparison (Default)

Config: promptfooconfig.yaml

Compares different Ollama models (llama4:scout, llama2-uncensored) with OpenAI models using various prompts and assertions.

Running:

npx promptfoo@latest eval

Or with a specific config:

npx promptfoo@latest eval -c promptfooconfig.yaml

What this tests:

  • Compares uncensored vs standard models
  • Tests with controversial/edge-case questions
  • Validates models don't refuse legitimate queries
  • Demonstrates prompt format differences (Llama vs OpenAI)

Tutorial: See the accompanying guide at https://promptfoo.dev/docs/guides/censored-vs-uncensored-ollama/

2. Function Calling

Config: promptfooconfig.function-calling.yaml

Demonstrates Ollama's function calling capabilities using a tiny 1B parameter model.

Running:

npx promptfoo@latest eval -c promptfooconfig.function-calling.yaml

What this tests:

  • Function calling with llama3.2:1b (tiny, fast model)
  • OpenAI-compatible tool format
  • Weather API function example with location extraction
  • Validates tool calls with is-valid-openai-tools-call assertion

Expected output:

✔ Evaluation complete
Pass Rate: 100.00%
Successes: 3

Each test generates a tool call:

[
  {
    "function": {
      "name": "get_current_weather",
      "arguments": "{\"location\":\"Boston\",\"unit\":\"celsius\"}"
    }
  }
]

Supported models: Models with function calling support include llama3.2:1b, llama3.2:3b, llama3.1, llama3.3, and qwen2.5.

Customization

For Comparison Example

Edit the prompts and test cases in promptfooconfig.yaml. You can modify:

  • Models being compared
  • Test questions in the tests section
  • Assertions to validate different behaviors
  • Prompt formats in the prompts/ directory

For Function Calling Example

Edit promptfooconfig.function-calling.yaml to:

  • Change the test cities
  • Modify the tool definition in get_current_weather.yaml
  • Add additional functions
  • Test with different models

File Structure

examples/ollama/
├── README.md                              # This file
├── promptfooconfig.yaml                   # Model comparison (default)
├── promptfooconfig.function-calling.yaml  # Function calling example
├── prompts/
│   ├── llama_prompt.txt                   # Llama-style prompt format
│   └── openai_prompt.json                 # OpenAI chat format
├── prompts.txt                            # Additional prompt examples
└── get_current_weather.yaml               # Tool definition for function calling

Viewing Results

After running an evaluation, view the results in the web UI:

npx promptfoo@latest view

This opens an interactive comparison showing:

  • Side-by-side model outputs
  • Pass/fail status for each assertion
  • Token usage and latency metrics

FAQ

Common questions

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.