"""Run query through Merriam-Webster API and return a formatted result."""
        quoted_query = quote(query)
        request_url = (
            f"{MERRIAM_WEBSTER_API_URL}/{quoted_query}"
            f"?key={self.merriam_webster_api_key}"
        )
        response = requests.get(request_url, timeout=MERRIAM_WEBSTER_TIMEOUT)
        if response.status_code != 200:
            return response.text
        return self._format_response(query, response)
    def _format_response(self, query: str, response: requests.Response) -> str:
        content = json.loads(response.content)
        if not content:
            return f"No Merriam-Webster definition was found for query '{query}'."
        if isinstance(content[0], str):
            result = f"No Merriam-Webster definition was found for query '{query}'.\n"
            if len(content) > 1:
                alternatives = [f"{i + 1}. {content[i]}" for i in range(len(content))]
                result += "You can try one of the following alternative queries:\n\n"
                result += "\n".join(alternatives)
            else:
                result += f"Did you mean '{content[0]}'?"
        else:
            result = self._format_definitions(query, content)
        return result
    def _format_definitions(self, query: str, definitions: List[Dict]) -> str:
        formatted_definitions: List[str] = []
        for definition in definitions:
            formatted_definitions.extend(self._format_definition(definition))
        if len(formatted_definitions) == 1:
            return f"Definition of '{query}':\n" f"{formatted_definitions[0]}"
        result = f"Definitions of '{query}':\n\n"