~95% on SimpleQA (e.g. Qwen3.6-27B on a 3090). Supports all local and cloud LLMs (llama.cpp, Ollama, Google, ...). 10+ search engines - arXiv, PubMed, your private documents. Everything Local & Encrypted.
Python academiaanthropicarxivbravedeep-researchencryptionhome-automationhomeserverlocallocal-deep-researchlocal-llmmistralollamaopenaipubmedresearchresearch-toolretrieval-augmented-generationsearxngself-hosted
fix: improve GitHub search engine authentication and error handling
LearningCircuitbf23b0ad24f4
diff --git a/src/local_deep_research/defaults/default_settings.json b/src/local_deep_research/defaults/default_settings.jsonindex 5649744471..cc3009d624 100644--- a/src/local_deep_research/defaults/default_settings.json+++ b/src/local_deep_research/defaults/default_settings.json@@ -1823,6 +1823,20 @@"value": false,"visible": true},+ "search.engine.web.github.api_key": {+ "category": "github",+ "description": "GitHub Personal Access Token for API authentication. Without this, you're limited to 60 requests/hour. With authentication, you get 5000 requests/hour.",+ "editable": true,+ "max_value": null,+ "min_value": null,+ "name": "GitHub API Key",+ "options": null,+ "step": null,+ "type": "SEARCH",+ "ui_element": "password",+ "value": "",+ "visible": true+ },"search.engine.web.github.strengths": {"category": "github","description": "Setting for github.strengths",diff --git a/src/local_deep_research/web_search_engines/engines/search_engine_github.py b/src/local_deep_research/web_search_engines/engines/search_engine_github.pyindex f4f53404fb..279b1f9c5b 100644--- a/src/local_deep_research/web_search_engines/engines/search_engine_github.py+++ b/src/local_deep_research/web_search_engines/engines/search_engine_github.py@@ -26,6 +26,8 @@ class GitHubSearchEngine(BaseSearchEngine):include_issues: bool = False,llm: Optional[BaseLLM] = None,max_filtered_results: Optional[int] = None,+ settings_snapshot: Optional[Dict[str, Any]] = None,+ **kwargs,):"""Initialize the GitHub search engine.@@ -38,18 +40,37 @@ class GitHubSearchEngine(BaseSearchEngine):include_issues: Whether to include recent issues for repositoriesllm: Language model for relevance filteringmax_filtered_results: Maximum number of results to keep after filtering+ settings_snapshot: Settings snapshot for configuration+ **kwargs: Additional parameters to pass to parent class"""# Initialize the BaseSearchEngine with LLM, max_filtered_results, and max_resultssuper().__init__(llm=llm,max_filtered_results=max_filtered_results,max_results=max_results,+ settings_snapshot=settings_snapshot,+ **kwargs,)- self.api_key = api_keyself.search_type = search_typeself.include_readme = include_readmeself.include_issues = include_issues+ # Get API key - check params first, then settings_snapshot+ from ...config.search_config import get_setting_from_snapshot++ github_api_key = api_key+ if not github_api_key:+ try:+ github_api_key = get_setting_from_snapshot(+ "search.engine.web.github.api_key",+ settings_snapshot=settings_snapshot,+ )+ except Exception as e:+ logger.debug(f"Could not get GitHub API key from settings: {e}")+ github_api_key = None++ self.api_key = github_api_key+# API endpointsself.api_base = "https://api.github.com"self.search_endpoint = f"{self.api_base}/search/{search_type}"@@ -63,29 +84,36 @@ class GitHubSearchEngine(BaseSearchEngine):# Add authentication if API key providedif self.api_key:self.headers["Authorization"] = f"token {self.api_key}"- logger.info("Using authenticated GitHub API requests")+ logger.info(+ "Using authenticated GitHub API requests (5000 requests/hour limit)"+ )else:- logger.warning(- "No GitHub API key provided. Rate limits will be restricted."+ logger.info(+ "Using unauthenticated GitHub API requests (60 requests/hour limit). "+ "To increase the limit, add a GitHub Personal Access Token in Settings > Search Engines > GitHub API Key")def _handle_rate_limits(self, response):"""Handle GitHub API rate limits by logging warnings and sleeping if necessary"""remaining = int(response.headers.get("X-RateLimit-Remaining", 60))reset_time = int(response.headers.get("X-RateLimit-Reset", 0))+ limit = int(response.headers.get("X-RateLimit-Limit", 60))if remaining < 5:current_time = time.time()wait_time = max(reset_time - current_time, 0)- logger.warning(- f"GitHub API rate limit almost reached. {remaining} requests remaining."- )- if wait_time > 0 and remaining == 0:- logger.warning(- f"GitHub API rate limit exceeded. Waiting {wait_time:.0f} seconds."+ if remaining == 0:+ if wait_time > 0:+ logger.info(+ f"GitHub API rate limit reached ({limit} requests/hour). "+ f"Waiting {min(wait_time, 10):.0f} seconds before retry..."+ )+ time.sleep(min(wait_time, 10)) # Wait at most 10 seconds+ else:+ logger.debug(+ f"GitHub API rate limit almost reached. {remaining}/{limit} requests remaining.")- time.sleep(min(wait_time, 60)) # Wait at most 60 secondsdef _optimize_github_query(self, query: str) -> str:"""@@ -100,12 +128,20 @@ class GitHubSearchEngine(BaseSearchEngine):# Get LLM from config if not already setif not self.llm:try:- self.llm = llm_config.get_llm()+ # Try to get LLM with settings snapshot+ if self.settings_snapshot:+ self.llm = llm_config.get_llm(+ settings_snapshot=self.settings_snapshot+ )+ else:+ self.llm = llm_config.get_llm()if not self.llm:logger.warning("No LLM available for query optimization")return query- except Exception:- logger.exception("Error getting LLM from config")+ except Exception as e:+ logger.warning(+ f"Error getting LLM from config: {e}. Using original query."+ )return queryprompt = f"""Transform this GitHub search query into an optimized version for the GitHub search API. Follow these steps:@@ -139,6 +175,28 @@ class GitHubSearchEngine(BaseSearchEngine):# Handle string responsesoptimized_query = str(response).strip()+ # Remove outer quotes if the entire query is wrapped in them+ # This happens when LLM incorrectly quotes the whole query including operators+ if optimized_query.startswith('"') and optimized_query.endswith(+ '"'+ ):+ # Check if there are GitHub operators inside the quotes+ if any(+ op in optimized_query+ for op in [+ "stars:",+ "language:",+ "in:",+ "pushed:",+ "created:",+ "NOT ",+ ]+ ):+ logger.info(+ "Removing outer quotes from query that contains operators"+ )+ optimized_query = optimized_query[1:-1]+# Validate the optimized queryif optimized_query and len(optimized_query) > 0:logger.info(@@ -194,6 +252,12 @@ class GitHubSearchEngine(BaseSearchEngine):params["sort"] = "followers"params["order"] = "desc"+ logger.info(f"GitHub API request URL: {self.search_endpoint}")+ logger.info(f"GitHub API request params: {params}")+ logger.info(+ f"GitHub API headers (auth): {'Authorization' in self.headers}"+ )+# Apply rate limiting before requestself._last_wait_time = self.rate_tracker.apply_rate_limit(self.engine_type@@ -204,6 +268,11 @@ class GitHubSearchEngine(BaseSearchEngine):self.search_endpoint, headers=self.headers, params=params)+ logger.info(f"GitHub API response status: {response.status_code}")+ logger.info(+ f"GitHub API response headers: X-RateLimit-Limit={response.headers.get('X-RateLimit-Limit')}, X-RateLimit-Remaining={response.headers.get('X-RateLimit-Remaining')}, X-RateLimit-Reset={response.headers.get('X-RateLimit-Reset')}"+ )+# Check for rate limitingself._handle_rate_limits(response)@@ -216,6 +285,14 @@ class GitHubSearchEngine(BaseSearchEngine):f"GitHub search returned {len(results)} results (total available: {total_count})")+ if results:+ logger.info(+ f"First result title/name: {results[0].get('name', results[0].get('title', 'N/A'))}"+ )+ logger.info(+ f"Result type: {type(results[0])}, keys: {list(results[0].keys())[:5]}"+ )+# Log the rate limit informationrate_limit_remaining = response.headers.get("X-RateLimit-Remaining", "unknown"@@ -227,8 +304,9 @@ class GitHubSearchEngine(BaseSearchEngine):# If no results, try to provide more guidanceif not results:logger.warning(- "No results found. Consider these search tips:"+ f"No results found for query: '{github_query}'. Response data: {data}")+ logger.warning("Consider these search tips:")logger.warning("1. Use shorter, more specific queries")logger.warning("2. For repositories, try adding 'stars:>100' or 'language:python'"@@ -240,10 +318,12 @@ class GitHubSearchEngine(BaseSearchEngine):logger.error(f"GitHub API error: {response.status_code} - {response.text}")+ logger.error(f"Full response headers: {dict(response.headers)}")except Exception:logger.exception("Error searching GitHub")+ logger.info(f"Returning {len(results)} GitHub results to caller")return resultsdef _get_readme_content(self, repo_full_name: str) -> str:@@ -471,6 +551,11 @@ class GitHubSearchEngine(BaseSearchEngine):List of preview dictionaries"""logger.info(f"Getting GitHub previews for query: {query}")+ logger.info(+ f"Current search_type: {self.search_type}, max_results: {self.max_results}"+ )++ results = [] # Initialize results to empty list# For contribution-focused queries, automatically adjust search type and add filtersif any(@@ -549,6 +634,10 @@ class GitHubSearchEngine(BaseSearchEngine):# Perform standard GitHub searchresults = self._search_github(query)+ logger.info(+ f"_search_github returned {len(results) if results else 0} results"+ )+if not results:logger.warning(f"No GitHub results found for query: {query}")return []