-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleChat.java
More file actions
48 lines (38 loc) · 1.74 KB
/
SimpleChat.java
File metadata and controls
48 lines (38 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package examples.simple_chat;
import java.time.Duration;
import com.judgmentlabs.judgeval.Judgeval;
import com.judgmentlabs.judgeval.data.Example;
import com.openai.client.OpenAIClient;
import com.openai.client.okhttp.OpenAIOkHttpClient;
import com.openai.models.ChatModel;
import com.openai.models.chat.completions.ChatCompletionCreateParams;
public class SimpleChat {
public static void main(String[] args) {
var client = Judgeval.builder()
.apiKey(System.getenv("JUDGMENT_API_KEY"))
.organizationId(System.getenv("JUDGMENT_ORG_ID"))
.build();
var tracer = client.tracer().create().projectName("SimpleChat-Java").build();
OpenAIClient otelClient = OpenAIOkHttpClient.fromEnv();
tracer.span("chat.session", () -> {
var req = ChatCompletionCreateParams.builder()
.model(ChatModel.GPT_4O_MINI)
.maxCompletionTokens(512)
.addUserMessage("Say hi.")
.build();
var res = otelClient.chat().completions().create(req);
System.out.println(String.valueOf(res));
tracer.asyncEvaluate(client.scorers().builtIn().answerCorrectness().threshold(0.8).build(),
Example.builder()
.property("input", "What is 2+2?")
.property("actual_output", "4")
.property("expected_output", "4")
.build());
tracer.asyncTraceEvaluate(client.scorers().tracePromptScorer().get("ExampleTraceScorer"));
});
try {
Thread.sleep(Duration.ofSeconds(5).toMillis());
} catch (InterruptedException ignored) {
}
}
}