Skip to content

Commit e33b2c5

Browse files
committed
wip : working!
1 parent 0495e7e commit e33b2c5

12 files changed

Lines changed: 2209 additions & 0 deletions

File tree

‎examples/build.gradle‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,18 @@ task runSpringAI(type: JavaExec) {
141141
suspend = false
142142
}
143143
}
144+
145+
146+
task runRemoteEval(type: JavaExec) {
147+
group = 'Braintrust SDK Examples'
148+
description = 'Run the remote eval example'
149+
classpath = sourceSets.main.runtimeClasspath
150+
mainClass = 'dev.braintrust.examples.RemoteEvalExample'
151+
systemProperty 'org.slf4j.simpleLogger.log.dev.braintrust', braintrustLogLevel
152+
debugOptions {
153+
enabled = true
154+
port = 5566
155+
server = true
156+
suspend = false
157+
}
158+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package dev.braintrust.examples;
2+
3+
import com.openai.client.okhttp.OpenAIOkHttpClient;
4+
import com.openai.models.ChatModel;
5+
import com.openai.models.chat.completions.ChatCompletionCreateParams;
6+
import dev.braintrust.Braintrust;
7+
import dev.braintrust.devserver.Devserver;
8+
import dev.braintrust.devserver.RemoteEval;
9+
import dev.braintrust.eval.Scorer;
10+
import dev.braintrust.instrumentation.openai.BraintrustOpenAI;
11+
import java.util.List;
12+
import java.util.concurrent.CountDownLatch;
13+
14+
/** Simple Dev Server for Remote Evals */
15+
public class RemoteEvalExample {
16+
public static void main(String[] args) throws Exception {
17+
var braintrust = Braintrust.get();
18+
var openTelemetry = braintrust.openTelemetryCreate();
19+
var openAIClient = BraintrustOpenAI.wrapOpenAI(openTelemetry, OpenAIOkHttpClient.fromEnv());
20+
21+
RemoteEval<String, String> foodTypeEval =
22+
RemoteEval.<String, String>builder()
23+
.name("food-type-classifier")
24+
.config(braintrust.config())
25+
.taskFunction(
26+
food -> {
27+
if (System.currentTimeMillis() > 0) return "java-fruit";
28+
var request =
29+
ChatCompletionCreateParams.builder()
30+
.model(ChatModel.GPT_4O_MINI)
31+
.addSystemMessage("Return a one word answer")
32+
.addUserMessage(
33+
"What kind of food is " + food + "?")
34+
.maxTokens(50L)
35+
.temperature(0.0)
36+
.build();
37+
var response =
38+
openAIClient.chat().completions().create(request);
39+
return response.choices()
40+
.get(0)
41+
.message()
42+
.content()
43+
.orElse("")
44+
.toLowerCase();
45+
})
46+
.scorers(List.of(Scorer.of("simple_scorer", (expected, result) -> 0.7)))
47+
.build();
48+
49+
Devserver devserver =
50+
Devserver.builder()
51+
.registerEval(foodTypeEval)
52+
.host("localhost") // set to 0.0.0.0 to bind all interfaces
53+
.port(8301)
54+
.build();
55+
56+
System.out.println("Starting Braintrust dev server");
57+
devserver.start();
58+
// await shutdown
59+
CountDownLatch latch = new CountDownLatch(1);
60+
Runtime.getRuntime()
61+
.addShutdownHook(
62+
new Thread(
63+
() -> {
64+
System.out.println("Shutting down...");
65+
devserver.stop();
66+
latch.countDown();
67+
}));
68+
latch.await();
69+
}
70+
}

0 commit comments

Comments
 (0)