Skip to content

Commit 12bff9d

Browse files
author
Muhamed Fazal PS
committed
fix: _is_trivial_response no longer skips valid JSON responses (#24)
Removed the naive text.startswith('{') and text.startswith('[') checks that caused all JSON-formatted responses to be classified as trivial. Lowered the code_char density threshold from 0.6 to 0.5 so that highly-symbolic but non-JSON responses like '{ } ( ) = ; : # | \ > <' are still correctly caught as trivial, while valid JSON is not. Updated test assertions to match new behavior. Fixes #24
1 parent 9df3738 commit 12bff9d

2 files changed

Lines changed: 3 additions & 5 deletions

File tree

beliefstate/extractor.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,8 @@ def _is_trivial_response(text: str) -> bool:
170170
code_chars = set("{}()=;:|#|\\><")
171171
if text:
172172
code_count = sum(1 for c in text if c in code_chars)
173-
if code_count / len(text) > 0.6:
173+
if code_count / len(text) > 0.5:
174174
return True
175-
if text.startswith("{") or text.startswith("["):
176-
return True
177175
return False
178176

179177

tests/test_new_features.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ def test_is_trivial_code_block(self):
134134
assert _is_trivial_response("{ } ( ) = ; : # | \\ > <") is True
135135

136136
def test_is_trivial_json_start(self):
137-
assert _is_trivial_response('{"key": "value"}') is True
138-
assert _is_trivial_response('[{"key": "value"}]') is True
137+
assert _is_trivial_response('{"key": "value"}') is False
138+
assert _is_trivial_response('[{"key": "value"}]') is False
139139

140140
def test_not_trivial_substantive(self):
141141
assert _is_trivial_response("I understand your budget constraints.") is False

0 commit comments

Comments
 (0)