Package dev.braintrust
Class Braintrust
java.lang.Object
dev.braintrust.Braintrust
Main entry point for the Braintrust SDK.
This class provides access to all Braintrust functionality. Most users will interact with a
singleton instance via get(), though you can create independent instances if needed.
The Braintrust instance also provides methods for enabling Braintrust in open telemetry builders.
Additionally, vendor-specific instrumentation or functionality is provided by
Braintrust<Vendor Name>. E.g. BraintrustOpenAI, BraintrustAnthropic, etc.
-
Method Summary
Modifier and TypeMethodDescriptionconfig()<INPUT,OUTPUT>
Eval.Builder<INPUT,OUTPUT> Create a new eval builder<INPUT,OUTPUT>
Dataset<INPUT,OUTPUT> fetchDataset(String datasetName) <INPUT,OUTPUT>
Dataset<INPUT,OUTPUT> fetchDataset(String datasetName, String datasetVersion) <INPUT,OUTPUT>
Scorer<INPUT,OUTPUT> fetchScorer(String scorerSlug) Fetch a scorer from Braintrust by slug, using the default project from configuration.<INPUT,OUTPUT>
Scorer<INPUT,OUTPUT> fetchScorer(String scorerSlug, String version) Fetch a scorer from Braintrust by slug, using the default project from configuration.<INPUT,OUTPUT>
Scorer<INPUT,OUTPUT> fetchScorer(String projectName, String scorerSlug, String version) Fetch a scorer from Braintrust by project name and slug.static Braintrustget()get or create the global braintrust instance.static Braintrustget(BraintrustConfig config) get or create the global braintrust instance from the given configstatic Braintrustof(BraintrustConfig config) Create a new Braintrust instance from the given configio.opentelemetry.api.OpenTelemetryQuick start method that sets up global OpenTelemetry with this Braintrust.io.opentelemetry.api.OpenTelemetryopenTelemetryCreate(boolean registerGlobal) Quick start method that sets up OpenTelemetry with this Braintrust.voidopenTelemetryEnable(io.opentelemetry.sdk.trace.SdkTracerProviderBuilder tracerProviderBuilder, io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder loggerProviderBuilder, io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder meterProviderBuilder) Add braintrust to existing open telemetry builders
This method provides the most options for configuring Braintrust and OpenTelemetry.the the URI to the configured braintrust org and project
-
Method Details
-
get
get or create the global braintrust instance. Most users will want to use this method to access the Braintrust SDK. -
get
get or create the global braintrust instance from the given config -
of
Create a new Braintrust instance from the given config -
projectUri
the the URI to the configured braintrust org and project -
openTelemetryCreate
public io.opentelemetry.api.OpenTelemetry openTelemetryCreate()Quick start method that sets up global OpenTelemetry with this Braintrust.
If you're looking for more options for configuring Braintrust/OpenTelemetry, consult the `enable` method. -
openTelemetryCreate
public io.opentelemetry.api.OpenTelemetry openTelemetryCreate(boolean registerGlobal) Quick start method that sets up OpenTelemetry with this Braintrust.
If you're looking for more options for configuring Braintrust and OpenTelemetry, consult the `enable` method. -
openTelemetryEnable
public void openTelemetryEnable(@Nonnull io.opentelemetry.sdk.trace.SdkTracerProviderBuilder tracerProviderBuilder, @Nonnull io.opentelemetry.sdk.logs.SdkLoggerProviderBuilder loggerProviderBuilder, @Nonnull io.opentelemetry.sdk.metrics.SdkMeterProviderBuilder meterProviderBuilder) Add braintrust to existing open telemetry builders
This method provides the most options for configuring Braintrust and OpenTelemetry. If you're looking for a more user-friendly setup, consult the `openTelemetryCreate` methods.
NOTE: if your otel setup does not have any particular builder, pass an instance of the default provider builder. E.g. `SdkMeterProvider.builder()`
NOTE: This method should only be invoked once. Enabling Braintrust multiple times is unsupported and may lead to undesired behavior -
evalBuilder
Create a new eval builder -
fetchDataset
-
fetchDataset
-
fetchScorer
Fetch a scorer from Braintrust by slug, using the default project from configuration.- Parameters:
scorerSlug- the unique slug identifier for the scorer- Returns:
- a Scorer that invokes the remote function
-
fetchScorer
public <INPUT,OUTPUT> Scorer<INPUT,OUTPUT> fetchScorer(String scorerSlug, @Nullable String version) Fetch a scorer from Braintrust by slug, using the default project from configuration.- Parameters:
scorerSlug- the unique slug identifier for the scorerversion- optional version of the scorer to fetch- Returns:
- a Scorer that invokes the remote function
-
fetchScorer
public <INPUT,OUTPUT> Scorer<INPUT,OUTPUT> fetchScorer(String projectName, String scorerSlug, @Nullable String version) Fetch a scorer from Braintrust by project name and slug.- Parameters:
projectName- the name of the project containing the scorerscorerSlug- the unique slug identifier for the scorerversion- optional version of the scorer to fetch- Returns:
- a Scorer that invokes the remote function
-
config
-
apiClient
-
promptLoader
-