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

Checks evaluator plugin returns multiple scores. #1370

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
45 changes: 28 additions & 17 deletions js/plugins/checks/src/evaluation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ export function checksEvaluators(
}
);

// Individual evaluators, one per configured metric.
const evaluators = policy_configs.map((policy_config) => {
return createPolicyEvaluator(projectId, auth, ai, policy_config);
return createPolicyEvaluator(projectId, auth, ai, [policy_config], policy_config.type as string);
});

// Single evaluator instnace with all configured policies.
evaluators.push(createPolicyEvaluator(projectId, auth, ai, policy_configs, "all_policies"))

return evaluators;
}

Expand All @@ -104,15 +108,15 @@ function createPolicyEvaluator(
projectId: string,
auth: GoogleAuth,
ai: Genkit,
policy_config: ChecksEvaluationMetricConfig
policy_config: ChecksEvaluationMetricConfig[],
name: string,
): EvaluatorAction {
const policyType = policy_config.type as string;

return ai.defineEvaluator(
{
name: `checks/${policyType.toLowerCase()}`,
displayName: policyType,
definition: `Evaluates text against the Checks ${policyType} policy.`,
name: `checks/${name.toLowerCase()}`,
displayName: name,
definition: `Evaluates text against the Checks ${name} policy.`,
},
async (datapoint: BaseEvalDataPoint) => {
const partialRequest = {
Expand All @@ -121,10 +125,12 @@ function createPolicyEvaluator(
content: datapoint.output as string,
},
},
policies: {
policy_type: policy_config.type,
threshold: policy_config.threshold,
},
policies: policy_config.map(config => {
return {
policy_type: config.type,
threshold: config.threshold,
}
}),
};

const response = await checksEvalInstance(
Expand All @@ -134,15 +140,20 @@ function createPolicyEvaluator(
ResponseSchema
);

return {
evaluation: {
score: response.policyResults[0].score,
const evaluationResults = response.policyResults.map(result => {
return {
id: result.policyType,
score: result.score,
details: {
reasoning: response.policyResults[0].violationResult,
reasoning: `Status ${result.violationResult}`,
},
},
testCaseId: datapoint.testCaseId,
};
}
});

return {
evaluation: evaluationResults,
testCaseId: datapoint.testCaseId
}
HunterHeston marked this conversation as resolved.
Show resolved Hide resolved
}
);
}
Expand Down
Loading