Universal library for evaluating AI models
Actively maintained. Last release 3 days ago, commits in 11 of the last 26 weeks. A safe choice.
pip install autoevalsAutoevals
Autoevals is a tool to quickly and easily evaluate AI model outputs.
It bundles together a variety of automatic evaluation methods including:
- LLM-as-a-judge
- Heuristic (e.g. Levenshtein distance)
- Statistical (e.g. BLEU)
Autoevals is developed by the team at Braintrust.
Autoevals uses model-graded evaluation for a variety of subjective tasks including fact checking, safety, and more. Many of these evaluations are adapted from OpenAI's excellent evals project but are implemented so you can flexibly run them on individual examples, tweak the prompts, and debug their outputs.
You can also create your own model-graded evaluations with Autoevals. It's easy to add custom prompts, parse outputs, and manage exceptions.
Requirements
- Python 3.9 or higher
- Compatible with both OpenAI Python SDK v0.x and v1.x
Installation
TypeScript
npm install autoevals
Python
pip install autoevals
Getting started
Use Autoevals to model-grade an example LLM completion using the Factuality prompt.
By default, Autoevals uses your OPENAI_API_KEY environment variable to authenticate with OpenAI's API.
Python
from autoevals.llm import *
import asyncio
# Create a new LLM-based evaluator
evaluator = Factuality()
# Synchronous evaluation
input = "Which country has the highest population?"
output = "People's Republic of China"
expected = "China"
# Using the synchronous API
result = evaluator(output, expected, input=input)
print(f"Factuality score (sync): {result.score}")
print(f"Factuality metadata (sync): {result.metadata['rationale']}")
# Using the asynchronous API
async def main():
result = await evaluator.eval_async(output, expected, input=input)
print(f"Factuality score (async): {result.score}")
print(f"Factuality metadata (async): {result.metadata['rationale']}")
# Run the async example
asyncio.run(main())
TypeScript
import { Factuality } from "autoevals";
(async () => {
const input = "Which country has the highest population?";
const output = "People's Republic of China";
const expected = "China";
const result = await Factuality({ output, expected, input });
console.log(`Factuality score: ${result.score}`);
console.log(`Factuality metadata: ${result.metadata?.rationale}`);
})();