Skip to content

Commit 08362d4

Browse files
committed
fix: tests + updated docstring in web_search handler
1 parent 2565198 commit 08362d4

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

nilai-api/src/nilai_api/handlers/web_search.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ async def _make_brave_api_request(query: str, request: Request) -> Dict[str, Any
9797
9898
Args:
9999
query: The search query string to execute
100+
request: FastAPI request object for rate limiting
100101
101102
Returns:
102103
Dict containing the raw API response data
@@ -242,6 +243,16 @@ async def perform_web_search_async(query: str, request: Request) -> WebSearchCon
242243
Fetches only the exact page for each Brave URL and extracts its
243244
main content with trafilatura. If extraction fails, falls back to
244245
the Brave snippet.
246+
247+
Args:
248+
query: The search query string to execute
249+
request: FastAPI request object for rate limiting
250+
251+
Returns:
252+
WebSearchContext with formatted search results and source information
253+
254+
Raises:
255+
HTTPException: If no results are found (404) or if the API request fails
245256
"""
246257
if not (query and query.strip()):
247258
logger.warning("Empty or invalid query provided for web search")
@@ -721,6 +732,7 @@ async def handle_web_search_for_responses(
721732
req: ResponseRequest containing input to process
722733
model_name: Name of the LLM model to use for query generation
723734
client: LLM client instance for making API calls
735+
request: FastAPI request object for rate limiting
724736
725737
Returns:
726738
WebSearchEnhancedInput with web search context added, or original

tests/unit/nilai_api/test_web_search.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ async def test_make_brave_api_request_calls_rps_limit():
207207
mock_http_client = AsyncMock()
208208
mock_response = AsyncMock()
209209
mock_response.status_code = 200
210-
mock_response.json = AsyncMock(return_value=mock_data)
210+
mock_response.json = MagicMock(return_value=mock_data)
211211
mock_http_client.get = AsyncMock(return_value=mock_response)
212212
mock_client.return_value = mock_http_client
213213

0 commit comments

Comments
 (0)