<commit_before>import requests

BASE_URL = 'http://localhost:8000/client/api/experiments/'

def get_experiments(client_id, experiment_ids=None, user_id=None, bucket_if_necessary=True, user_data=None):
    """
    Retrieve the experiments the user is a part of
    @param client_id : Bernoulli Client ID
    @param experiment_ids : Either a single or list of experiment ids to retreive
    @param user_id : An identifier for the user
    @param bucket_if_necessary : Choose a variant for the user if one has not been chosen
    @param user_data : Dictionary of user information to be used by the segment filters
    """

    if not client_id:
        raise Exception("client_id is required")

    if type(experiment_ids) is dict:
        experiment_ids = ','.join(experiment_ids)

    response = requests.get(BASE_URL, params={
        'clientId': client_id,
        'experimentsIds': experiment_ids,
        'userId': user_id,
        'bucketIfNecessary': bucket_if_necessary,
        'userData': user_data,
    })

    val = response.json()
    if val['status'] != 'ok':
        raise Exception(val['message'])

    return val['value']

def record_goal_attained(client_id, experiment_id, variant_id, user_id):
    """
    Record that a variant was successful for a user
    @param client_id : Bernoulli Client ID
    @param experiment_id : A single experiment id
    @param variant_id : The ID of the variant that was successful
    @param user_id : An identifier for the user
    """

    response = requests.get(BASE_URL + str(experiment_id), params={
        'clientId': client_id,
        'userId': user_id,
        'variantId': variant_id,
    })

    val = response.json()
    if val['status'] != 'ok':
        raise Exception(val['message'])

    return val['value'] # Should be True<commit_msg>fixes<commit_after>import requests

BASE_URL = 'http://localhost:5000/client/api/experiments/'

def get_experiments(client_id, experiment_ids=None, user_id=None, bucket_if_necessary=True, user_data=None):
    """
    Retrieve the experiments the user is a part of
    @param client_id : Bernoulli Client ID
    @param experiment_ids : Either a single or list of experiment ids to retreive
    @param user_id : An identifier for the user
    @param bucket_if_necessary : Choose a variant for the user if one has not been chosen
    @param user_data : Dictionary of user information to be used by the segment filters
    """

    if not client_id:
        raise Exception("client_id is required")

    if type(experiment_ids) is dict:
        experiment_ids = ','.join(experiment_ids)

    try:
        response = requests.get(BASE_URL, params={
            'clientId': client_id,
            'experimentIds': experiment_ids,
            'userId': user_id,
            'bucketIfNecessary': bucket_if_necessary,
            'userData': user_data,
        })
    except requests.ConnectionError:
        raise Exception("Unable to access service")

    val = response.json()
    if val['status'] != 'ok':
        raise Exception(val['message'])

    return val['value']

def record_goal_attained(client_id, experiment_id, user_id):
    """
    Record that a variant was successful for a user
    @param client_id : Bernoulli Client ID
    @param experiment_id : A single experiment id
    @param user_id : An identifier for the user
    """

    try:
        response = requests.post(BASE_URL, data={
            'clientId': client_id,
            'userId': user_id,
            'experimentId': experiment_id,
        })
    except requests.ConnectionError:
        raise Exception("Unable to access services")

    val = response.json()
    if val['status'] != 'ok':
        raise Exception(val['message'])

    return val['value'] # Should be True
{'fraction_non_alphanumeric': 0.09498399146211313, 'fraction_numerical': 0.0021344717182497333, 'mean_word_length': 3.0794341675734493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1423707', 'n_tokens_mistral': 1080, 'n_tokens_neox': 1059, 'n_words': 341}