feat: Add max_results kwarg to DDGS tool
This commit is contained in:
		
							parent
							
								
									5991206ae5
								
							
						
					
					
						commit
						8ec6674592
					
				|  | @ -0,0 +1,5 @@ | ||||||
|  | from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel | ||||||
|  | 
 | ||||||
|  | agent = CodeAgent(tools=[DuckDuckGoSearchTool(max_results=2)], model=HfApiModel()) | ||||||
|  | 
 | ||||||
|  | agent.run("How many seconds would it take for a leopard at full speed to run through Pont des Arts?") | ||||||
|  | @ -153,8 +153,9 @@ class DuckDuckGoSearchTool(Tool): | ||||||
|     } |     } | ||||||
|     output_type = "any" |     output_type = "any" | ||||||
| 
 | 
 | ||||||
|     def __init__(self, **kwargs): |     def __init__(self, *args, max_results=10, **kwargs): | ||||||
|         super().__init__(self, **kwargs) |         super().__init__(*args, **kwargs) | ||||||
|  |         self.max_results = max_results | ||||||
|         try: |         try: | ||||||
|             from duckduckgo_search import DDGS |             from duckduckgo_search import DDGS | ||||||
|         except ImportError: |         except ImportError: | ||||||
|  | @ -164,7 +165,7 @@ class DuckDuckGoSearchTool(Tool): | ||||||
|         self.ddgs = DDGS() |         self.ddgs = DDGS() | ||||||
| 
 | 
 | ||||||
|     def forward(self, query: str) -> str: |     def forward(self, query: str) -> str: | ||||||
|         results = self.ddgs.text(query, max_results=10) |         results = self.ddgs.text(query, max_results=self.max_results) | ||||||
|         postprocessed_results = [ |         postprocessed_results = [ | ||||||
|             f"[{result['title']}]({result['href']})\n{result['body']}" |             f"[{result['title']}]({result['href']})\n{result['body']}" | ||||||
|             for result in results |             for result in results | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue