Skip to content

Commit 3f088ac

Browse files
committed
support top-level tags and metadata for experiments
1 parent f317d4e commit 3f088ac

2 files changed

Lines changed: 37 additions & 3 deletions

File tree

src/main/java/dev/braintrust/api/BraintrustApiClient.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -707,10 +707,18 @@ record CreateExperimentRequest(
707707
String projectId,
708708
String name,
709709
Optional<String> description,
710-
Optional<String> baseExperimentId) {
710+
Optional<String> baseExperimentId,
711+
Optional<List<String>> tags,
712+
Optional<Map<String, Object>> metadata) {
711713

712714
public CreateExperimentRequest(String projectId, String name) {
713-
this(projectId, name, Optional.empty(), Optional.empty());
715+
this(
716+
projectId,
717+
name,
718+
Optional.empty(),
719+
Optional.empty(),
720+
Optional.empty(),
721+
Optional.empty());
714722
}
715723
}
716724

src/main/java/dev/braintrust/eval/Eval.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ public final class Eval<INPUT, OUTPUT> {
3333
private final @Nonnull Dataset<INPUT, OUTPUT> dataset;
3434
private final @Nonnull Task<INPUT, OUTPUT> task;
3535
private final @Nonnull List<Scorer<INPUT, OUTPUT>> scorers;
36+
private final @Nonnull List<String> tags;
37+
private final @Nonnull Map<String, Object> metadata;
3638

3739
private Eval(Builder<INPUT, OUTPUT> builder) {
3840
this.experimentName = builder.experimentName;
@@ -52,6 +54,8 @@ private Eval(Builder<INPUT, OUTPUT> builder) {
5254
this.dataset = builder.dataset;
5355
this.task = Objects.requireNonNull(builder.task);
5456
this.scorers = List.copyOf(builder.scorers);
57+
this.tags = List.copyOf(builder.tags);
58+
this.metadata = Map.copyOf(builder.metadata);
5559
}
5660

5761
/** Runs the evaluation and returns results. */
@@ -62,7 +66,9 @@ public EvalResult run() {
6266
orgAndProject.project().id(),
6367
experimentName,
6468
Optional.empty(),
65-
Optional.empty()));
69+
Optional.empty(),
70+
tags.isEmpty() ? Optional.empty() : Optional.of(tags),
71+
metadata.isEmpty() ? Optional.empty() : Optional.of(metadata)));
6672
dataset.forEach(datasetCase -> evalOne(experiment.id(), datasetCase));
6773
var experimentUrl =
6874
"%s/experiments/%s"
@@ -163,6 +169,8 @@ public static final class Builder<INPUT, OUTPUT> {
163169
private @Nullable Tracer tracer = null;
164170
private @Nullable Task<INPUT, OUTPUT> task;
165171
private @Nonnull List<Scorer<INPUT, OUTPUT>> scorers = List.of();
172+
private @Nonnull List<String> tags = List.of();
173+
private @Nonnull Map<String, Object> metadata = Map.of();
166174

167175
public Eval<INPUT, OUTPUT> build() {
168176
if (config == null) {
@@ -256,5 +264,23 @@ public final Builder<INPUT, OUTPUT> scorers(Scorer<INPUT, OUTPUT>... scorers) {
256264
this.scorers = List.of(scorers);
257265
return this;
258266
}
267+
268+
/** Sets tags for the experiment. */
269+
public Builder<INPUT, OUTPUT> tags(List<String> tags) {
270+
this.tags = List.copyOf(tags);
271+
return this;
272+
}
273+
274+
/** Sets tags for the experiment (varargs convenience method). */
275+
public Builder<INPUT, OUTPUT> tags(String... tags) {
276+
this.tags = List.of(tags);
277+
return this;
278+
}
279+
280+
/** Sets metadata for the experiment. */
281+
public Builder<INPUT, OUTPUT> metadata(Map<String, Object> metadata) {
282+
this.metadata = Map.copyOf(metadata);
283+
return this;
284+
}
259285
}
260286
}

0 commit comments

Comments
 (0)