mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-01-04 11:07:52 +00:00
Allow values that are not dictionaries in the request params in the /search endpoint (#2720)
* let params contain something else than dictionaries * rewrite the test same style as the main branch
This commit is contained in:
parent
6b39fbd39c
commit
632cd1c141
@ -1,5 +1,6 @@
|
||||
from typing import Dict, Any
|
||||
|
||||
import collections
|
||||
import logging
|
||||
import time
|
||||
import json
|
||||
@ -72,7 +73,7 @@ def _process_request(pipeline, request) -> Dict[str, Any]:
|
||||
|
||||
# format targeted node filters (e.g. "params": {"Retriever": {"filters": {"value"}}})
|
||||
for key in params.keys():
|
||||
if "filters" in params[key].keys():
|
||||
if isinstance(params[key], collections.Mapping) and "filters" in params[key].keys():
|
||||
params[key]["filters"] = _format_filters(params[key]["filters"])
|
||||
|
||||
result = pipeline.run(query=request.query, params=params, debug=request.debug)
|
||||
|
||||
@ -347,6 +347,25 @@ def test_query_with_no_documents_and_no_answers(client):
|
||||
assert response_json["answers"] == []
|
||||
|
||||
|
||||
def test_query_with_bool_in_params(client):
|
||||
"""
|
||||
Ensure items of params can be other types than dictionary, see
|
||||
https://github.com/deepset-ai/haystack/issues/2656
|
||||
"""
|
||||
with mock.patch("rest_api.controller.search.query_pipeline") as mocked_pipeline:
|
||||
# `run` must return a dictionary containing a `query` key
|
||||
mocked_pipeline.run.return_value = {"query": TEST_QUERY}
|
||||
request_body = {
|
||||
"query": TEST_QUERY,
|
||||
"params": {"debug": True, "Retriever": {"top_k": 5}, "Reader": {"top_k": 3}},
|
||||
}
|
||||
response = client.post(url="/query", json=request_body)
|
||||
assert 200 == response.status_code
|
||||
response_json = response.json()
|
||||
assert response_json["documents"] == []
|
||||
assert response_json["answers"] == []
|
||||
|
||||
|
||||
def test_write_feedback(client, feedback):
|
||||
response = client.post(url="/feedback", json=feedback)
|
||||
assert 200 == response.status_code
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user