Skip to content

Commit 9f5d515

Browse files
committed
🚧 dealing with the pydantic error by updating the struct to provide a default value
1 parent 4a43c3a commit 9f5d515

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

detectors/common/scheme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ContentAnalysisResponse(BaseModel):
127127
start: int = Field(example=14)
128128
end: int = Field(example=26)
129129
text: str = Field(example="[email protected]")
130-
detection: str = Field(example="Net.EmailAddress")
130+
detection: str = Field(default="detection", example="Net.EmailAddress")
131131
detection_type: str = Field(example="pii")
132132
score: float = Field(example=0.8)
133133
evidences: Optional[List[EvidenceObj]] = Field(

detectors/huggingface/detector.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,16 @@ def process_sequence_classification(self, text, detector_params=None, threshold=
249249
and idx not in all_safe_labels
250250
and label not in all_safe_labels
251251
):
252+
detection_value = getattr(self.model.config, "problem_type", None)
252253
content_analyses.append(
253254
ContentAnalysisResponse(
254255
start=0,
255256
end=len(text),
256-
detection=getattr(self.model.config, "problem_type", None) or "sequence_classification",
257257
detection_type=label,
258258
score=prob,
259259
text=text,
260260
evidences=[],
261+
**({"detection": detection_value} if detection_value is not None else {})
261262
)
262263
)
263264
return content_analyses

0 commit comments

Comments
 (0)