mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Map an unrecognised classification reply to UNKNOWN 🟥
This commit is contained in:
parent
d0e5aa9e3f
commit
11a498ba4e
2 changed files with 21 additions and 1 deletions
|
|
@ -33,6 +33,14 @@ class ChatGptPropertyTypeClassifier(PropertyTypeClassifier):
|
|||
)
|
||||
raw: dict[str, Any] = json.loads(reply)
|
||||
return {
|
||||
description: PropertyType(raw[description])
|
||||
description: self._to_property_type(raw[description])
|
||||
for description in descriptions
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def _to_property_type(value: Any) -> PropertyType:
|
||||
"""Map a reply value to a PropertyType, defaulting to UNKNOWN."""
|
||||
try:
|
||||
return PropertyType(value)
|
||||
except ValueError:
|
||||
return PropertyType.UNKNOWN
|
||||
|
|
|
|||
|
|
@ -31,3 +31,15 @@ def test_classifies_description_into_property_type() -> None:
|
|||
|
||||
# Assert
|
||||
assert result == {"semi-detached": PropertyType.HOUSE}
|
||||
|
||||
|
||||
def test_unrecognised_category_maps_to_unknown() -> None:
|
||||
# Arrange
|
||||
chat_gpt = _FakeChatGPT(reply='{"garden shed": "Shed"}')
|
||||
classifier = ChatGptPropertyTypeClassifier(chat_gpt)
|
||||
|
||||
# Act
|
||||
result = classifier.classify({"garden shed"})
|
||||
|
||||
# Assert
|
||||
assert result == {"garden shed": PropertyType.UNKNOWN}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue