fix: bocha filter list

Co-Authored-By: zengxy <11961641+zengxy@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek 2025-12-20 17:24:24 +04:00
parent 823b9a6dd9
commit b5bd8704fe

View file

@ -9,13 +9,13 @@ log = logging.getLogger(__name__)
def _parse_response(response):
result = {}
results = []
if "data" in response:
data = response["data"]
if "webPages" in data:
webPages = data["webPages"]
if "value" in webPages:
result["webpage"] = [
results = [
{
"id": item.get("id", ""),
"name": item.get("name", ""),
@ -29,7 +29,7 @@ def _parse_response(response):
}
for item in webPages["value"]
]
return result
return results
def search_bocha(
@ -51,7 +51,7 @@ def search_bocha(
response = requests.post(url, headers=headers, data=payload, timeout=5)
response.raise_for_status()
results = _parse_response(response.json())
print(results)
if filter_list:
results = get_filtered_results(results, filter_list)
@ -59,5 +59,5 @@ def search_bocha(
SearchResult(
link=result["url"], title=result.get("name"), snippet=result.get("summary")
)
for result in results.get("webpage", [])[:count]
for result in results[:count]
]