From f8f92e36bcad1b6bb2c664f61c454ce120cee99e Mon Sep 17 00:00:00 2001 From: Baur Date: Mon, 17 Jun 2024 15:36:48 -0700 Subject: [PATCH] [bug] change post to get for report function --- pyproject.toml | 2 +- tests/zenguard_e2e_test.py | 6 +++--- zenguard/zenguard.py | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 543c98e..f9a1d3f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "zenguard" -version = "0.1.16" +version = "0.1.18" description = "Fast production grade security for GenAI applications" authors = ["ZenGuard Team "] license = "MIT" diff --git a/tests/zenguard_e2e_test.py b/tests/zenguard_e2e_test.py index b06a430..e339b47 100644 --- a/tests/zenguard_e2e_test.py +++ b/tests/zenguard_e2e_test.py @@ -111,7 +111,7 @@ def test_detect_error_no_detectors(zenguard): def test_report_with_valid_detector_and_days(zenguard): - with patch("httpx.post") as mock_post: + with patch("httpx.get") as mock_post: mock_response = Mock() # TODO(baur): Update this to the actual response mock_response.json.return_value = {"prompt_injections": 10} @@ -124,7 +124,7 @@ def test_report_with_valid_detector_and_days(zenguard): # Assert only the relevant parts of the API call assert API_REPORT_PROMPT_INJECTIONS in mock_post_args[0] - assert mock_post_kwargs["json"] == {"days": 7} + assert mock_post_kwargs["params"] == {"days": 7} def test_report_with_invalid_detector(zenguard): @@ -133,7 +133,7 @@ def test_report_with_invalid_detector(zenguard): def test_report_with_request_error(zenguard): - with patch("httpx.post") as mock_post: + with patch("httpx.get") as mock_post: mock_post.side_effect = httpx.RequestError("Connection error") with pytest.raises(RuntimeError) as exc_info: diff --git a/zenguard/zenguard.py b/zenguard/zenguard.py index 8d3db8e..85da1de 100644 --- a/zenguard/zenguard.py +++ b/zenguard/zenguard.py @@ -222,16 +222,16 @@ def report(self, detector: Detector, days: int = None): "Only Prompt Injection detector is currently supported for reports" ) - json = {} + params = {} if days: - json = {"days": days} + params["days"] = days url = self._backend + API_REPORT_PROMPT_INJECTIONS try: - response = httpx.post( + response = httpx.get( url, - json=json, + params=params, headers={"x-api-key": self._api_key}, timeout=20, )