Handle empty doctor model responses
This commit is contained in:
parent
e3564e211b
commit
dd93d984d2
|
|
@ -324,6 +324,8 @@ def external_config():
|
|||
|
||||
def parse_answer(response):
|
||||
"""Allow one complete Markdown JSON fence, then use the unchanged validator."""
|
||||
if not isinstance(response, str) or not response.strip():
|
||||
raise ValueError("model returned no text content")
|
||||
text = response.strip()
|
||||
match = re.fullmatch(r"```(?:json)?[ \t]*\r?\n(.*?)\r?\n```", text, re.DOTALL | re.IGNORECASE)
|
||||
return json.loads(match.group(1) if match else text)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ rank_spec.loader.exec_module(ranker)
|
|||
|
||||
|
||||
class DoctorModelLabTests(unittest.TestCase):
|
||||
def test_empty_or_non_text_response_is_a_validation_rejection(self):
|
||||
for response in (None, "", " ", {"unexpected": "content"}):
|
||||
with self.subTest(response=response), self.assertRaisesRegex(ValueError, "no text content"):
|
||||
lab.parse_answer(response)
|
||||
|
||||
def test_external_request_uses_the_same_evidence_and_private_key(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
name, tsv = lab.CASES[0]
|
||||
|
|
|
|||
Loading…
Reference in New Issue