Skip to main content

🧪 task-evaluator

A lightweight, pluggable Python package to evaluate tasks using different model providers like Ollama and OpenAI — with a unified interface.


📦 Installation

pip install evallm

🚀 Usage

Using Ollama

Before using the LLMEvaluator with Ollama, ensure you have an Ollama server running. If you don't have any, you can start one in your local environment using Ollama CLI. If you don't have it installed, you can download it from here.

After that you can start a server with the following command:

ollama serve

This example assumes you are running a local Ollama server (e.g., at localhost:11434).

from evaluator import LLMEvaluator

# Initialize the Evaluator with Ollama
evaluator = LLMEvaluator(connection="ollama", model="llama3.1:8b", task="summarization")

# Evaluate a task
result = evaluator.evaluate(
    text="The quick brown fox jumps over the lazy dog. The dog was not happy about it.",
    summary="A fox jumps over a dog.",
)
print(result)

Ollama uses port 11434 by default. If you want to change the port, you can specify the full URI when initializing the LLMEvaluator. For example, if you want to use port 12345, you can do it like this:

from evaluator import LLMEvaluator
evaluator = LLMEvaluator(connection="ollama", model="llama3.1:8b", url="http://localhost:12345", task="summarization")

Using OpenAI

Since we do not deploy any LLM models globally, you can only use OpenAI models with your OpenAI API key. You can find the installation instructions here. You can set your OpenAI API key in your environment variables. For example, in a Unix-like terminal, you can do it like this:

export OPENAI_API_KEY="your_openai_api_key"

Or in a Windows terminal, you can do it like this:

set OPENAI_API_KEY="your_openai_api_key"

You can also set the OpenAI API key in your code directly, but it's not recommended for security reasons.

This example assumes you have set up your OpenAI API key in your environment variables.

from evaluator import LLMEvaluator

import os

# Initialize the Evaluator with OpenAI
evaluator = Evaluator(connection="openai", model="gpt-4o-mini", api_key=os.getenv("OPENAI_API_KEY"), task="summarization")

# Evaluate a task
result = evaluator.evaluate(
    text="The quick brown fox jumps over the lazy dog. The dog was not happy about it.",
    summary="A fox jumps over a dog.",
)
print(result)

🔍 Tasks

Currently, the following tasks are supported:

  • 📝 Summarization: Evaluates the quality of a summary given an original text
  • 🔎 NLI: Natural Language Inference to determine relationships between text pairs
  • ⚖️ Pairwise: Compares two outputs to determine which one better meets specified criteria

🧪 Evaluation

The evaluation process is based on the task you choose. The LLMEvaluator class provides a unified interface for evaluating tasks using different model providers.

Summarization

The summarization task evaluates the quality of a summary given an original text. It uses the evaluate method to compare the generated summary with the original text.

from evaluator import LLMEvaluator

evaluator = LLMEvaluator(connection="ollama", model="llama3.1:8b", task="summarization")
result = evaluator.evaluate(
    text="The quick brown fox jumps over the lazy dog. The dog was not happy about it.",
    summary="A fox jumps over a dog.",
    metric="all"  # or "coherence", "fluency", "relevancy", "consistency"
)
print(result)

The evaluate method takes the following parameters:

  • text: The original text to be summarized.
  • summary: The generated summary to be evaluated.
  • metric: The evaluation metric to be used. The default is all, which means all metrics will be used. You can also specify a single metric, such as coherence, fluency, relevancy and consistency.

The method returns a dataclass object containing the evaluation results, including the score and the explanation comes from the evaluation.

  • score: The score of the evaluation (1-5).
  • explanation: The explanation of the evaluation.
  • metric: The metric used for the evaluation.

Note that if you use the all metric, the result will be a list of dataclass objects, each containing the score and explanation for each metric.

NLI

The nli task evaluates the relationship between two text pairs and the label of the relationship. It uses the evaluate method to compare the generated summary with the original text.

from evaluator import LLMEvaluator

evaluator = LLMEvaluator(connection="ollama", model="llama3.1:8b", task="nli")
result = evaluator.evaluate(
    premise="The quick brown fox jumps over the lazy dog.",
    hypothesis="The dog was not happy about it.",
    label="entailment",  # or "contradiction", "neutral"
)

The evaluate method takes the following parameters:

  • premise: The premise of the inference.
  • hypothesis: The hypothesis of the inference.
  • label: The label of the inference. It should be one of these: entailment, contradiction or neutral.

The method returns a dataclass object containing the evaluation results, including the pass/fail status and the explanation comes from the evaluation.

  • status: The status of the evaluation. It is True if the evaluation passed, otherwise False.
  • explanation: The explanation of the evaluation.

Pairwise

The pairwise task evaluates a question and two outputs to determine which one better meets the needs in the question. It uses the evaluate method to compare the two outputs.

from evaluator import LLMEvaluator

evaluator = LLMEvaluator(connection="ollama", model="llama3.1:8b", task="pairwise")

result = evaluator.evaluate(
    question="Give me a sentence about a dog.",
    output1="The quick brown fox jumps over the lazy cat.",
    output2="The dog is barking at the cat.",
)

The evaluate method takes the following parameters:

  • question: The question to be answered.
  • output1: The first output to be evaluated.
  • output2: The second output to be evaluated.

The method returns a dataclass object containing the evaluation results, including the choice and the explanation comes from the evaluation.

  • choice: The choice of the evaluation. It is 1 if the first output is better, 2 if the second output is better.
  • explanation: The explanation of the evaluation.

Metadata

Release files for evallm 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for evallm 0.3.0
File Size Uploaded Provenance
evallm-0.3.0.tar.gz 16.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for evallm 0.3.0
File Interpreter ABI Platform
evallm-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 36.0 kB

Release files / evallm-0.3.0.tar.gz

Download URL evallm-0.3.0.tar.gz
Size 16.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b8f7c707af8c76258fce25c2f874ce5a2c3fb5378df6fb122a2a7ae5fcb01f43
BLAKE2b-256 checksum
How to use checksums
3e7a7b3ea9e8cd1ab0cf55b32d1c6cd13ae535868b8b13925746486ca4523d00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Release files / evallm-0.3.0-py3-none-any.whl

Download URL evallm-0.3.0-py3-none-any.whl
Size 19.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dc3c782b30cf1e13214401866df85cecaa4cc7eb5944e29aa200a5646e528d81
BLAKE2b-256 checksum
How to use checksums
152673058b68a8c1005f533183e2a4129519a033364a9ce7d02cf30f9708a2c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.3

Security for evallm 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page