| 1 | # from langchain_community.utilities import DuckDuckGoSearchAPIWrapper |
| 2 | |
| 3 | # def search(query: str, results = 5, region = "wt-wt", time="y") -> str: |
| 4 | # # Create an instance with custom parameters |
| 5 | # api = DuckDuckGoSearchAPIWrapper( |
| 6 | # region=region, # Set the region for search results |
| 7 | # safesearch="off", # Set safesearch level (options: strict, moderate, off) |
| 8 | # time=time, # Set time range (options: d, w, m, y) |
| 9 | # max_results=results # Set maximum number of results to return |
| 10 | # ) |
| 11 | # # Perform a search |
| 12 | # result = api.run(query) |
| 13 | # return result |
| 14 | |
| 15 | from duckduckgo_search import DDGS |
| 16 | |
| 17 | def search(query: str, results = 5, region = "wt-wt", time="y") -> list[str]: |
| 18 | |
| 19 | ddgs = DDGS() |
| 20 | src = ddgs.text( |
| 21 | query, |
| 22 | region=region, # Specify region |
| 23 | safesearch="off", # SafeSearch setting |
| 24 | timelimit=time, # Time limit (y = past year) |
| 25 | max_results=results # Number of results to return |
| 26 | ) |
| 27 | results = [] |
| 28 | for s in src: |
| 29 | results.append(str(s)) |
| 30 | return results |