benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 8ea946e9-3cb9-5e76-93e3-7dca32eaf9ee

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import re
import urllib.request
import json

# Constants
IP_REGEX = r'[0-9]+(?:\.[0-9]+){3}'

def task_func(API_URL):
    """
    Get the public IP address of the current host from an API.
    
    Parameters:
    API_URL (str): The API url that will return json format of the 'ip'.

    Returns:
    str: The public IP address.
    
    Raises:
    If the API request fails, the function will return the error message.
    
    Requirements:
    - re
    - urllib.request
    - json
    
    Example:
    >>> import json
    >>> from unittest.mock import MagicMock
    >>> mock_response = MagicMock()
    >>> mock_response.read.return_value = json.dumps({'ip': '192.168.1.1'}).encode('utf-8')
    >>> mock_urlopen = MagicMock(return_value=mock_response)
    >>> with unittest.mock.patch('urllib.request.urlopen', mock_urlopen):
    ...     task_func('https://api.ipify.org?format=json')
    '192.168.1.1'
    """

instruct prompt

Get the public IP address of the current host from an API.
The function should raise the exception for: If the API request fails, the function will return the error message.
The function should output with:
    str: The public IP address.
You should write self-contained code starting with:

Code

import re
import urllib.request
import json
# Constants
IP_REGEX = r'[0-9]+(?:\.[0-9]+){3}'
def task_func(API_URL):

code prompt

Code

import re
import urllib.request
import json
# Constants
IP_REGEX = r'[0-9]+(?:\.[0-9]+){3}'
def task_func(API_URL):

entry point

task_func

libs

  • urllib
  • re
  • json

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import