text stringlengths 0 59.1k |
|---|
scorer: createModerationScorer({ model: moderationModel, threshold: 0.5 }), |
}, |
keyword: { |
scorer: keywordScorer, |
params: { keyword: "refund" }, |
}, |
}, |
}, |
}); |
``` |
### LLM Judge for Helpfulness |
```ts |
import { Agent, buildScorer } from "@voltagent/core"; |
import { openai } from "@ai-sdk/openai"; |
import { z } from "zod"; |
const HELPFULNESS_SCHEMA = z.object({ |
score: z.number().min(0).max(1), |
reason: z.string(), |
}); |
const helpfulnessScorer = buildScorer({ |
id: "helpfulness", |
label: "Helpfulness", |
}) |
.score(async ({ payload }) => { |
const agent = new Agent({ |
name: "helpfulness-judge", |
model: openai("gpt-4o-mini"), |
instructions: "You rate responses for helpfulness", |
}); |
const prompt = `Rate the response for clarity, accuracy, and helpfulness. |
User Input: ${payload.input} |
Assistant Response: ${payload.output} |
Provide a score from 0 to 1 with an explanation.`; |
const response = await agent.generateObject(prompt, HELPFULNESS_SCHEMA); |
const rawResults = (payload as any).results?.raw ?? {}; |
rawResults.helpfulnessJudge = response.object; |
return { |
score: response.object.score, |
metadata: { reason: response.object.reason }, |
}; |
}) |
.reason(({ results }) => { |
const judge = results.raw?.helpfulnessJudge as { reason?: string }; |
return { reason: judge?.reason ?? "No explanation provided." }; |
}) |
.build(); |
const agent = new Agent({ |
name: "support", |
model: openai("gpt-4o"), |
eval: { |
sampling: { type: "ratio", rate: 0.1 }, // 10% sampling |
scorers: { |
helpfulness: { scorer: helpfulnessScorer }, |
}, |
}, |
}); |
``` |
### Multiple Scorers with Different Sampling |
```ts |
const agent = new Agent({ |
name: "support", |
model: openai("gpt-4o"), |
eval: { |
triggerSource: "production", |
environment: "prod-us-east", |
sampling: { type: "ratio", rate: 1 }, // default: score everything |
scorers: { |
moderation: { |
scorer: createModerationScorer({ model, threshold: 0.5 }), |
sampling: { type: "ratio", rate: 1 }, // always run |
}, |
answerCorrectness: { |
scorer: createAnswerCorrectnessScorer(), |
sampling: { type: "ratio", rate: 0.05 }, // 5% (expensive) |
params: (payload) => ({ |
expectedAnswer: lookupExpectedAnswer(payload.input), |
}), |
}, |
keyword: { |
scorer: keywordScorer, |
params: { keyword: "refund" }, |
sampling: { type: "ratio", rate: 1 }, // cheap, always run |
}, |
}, |
}, |
}); |
``` |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.