MCPcopy Create free account
hub / github.com/CaraJ7/MMSearch / DDGSQueryRun

Class DDGSQueryRun

utils/utils.py:91–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89 raise ValueError
90## API: Search Engine Retrieval + Screenshot of top section
91class DDGSQueryRun:
92 name = "duckduckgo_search"
93 signature = f"{name}(query: str) -> str"
94
95 def __init__(self, max_results: int, rapidapi_name: str = "one"):
96 self.max_results = max_results
97 self.api_wrapper = RapidAPI(rapidapi_name)
98
99 async def __call__(self, query: str, screenshot_dir_path: str) -> List[Dict[str, Any]]:
100 try:
101 output = self.api_wrapper.query(query, max_results=self.max_results+20) # account for error website
102 except Exception as e:
103 logger.error(f"DDGSQueryRun call failed: {e}")
104 output = []
105
106 evidences = []
107 for idx, result in enumerate(output):
108 evidence = {
109 "title": result["title"],
110 "snippet": result.get("description", result.get("body", "")),
111 'url': result['href'],
112 'screenshot_path': os.path.join(screenshot_dir_path, f"{idx}.jpg")
113 }
114 success = await take_screenshot_async(evidence['url'], os.path.join(screenshot_dir_path, f"{idx}.jpg"))
115 if success:
116 evidences.append(evidence)
117 if len(evidences) == self.max_results:
118 break
119
120 if not evidences:
121 evidences = None
122
123 return evidences
124## Screenshot of top section. Set the size to be 1024*1024
125async def take_screenshot_async(url: str, screenshot_path: str, timeout: int = BRIEF_TIMEOUT):
126 async with async_playwright() as p:

Callers 1

run_queryFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected