Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pairwise): trace evaluators in evaluateComparitive #682

Merged
merged 1 commit into from
May 13, 2024
Merged
Changes from all commits
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
30 changes: 28 additions & 2 deletions js/src/evaluation/evaluate_comparative.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import {
} from "../schemas.js";
import { shuffle } from "../utils/shuffle.js";
import { AsyncCaller } from "../utils/async_caller.js";
import { type evaluate } from "./index.js";
import { evaluate } from "./index.js";
import pRetry from "p-retry";
import { getCurrentRunTree, traceable } from "../traceable.js";

type ExperimentResults = Awaited<ReturnType<typeof evaluate>>;

Expand Down Expand Up @@ -332,12 +333,37 @@ export async function evaluateComparative(
return result;
}

const tracedEvaluators = options.evaluators.map((evaluator) =>
traceable(
async (
runs: Run[],
example: Example
): Promise<ComparisonEvaluationResultRow> => {
const evaluatorRun = getCurrentRunTree();
const result = await evaluator(runs, example);

// sanitise the payload before sending to LangSmith
evaluatorRun.inputs = { runs: runs, example: example };
evaluatorRun.outputs = result;

return {
...result,
source_run_id: result.source_run_id ?? evaluatorRun.id,
};
},
{
project_name: "evaluators",
dqbd marked this conversation as resolved.
Show resolved Hide resolved
name: evaluator.name || "evaluator",
}
)
);

const promises = Object.entries(runMapByExampleId).flatMap(
([exampleId, runs]) => {
const example = exampleMap[exampleId];
if (!example) throw new Error(`Example ${exampleId} not found.`);

return options.evaluators.map((evaluator) =>
return tracedEvaluators.map((evaluator) =>
caller.call(
evaluateAndSubmitFeedback,
runs,
Expand Down
Loading