Skip to content

Commit

Permalink
Update to ValueError when missing params
Browse files Browse the repository at this point in the history
  • Loading branch information
dakennguyen committed Jul 18, 2023
1 parent 649c9f7 commit 9ec4a4b
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 32 deletions.
3 changes: 0 additions & 3 deletions app/routes/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from parsimonious.exceptions import IncompleteParseError

from app.core.custom_exceptions import (
MissingParameterException,
InvalidTemplateException,
InternalServerException,
InvalidModelException,
Expand Down Expand Up @@ -34,8 +33,6 @@ def send_message(body: SendMessageRequest) -> SendMessageResponse:

try:
content = guidance.query()
except KeyError as e:
raise MissingParameterException(str(e))
except (SyntaxError, IncompleteParseError) as e:
raise InvalidTemplateException(str(e))
except Exception as e:
Expand Down
22 changes: 0 additions & 22 deletions tests/routes/messages_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,6 @@ def test_send_message_raise_value_error(test_client, headers, mocker):
}


def test_send_message_raise_key_error(test_client, headers, mocker):
mocker.patch.object(
GuidanceWrapper, "query", side_effect=KeyError("key error message")
)
body = {
"template": {
"id": 123,
"content": "some template",
},
"preferredModel": "GPT35_TURBO",
"parameters": {"query": "Some query"},
}
response = test_client.post("/api/v1/messages", headers=headers, json=body)
assert response.status_code == 400
assert response.json() == {
"detail": {
"type": "missing_parameter",
"errorMessage": "'key error message'",
}
}


def test_send_message_with_wrong_api_key(test_client):
headers = {"Authorization": "wrong api key"}
response = test_client.post("/api/v1/messages", headers=headers, json={})
Expand Down
10 changes: 3 additions & 7 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 @@ -54,15 +51,14 @@ def test_query_missing_required_params(mocker):
parameters={"somethingelse": "Something"},
)

with pytest.raises(KeyError, match="Command/variable 'query' not found!"):
# try:
with pytest.raises(
ValueError, match="The handlebars do not generate 'response'"
):
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 9ec4a4b

Please sign in to comment.