-
Notifications
You must be signed in to change notification settings - Fork 10
fix: Brave API web search RPS limit with Redis #166
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…h handlers to support rate limiting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
Copilot
AI
Nov 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
"""| ) -> 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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.
No description provided.