Skip to content

Commit

Permalink
Update how guidance handle error when missing params for the handlebar (
Browse files Browse the repository at this point in the history
  • Loading branch information
dakennguyen authored Jul 22, 2023
1 parent ad2fe48 commit 164de0f
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/services/guidance_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
"""

Expand All @@ -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'")

Expand Down
6 changes: 0 additions & 6 deletions tests/services/guidance_wrapper_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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):
Expand Down

0 comments on commit 164de0f

Please sign in to comment.