Skip to content

Commit caeaa0b

Browse files
committed
Fix broken PromptScorer/Classifier Scorer UTs. Pydantic attribute issues are resolved and now UTs pass.
1 parent b64e0e8 commit caeaa0b

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

judgeval/scorers/prompt_scorer.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ class PromptScorer(CustomScorer, BaseModel):
4747
score_type: str
4848
threshold: float = Field(default=0.5)
4949
using_native_model: bool = Field(default=True)
50+
51+
# DO NOT SET THESE FIELDS MANUALLY, THEY ARE SET BY THE SCORE_EXAMPLE METHOD
52+
response: Optional[dict] = None
53+
result: Optional[float] = None
5054

5155
def __init__(
5256
self,
@@ -295,6 +299,7 @@ def __init__(self, name: str, slug: str, conversation: List[dict], options: Mapp
295299
BaseModel.__init__(
296300
self,
297301
name=name,
302+
slug=slug,
298303
score_type=name,
299304
conversation=conversation,
300305
options=options,

tests/scorers/test_prompt_scorer.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import pytest
2+
from pydantic import BaseModel, Field
23
from unittest.mock import MagicMock, AsyncMock
3-
from typing import List, Dict
4+
from typing import List, Dict, Any
45

56
from judgeval.data import Example
67
from judgeval.scorers.prompt_scorer import PromptScorer, ClassifierScorer
@@ -27,6 +28,9 @@ def mock_model():
2728

2829
# Simple implementation of PromptScorer for testing
2930
class SampleScorer(PromptScorer):
31+
32+
model: Any = Field(default=None)
33+
3034
def __init__(self, mock_model, *args, **kwargs):
3135
super().__init__(*args, **kwargs)
3236
self.model = mock_model
@@ -105,6 +109,7 @@ def classifier_options(self):
105109
def test_classifier_init(self, classifier_conversation, classifier_options):
106110
scorer = ClassifierScorer(
107111
name="test_classifier",
112+
slug="test_classifier_slug",
108113
conversation=classifier_conversation,
109114
options=classifier_options
110115
)
@@ -114,6 +119,7 @@ def test_classifier_init(self, classifier_conversation, classifier_options):
114119
def test_build_measure_prompt(self, example, classifier_conversation, classifier_options):
115120
scorer = ClassifierScorer(
116121
name="test_classifier",
122+
slug="test_classifier_slug",
117123
conversation=classifier_conversation,
118124
options=classifier_options
119125
)
@@ -124,6 +130,7 @@ def test_build_measure_prompt(self, example, classifier_conversation, classifier
124130
def test_process_response(self, classifier_conversation, classifier_options):
125131
scorer = ClassifierScorer(
126132
name="test_classifier",
133+
slug="test_classifier_slug",
127134
conversation=classifier_conversation,
128135
options=classifier_options
129136
)
@@ -136,6 +143,7 @@ def test_process_response(self, classifier_conversation, classifier_options):
136143
def test_process_response_invalid_choice(self, classifier_conversation, classifier_options):
137144
scorer = ClassifierScorer(
138145
name="test_classifier",
146+
slug="test_classifier_slug",
139147
conversation=classifier_conversation,
140148
options=classifier_options
141149
)
@@ -147,6 +155,7 @@ def test_process_response_invalid_choice(self, classifier_conversation, classifi
147155
def test_success_check(self, classifier_conversation, classifier_options):
148156
scorer = ClassifierScorer(
149157
name="test_classifier",
158+
slug="test_classifier_slug",
150159
conversation=classifier_conversation,
151160
options=classifier_options
152161
)

0 commit comments

Comments
 (0)