Open
Conversation
…h handlers to support rate limiting
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (3)
nilai-api/src/nilai_api/handlers/web_search.py:106
- The docstring is missing documentation for the new
requestparameter. Please add it to the Args section:
Args:
query: The search query string to execute
request: FastAPI request object for rate limitingasync def _make_brave_api_request(query: str, request: Request) -> Dict[str, Any]:
"""Make an API request to the Brave Search API.
Args:
query: The search query string to execute
Returns:
Dict containing the raw API response data
Raises:
HTTPException: If API key is missing or API request fails
"""
nilai-api/src/nilai_api/handlers/web_search.py:245
- The docstring is incomplete and missing documentation for the new
requestparameter. The function should have a complete docstring including Args, Returns, and Raises sections. Please update it:
"""Perform an asynchronous web search using the Brave Search API.
Fetches only the exact page for each Brave URL and extracts its
main content with trafilatura. If extraction fails, falls back to
the Brave snippet.
Args:
query: The search query string to execute
request: FastAPI request object for rate limiting
Returns:
WebSearchContext with formatted search results and source information
Raises:
HTTPException: If no results are found (404) or if the API request fails
"""async def perform_web_search_async(query: str, request: Request) -> WebSearchContext:
"""Perform an asynchronous web search using the Brave Search API.
Fetches only the exact page for each Brave URL and extracts its
main content with trafilatura. If extraction fails, falls back to
the Brave snippet.
"""
nilai-api/src/nilai_api/handlers/web_search.py:728
- The docstring is missing documentation for the new
requestparameter. Please add it to the Args section:
Args:
req: ResponseRequest containing input to process
model_name: Name of the LLM model to use for query generation
client: LLM client instance for making API calls
request: FastAPI request object for rate limitingasync def handle_web_search_for_responses(
req: ResponseRequest, model_name: str, client: Any, request: Request
) -> WebSearchEnhancedInput:
"""Handle web search enhancement for response requests.
Analyzes the user's input to identify topics that require web search,
generates optimized search queries for each topic using an LLM, and
enhances the request with relevant web search results. Falls back to
single-query search if topic analysis fails or no topics need search.
Args:
req: ResponseRequest containing input to process
model_name: Name of the LLM model to use for query generation
client: LLM client instance for making API calls
Returns:
WebSearchEnhancedInput with web search context added, or original
input if no user query is found or search fails
"""
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| async def handle_web_search( | ||
| req_messages: ChatRequest, model_name: str, client: Any | ||
| req_messages: ChatRequest, model_name: str, client: Any, request: Request | ||
| ) -> WebSearchEnhancedMessages: |
There was a problem hiding this comment.
The function is missing a docstring. Please add comprehensive documentation that includes the new request parameter:
"""Handle web search enhancement for chat requests.
Analyzes the user's message to identify topics that require web search,
generates optimized search queries for each topic using an LLM, and
enhances the request with relevant web search results. Falls back to
single-query search if topic analysis fails or no topics need search.
Args:
req_messages: ChatRequest containing conversation messages
model_name: Name of the LLM model to use for query generation
client: LLM client instance for making API calls
request: FastAPI request object for rate limiting
Returns:
WebSearchEnhancedMessages with web search context added, or original
messages if no user query is found or search fails
"""
Suggested change
| ) -> WebSearchEnhancedMessages: | |
| ) -> WebSearchEnhancedMessages: | |
| """ | |
| Handle web search enhancement for chat requests. | |
| Analyzes the user's message to identify topics that require web search, | |
| generates optimized search queries for each topic using an LLM, and | |
| enhances the request with relevant web search results. Falls back to | |
| single-query search if topic analysis fails or no topics need search. | |
| Args: | |
| req_messages: ChatRequest containing conversation messages | |
| model_name: Name of the LLM model to use for query generation | |
| client: LLM client instance for making API calls | |
| request: FastAPI request object for rate limiting | |
| Returns: | |
| WebSearchEnhancedMessages with web search context added, or original | |
| messages if no user query is found or search fails | |
| """ |
fdff362 to
08362d4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.