Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<dependency>
<groupId>com.judgmentlabs</groupId>
<artifactId>judgeval-java</artifactId>
<version>0.2.3</version>
<version>0.3.0</version>
<exclusions>
<exclusion>
<groupId>io.opentelemetry</groupId>
Expand Down
134 changes: 134 additions & 0 deletions examples/src/main/java/examples/v1_quick_start/V1QuickStart.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package examples.v1_quick_start;

import com.judgmentlabs.judgeval.data.Example;
import com.judgmentlabs.judgeval.v1.JudgmentClient;
import com.judgmentlabs.judgeval.v1.scorers.built_in.AnswerCorrectnessScorer;
import com.judgmentlabs.judgeval.v1.scorers.built_in.FaithfulnessScorer;
import com.judgmentlabs.judgeval.v1.scorers.custom_scorer.CustomScorer;
import com.judgmentlabs.judgeval.v1.scorers.prompt_scorer.PromptScorer;
import com.judgmentlabs.judgeval.v1.tracer.Tracer;

public class V1QuickStart {
public static void main(String[] args) {
System.out.println("=== Judgeval SDK V1 Quick Start ===\n");

System.out.println("1. Initialize JudgmentClient");
JudgmentClient client = JudgmentClient.builder()
.apiKey(System.getenv("JUDGMENT_API_KEY"))
.organizationId(System.getenv("JUDGMENT_ORG_ID"))
.build();
System.out.println(" Client initialized\n");

System.out.println("2. Create and initialize Tracer");
Tracer tracer = client.tracer().create()
.projectName("quickstart-project")
.enableEvaluation(true)
.build();
tracer.initialize();
System.out.println(" Tracer initialized for project: quickstart-project\n");

System.out.println("3. Use Tracer for distributed tracing");
tracer.span("example-operation", () -> {
tracer.setLLMSpan();
tracer.setInput("What is the capital of France?");

String llmOutput = "The capital of France is Paris.";

tracer.setOutput(llmOutput);
System.out.println(" Traced operation with input/output");

System.out.println();

System.out.println("4. Access PromptScorer (fetch existing)");
try {
PromptScorer existingScorer = client.scorers()
.promptScorer()
.get("example-scorer");
System.out.println(" Retrieved PromptScorer: " + existingScorer.getName());
} catch (Exception e) {
System.out.println(" Note: Scorer 'example-scorer' not found (expected for first run)");
}
System.out.println();

System.out.println("5. Create new PromptScorer");
PromptScorer newScorer = client.scorers()
.promptScorer()
.create()
.name("kindness-scorer")
.prompt("Did the assistant respond kindly and respectfully?")
.threshold(0.7)
.build();
System.out.println(" Created PromptScorer: " + newScorer.getName());
System.out.println(" Threshold: " + newScorer.getThreshold());
System.out.println();

System.out.println("6. Use TracePromptScorer");
try {
PromptScorer traceScorer = client.scorers()
.tracePromptScorer()
.create()
.name("trace-quality-scorer")
.prompt("Does the entire trace show high quality reasoning?")
.threshold(0.8)
.build();
System.out.println(" Created TracePromptScorer: " + traceScorer.getName());
} catch (Exception e) {
System.out.println(" TracePromptScorer creation demo");
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This try-catch block is unnecessary. Creating a scorer using the builder pattern (create()...build()) is a local operation that does not perform I/O and is not expected to throw an exception. This block appears to be a copy-paste from the example for fetching an existing scorer, which does perform a network request. Removing the try-catch will make the code cleaner.

            PromptScorer traceScorer = client.scorers()
                    .tracePromptScorer()
                    .create()
                    .name("trace-quality-scorer")
                    .prompt("Does the entire trace show high quality reasoning?")
                    .threshold(0.8)
                    .build();
            System.out.println("   Created TracePromptScorer: " + traceScorer.getName());

System.out.println();

System.out.println("7. Use CustomScorer");
CustomScorer customScorer = client.scorers()
.customScorer()
.get("my-custom-scorer", "MyCustomScorerClass");
System.out.println(" Created CustomScorer: " + customScorer.getName());
System.out.println();

System.out.println("8. Use Built-in Scorers");
AnswerCorrectnessScorer correctnessScorer = client.scorers()
.builtIn()
.answerCorrectness()
.threshold(0.8)
.build();
System.out.println(" Created AnswerCorrectnessScorer with threshold: "
+ correctnessScorer.getThreshold());

FaithfulnessScorer faithfulnessScorer = client.scorers()
.builtIn()
.faithfulness()
.build();
System.out.println(" Created FaithfulnessScorer with default threshold: "
+ faithfulnessScorer.getThreshold());
System.out.println();

System.out.println("9. Run Evaluation");

System.out.println("10. Complete workflow example");
tracer.span("complete-llm-call", () -> {
tracer.setLLMSpan();
tracer.setInput("Explain quantum computing in simple terms");

String response = "Quantum computing uses quantum mechanics to process information...";

tracer.setOutput(response);

Example evaluationExample = Example.builder()
.property("input", "Explain quantum computing in simple terms")
.property("actual_output", response)
.property("expected_output", "A clear, simple explanation")
.build();
tracer.asyncEvaluate(client.scorers().builtIn().answerCorrectness().build(), evaluationExample);

System.out.println(" Traced LLM call with evaluation example ready");
});
System.out.println();
});

try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using Thread.sleep() to wait for asynchronous operations to complete is unreliable. The tracer might not have finished sending all data within the 10-second window, or the sleep might be unnecessarily long. Use the Tracer's built-in forceFlush() method to ensure all buffered spans are sent before the application exits.

        // Wait for async traces to be exported before exiting.
        tracer.forceFlush(10000);


}
}
2 changes: 1 addition & 1 deletion judgeval-java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.judgmentlabs</groupId>
<artifactId>judgeval-java</artifactId>
<version>0.2.4</version>
<version>0.3.0</version>
<packaging>jar</packaging>
<name>Judgeval Java</name>
<description>Java SDK for Judgeval</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
import com.judgmentlabs.judgeval.data.APIScorerType;
import com.judgmentlabs.judgeval.scorers.APIScorer;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* AnswerCorrectnessScorer scorer = AnswerCorrectnessScorer.create();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* AnswerCorrectnessScorer scorer = client.scorers().builtIn().answerCorrectness().build();
* }</pre>
*/
@Deprecated
public class AnswerCorrectnessScorer extends APIScorer {
public AnswerCorrectnessScorer() {
super(APIScorerType.ANSWER_CORRECTNESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
import com.judgmentlabs.judgeval.data.APIScorerType;
import com.judgmentlabs.judgeval.scorers.APIScorer;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* AnswerRelevancyScorer scorer = AnswerRelevancyScorer.create();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* AnswerRelevancyScorer scorer = client.scorers().builtIn().answerRelevancy().build();
* }</pre>
*/
@Deprecated
public class AnswerRelevancyScorer extends APIScorer {
public AnswerRelevancyScorer() {
super(APIScorerType.ANSWER_RELEVANCY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@
import com.judgmentlabs.judgeval.data.APIScorerType;
import com.judgmentlabs.judgeval.scorers.APIScorer;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* DerailmentScorer scorer = DerailmentScorer.create();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* DerailmentScorer scorer = client.scorers().builtIn().derailment().build();
* }</pre>
*/
@Deprecated
public class DerailmentScorer extends APIScorer {
public DerailmentScorer() {
super(APIScorerType.DERAILMENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
import com.judgmentlabs.judgeval.data.APIScorerType;
import com.judgmentlabs.judgeval.scorers.APIScorer;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* FaithfulnessScorer scorer = FaithfulnessScorer.create();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* FaithfulnessScorer scorer = client.scorers().builtIn().faithfulness().build();
* }</pre>
*/
@Deprecated
public class FaithfulnessScorer extends APIScorer {
public FaithfulnessScorer() {
super(APIScorerType.FAITHFULNESS);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@
import com.judgmentlabs.judgeval.data.APIScorerType;
import com.judgmentlabs.judgeval.scorers.APIScorer;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* InstructionAdherenceScorer scorer = InstructionAdherenceScorer.create();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* InstructionAdherenceScorer scorer = client.scorers().builtIn().instructionAdherence().build();
* }</pre>
*/
@Deprecated
public class InstructionAdherenceScorer extends APIScorer {
public InstructionAdherenceScorer() {
super(APIScorerType.INSTRUCTION_ADHERENCE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,22 @@
* Server-hosted custom scorer representation for enqueue payloads.
* Instances serialize into ExampleEvaluationRun.custom_scorers with score_type
* "Custom", server_hosted=true, and optional class_name for server routing.
*
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* CustomScorer scorer = CustomScorer.get("my-scorer");
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* CustomScorer scorer = client.scorers().customScorer().get("my-scorer");
* }</pre>
*/
@Deprecated
public class CustomScorer extends APIScorer {
public CustomScorer() {
super(APIScorerType.CUSTOM);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
import com.judgmentlabs.judgeval.exceptions.JudgmentAPIError;
import com.judgmentlabs.judgeval.internal.api.models.ScorerConfig;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* PromptScorer scorer = PromptScorer.get("my-scorer");
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* PromptScorer scorer = client.scorers().promptScorer().get("my-scorer");
* }</pre>
*/
@Deprecated
public class PromptScorer extends BasePromptScorer {

public PromptScorer(String name, String prompt, double threshold, Map<String, Double> options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
import com.judgmentlabs.judgeval.exceptions.JudgmentAPIError;
import com.judgmentlabs.judgeval.internal.api.models.ScorerConfig;

/**
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* TracePromptScorer scorer = TracePromptScorer.get("my-scorer");
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* PromptScorer scorer = client.scorers().tracePromptScorer().get("my-scorer");
* }</pre>
*/
@Deprecated
public class TracePromptScorer extends BasePromptScorer {

public TracePromptScorer(String name, String prompt, double threshold, Map<String, Double> options) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,30 @@
/**
* Main tracer for Judgment Labs distributed tracing and evaluation.
*
* @deprecated Use {@link com.judgmentlabs.judgeval.v1.JudgmentClient} instead.
*
* <p>
* Migration example:
*
* <pre>{@code
* // Old way:
* Tracer tracer = Tracer.createDefault("my-project");
* tracer.initialize();
*
* // New way:
* JudgmentClient client = JudgmentClient.builder().build();
* Tracer tracer = client.tracer().create()
* .projectName("my-project")
* .build();
* tracer.initialize();
* }</pre>
*
* @see TracerConfiguration
* @see SpanExporter
* @see com.judgmentlabs.judgeval.scorers.BaseScorer
* @see com.judgmentlabs.judgeval.data.Example
*/
@Deprecated
public final class Tracer extends BaseTracer {

private Tracer(TracerConfiguration configuration, ISerializer serializer, boolean shouldInitialize) {
Expand Down
Loading
Loading