Skip to content

Commit

Permalink
Include translate steps in try+catch so we can better debug issues. (#…
Browse files Browse the repository at this point in the history
…385)

This should make it much easier to reproduce the cause of the exception.
  • Loading branch information
brianwgoldman committed Apr 10, 2024
1 parent bc3a6b6 commit bc393d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
21 changes: 11 additions & 10 deletions modelgauge/simple_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,37 +122,38 @@ def _process_test_item(
) -> TestItemRecord:
interactions: List[PromptInteractionAnnotations] = []
for prompt in item.prompts:
if isinstance(prompt.prompt, TextPrompt):
sut_request = sut.translate_text_prompt(prompt.prompt)
else:
sut_request = sut.translate_chat_prompt(prompt.prompt)
try:
if isinstance(prompt.prompt, TextPrompt):
sut_request = sut.translate_text_prompt(prompt.prompt)
else:
sut_request = sut.translate_chat_prompt(prompt.prompt)
with sut_cache as cache:
sut_response = cache.get_or_call(sut_request, sut.evaluate)
response = sut.translate_response(sut_request, sut_response)
except Exception as e:
raise Exception(
f"Exception while handling SUT request `{sut_request}` for TestItem `{item}`"
f"Exception while handling SUT {sut.uid} for TestItem `{item}`"
) from e
response = sut.translate_response(sut_request, sut_response)

annotated_completions: List[SUTCompletionAnnotations] = []
for completion in response.completions:
annotations = {}
for annotator_data in annotators:
annotator = annotator_data.annotator
annotator_request = annotator.translate_request(prompt, completion)
try:
annotator_request = annotator.translate_request(prompt, completion)
with annotator_data.cache as cache:
annotator_response = cache.get_or_call(
annotator_request, annotator.annotate
)
annotation = annotator.translate_response(
annotator_request, annotator_response
)
except Exception as e:
raise Exception(
f"Exception while handling annotation for {annotator_data.key} on {response}"
) from e
annotation = annotator.translate_response(
annotator_request, annotator_response
)

annotations[annotator_data.key] = Annotation.from_instance(annotation)
annotated_completions.append(
SUTCompletionAnnotations(completion=completion, annotations=annotations)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_simple_test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def _raise_exception(*args, **kwargs):
tmpdir,
)
err_text = str(err_info.value)
assert "SUT request `text='1' num_completions=1`" in err_text
assert "Exception while handling SUT fake-sut" in err_text
assert "TestItem `prompts=[PromptWithContext(" in err_text
# Ensure it forwards the original issue
assert str(err_info.value.__cause__) == "some-exception"
Expand Down

0 comments on commit bc393d2

Please sign in to comment.