Skip to main content
Glama
baidu_search.py1.86 kB
#!/usr/bin/env python """ Baidu search API implementation """ import httpx from typing import List from loguru import logger from src.engines.base import SearchEngine, SearchResult class BaiduSearch(SearchEngine): """Baidu search implementation""" def __init__(self, api_key: str, secret_key: str): super().__init__() self.api_key = api_key self.secret_key = secret_key self.priority = 3.0 # Lower priority self.rate_limit_cooldown = 300 # 5 minute cooldown logger.info("Baidu search engine initialized successfully") def is_available(self) -> bool: """Check if Baidu search is available""" return (bool(self.api_key) and bool(self.secret_key) and not self.is_in_cooldown()) async def search(self, query: str, num_results: int = 10) -> List[SearchResult]: """Execute search using Baidu API""" if not self.is_available(): return [] try: logger.info(f"Sending Baidu search request: {query}") # Simplified implementation - would need proper Baidu API integration results = [] await self.record_success() logger.info(f"Baidu search successful: {query} ({len(results)} results)") return results except Exception as e: error_str = str(e).lower() if "rate" in error_str or "limit" in error_str or "429" in error_str or "quota" in error_str: await self.record_error(is_rate_limit=True) logger.error(f"Baidu search rate limit error: {str(e)}") else: await self.record_error() logger.error(f"Baidu search failed: {str(e)}") return []

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sailaoda/search-fusion-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server