def _wikipedia_search(query: str, num_results: int = 5) -> str | list[str]:
    """Return the results of a Wikipedia search
    Args:
        query (str): The search query.
        num_results (int): The number of results to return.
    Returns:
        str: The results of the search. The resulting string is a `json.dumps`
             of a list of len `num_results` containing dictionaries with the
             following structure: `{'title': <title>, 'summary': <summary>,
             'url': <url to relevant page>}`
    """
    search_url = (
        "https://en.wikipedia.org/w/api.php?action=query&"
        "format=json&list=search&utf8=1&formatversion=2&"
        f"srsearch={quote(query)}"
    )
    with requests.Session() as session:
        session.headers.update(
            {
                "User-Agent": (
                    "AutoGPT wikipedia_search plugin (https://news.agpt.co/contact/) Requests"
                )
            }
        )
        session.headers.update({"Accept": "application/json"})
        results = session.get(search_url)
        items = []
        try:
            results = results.json()
            for item in results["query"]["search"]:
                summary = re.sub(HTML_TAG_CLEANER, "", item["snippet"])
                items.append(
                    {
                        "title": item["title"],
                        "summary": summary,
                        "url": f"http://en.wikipedia.org/?curid={item['pageid']}",
                    }
                )
                if len(items) == num_results:
                    break
        except Exception as e:
            return f"'wikipedia_search' on query: '{query}' raised exception: '{e}'"

    return json.dumps(items, ensure_ascii=False, indent=4)
Return the results of a Wikipedia search
    Args:
        query (str): The search query.
        num_results (int): The number of results to return.
    Returns:
        str: The results of the search. The resulting string is a `json.dumps`
             of a list of len `num_results` containing dictionaries with the
             following structure: `{'title': <title>, 'summary': <summary>,
             'url': <url to relevant page>}`
    
src/autogpt_plugins/wikipedia_search/wikipedia_search.py