From 164de0f877c0aa5331eae0c6641b4c4e36f39204 Mon Sep 17 00:00:00 2001 From: Khoa Nguyen Date: Sat, 22 Jul 2023 16:05:36 +0200 Subject: [PATCH] Update how guidance handle error when missing params for the handlebar (#14) --- app/services/guidance_wrapper.py | 4 ++++ tests/services/guidance_wrapper_test.py | 6 ------ 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/app/services/guidance_wrapper.py b/app/services/guidance_wrapper.py index 54f1130a..3d6d653a 100644 --- a/app/services/guidance_wrapper.py +++ b/app/services/guidance_wrapper.py @@ -27,6 +27,7 @@ def query(self) -> Content: Text content object with LLM's response. Raises: + Reraises exception from guidance package ValueError: if handlebars do not generate 'response' """ @@ -36,6 +37,9 @@ def query(self) -> Content: **self.parameters, ) + if isinstance(result._exception, Exception): + raise result._exception + if "response" not in result: raise ValueError("The handlebars do not generate 'response'") diff --git a/tests/services/guidance_wrapper_test.py b/tests/services/guidance_wrapper_test.py index f43a558d..b20bb666 100644 --- a/tests/services/guidance_wrapper_test.py +++ b/tests/services/guidance_wrapper_test.py @@ -34,9 +34,6 @@ def test_query_success(mocker): assert result.text_content == "the output" -@pytest.mark.skip( - reason="This tests library behavior changed by Guidance version bump" -) def test_query_missing_required_params(mocker): mocker.patch.object( GuidanceWrapper, @@ -55,14 +52,11 @@ def test_query_missing_required_params(mocker): ) with pytest.raises(KeyError, match="Command/variable 'query' not found!"): - # try: result = guidance_wrapper.query() assert isinstance(result, Content) assert result.type == ContentType.TEXT assert result.text_content == "the output" - # except Exception as e: - # pass def test_query_handlebars_not_generate_response(mocker):