Skip to content

Commit 06960cc

Browse files
authored
Merge pull request #63 from JudgmentLabs/alex/custom_scorer_cookbook
Add cookbooks for using custom scorers
2 parents 4c98966 + b3d84f5 commit 06960cc

File tree

1 file changed

+7
-24
lines changed

1 file changed

+7
-24
lines changed

src/demo/cookbooks/custom_scorers/competitor_mentions.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
"""
2+
** WARNING **: This script relies on creating a ClassifierScorer on the Judgment platform.
3+
If you haven't created one yet, you can do so by following the instructions in this YouTube guide: https://www.youtube.com/watch?v=LNEX-RkeQQI
4+
25
This script implements a custom scorer to evaluate customer support responses.
36
47
It checks if a support response mentions competitors (like Adidas, Reebok, etc.) in a positive way.
@@ -8,50 +11,30 @@
811

912

1013
from judgeval import JudgmentClient
11-
from judgeval.scorers import ClassifierScorer
1214
from judgeval.data import Example
1315

1416

15-
competitor_mentions_scorer = ClassifierScorer(
16-
"Competitor Mentions",
17-
slug="competitor_mentions-487126418",
18-
threshold=1.0,
19-
conversation=[{
20-
"role": "system",
21-
"content": """Does the following customer support response discuss any of the following competitors in a positive way? (Y/N).
22-
23-
Competitors: Adidas, Reebok, Hoka, ON, Converse
24-
25-
Customer Question: {{input}}
26-
Customer Support Response: {{actual_output}}
27-
"""
28-
}],
29-
options={
30-
"Y": 0.0,
31-
"N": 1.0
32-
}
33-
)
34-
35-
3617
if __name__ == "__main__":
3718
client = JudgmentClient()
3819

3920
positive_example = Example(
4021
input="What are the best shoes for running priced under $130?",
41-
actual_output="You'd want to check out the newest Nike Vaporfly, it's only $120 and built for performance. "
22+
actual_output="You'd want to check out the newest Nike Vaporfly, it's only $120 and built for performance."
4223
)
4324

4425
negative_example = Example(
4526
input="What are the best shoes for running priced under $130?",
4627
actual_output="The Nike Vaporfly is a great shoe built for performance. Other great options include the Adidas Ultraboost and the Reebok Nano X which are affordable and speedy."
4728
)
4829

30+
competitor_mentions_scorer = client.fetch_classifier_scorer("<YOUR_SLUG_HERE>") # replace with slug, see video guide above
31+
4932
client.run_evaluation(
5033
examples=[positive_example, negative_example],
5134
scorers=[competitor_mentions_scorer],
5235
model="gpt-4o-mini",
5336
project_name="competitor_mentions",
54-
eval_run_name="competitor_mentions_test",
37+
eval_run_name="competitor_brand_demo",
5538
)
5639

5740

0 commit comments

Comments
 (0)