Braintrust Core

0.0.59 · active · verified Sat Apr 11

Braintrust Core is a Python package that provides shared core dependencies for other packages within the Braintrust ecosystem. It is primarily an internal utility library, with user-facing functionality for logging, tracing, evaluations, and CLI workflows typically exposed through the main `braintrust` SDK. The current version is 0.0.59, and it generally follows the release cadence of the broader Braintrust Python SDKs.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the usage of the main `braintrust` SDK for defining and running evaluations. `braintrust-core` is an internal dependency and not typically used directly in user quickstarts. Ensure you also install `autoevals` for scoring functions: `pip install braintrust autoevals`.

import os
from autoevals import LevenshteinScorer
from braintrust import Eval

# Set your Braintrust API key from environment variables
# BRAINTRUST_API_KEY='sk-...' (Replace with your actual key or set in environment)
api_key = os.environ.get('BRAINTRUST_API_KEY', 'YOUR_API_KEY_HERE')

# Define an evaluation
eval_run = Eval(
    "Say Hi Bot",
    data=lambda: [
        {"input": "Foo", "expected": "Hi Foo"},
        {"input": "Bar", "expected": "Hello Bar"},
    ],
    task=lambda input: "Hi " + input,
    scores=[LevenshteinScorer],
    api_key=api_key # Pass API key here or ensure BRAINTRUST_API_KEY env var is set
)

# Run the evaluation
# To run this, you would typically execute it via the Braintrust CLI:
# BRAINTRUST_API_KEY=YOUR_API_KEY braintrust eval your_script_name.py
# Or, to run directly in Python, if your API key is configured:
# result = eval_run.run() 
# print(result)

print("To run this evaluation, set BRAINTRUST_API_KEY and use the Braintrust CLI: braintrust eval <your_script.py>")

view raw JSON →