Skip to content

mirascope.tools.web._requests

RequestsConfig

Bases: _ConfigurableToolConfig

Configuration for HTTP requests

Requests

Bases: ConfigurableTool

Tool for making HTTP requests with built-in requests library.

call

call() -> str

Make an HTTP request to the given URL.

Returns:

Name Type Description
str str

Response text content if successful, error message if request fails

Source code in mirascope/tools/web/_requests.py
def call(self) -> str:
    """Make an HTTP request to the given URL.

    Returns:
        str: Response text content if successful, error message if request fails
    """
    try:
        response = requests.request(
            method=self.method,
            url=self.url,
            json=self.data,
            headers=self.headers,
            timeout=self._get_config().timeout,
        )
        response.raise_for_status()
        return response.text

    except Exception as e:
        return f"{type(e)}: Failed to extract content from URL {self.url}"