<commit_before>(function () {
    var sixpack = {host: "localhost", port: 5000};

    // check for node module loader
    var on_node = false;
    if (typeof module !== "undefined" && typeof require !== "undefined") {
        on_node = true;
        module.exports = sixpack;
    } else {
        window["sixpack"] = sixpack;
    }

    sixpack.simple_participate = function (experiment_name, alternatives, client_id, force, callback) {
        if (typeof client_id === "function") {
            callback = client_id;
            client_id = null;
        } else if (typeof force === "function") {
            callback = force;
            force = null;
        }

        var session = new sixpack.Session(client_id);
        session.participate(experiment_name, alternatives, force, function (err, res) {
            if (on_node) {
                return callback(err, res && res.alternative);
            } else {
                return callback(err.alternative);
            }
        });
    };

    sixpack.simple_convert = function (experiment_name, client_id, callback) {
        var session = new sixpack.Session(client_id);
        session.convert(experiment_name, function (err, res) {
            if (on_node) {
                return callback(err, res && res.status);
            } else {
                return callback(err.status);
            }
        });
    }

    sixpack.generate_client_id = function () {
        // from http://stackoverflow.com/questions/105034
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
            return v.toString(16);
        });
    };

    sixpack.Session = function (client_id, host, port) {
        this.client_id = client_id || sixpack.generate_client_id();
        this.host = host || sixpack.host;
        this.port = port || sixpack.port;
    };

    sixpack.Session.prototype = {
        participate: function(experiment_name, alternatives, force, callback) {
            if (typeof force === "function") {
                callback = force;
                force = null;
            }

            if (!experiment_name.match(/^[a-z0-9][a-z0-9\-_ ]*/)) {
                return callback(new Error("Bad experiment_name"));
            }

            if (alternatives.length < 2) {
                return callback(new Error("Must specify at least 2 alternatives"));
            }

            for (var i = 0; i < alternatives.length; i += 1) {
                if (!alternatives[i].match(/^[a-z0-9][a-z0-9\-_ ]*/)) {
                    return callback(new Error("Bad alternative name: " + alternatives[i]));
                }
            }
            var params = {client_id: this.client_id,
                          experiment: experiment_name,
                          alternatives: alternatives};
            if (force != null && _in_array(alternatives, force)) {
                params.force = force;
            }
            return _request("/participate", params, callback);
        },
        convert: function(experiment_name, callback) {
            var params = {client_id: this.client_id,
                          experiment: experiment_name};
            return _request("/convert", params, callback);
        }
    };

    var counter = 0;

    var _request = function(endpoint, params, callback) {
        if (!on_node) {
            var cb = "callback" + (++counter);
            params.callback = "sixpack." + cb
            sixpack[cb] = callback;
        }
        var url = _request_uri(endpoint, params);
        if (!on_node) {<commit_msg>For browser we need to actually throw errors.<commit_after>(function () {
    var sixpack = {host: "localhost", port: 5000};

    // check for node module loader
    var on_node = false;
    if (typeof module !== "undefined" && typeof require !== "undefined") {
        on_node = true;
        module.exports = sixpack;
    } else {
        window["sixpack"] = sixpack;
    }

    sixpack.simple_participate = function (experiment_name, alternatives, client_id, force, callback) {
        if (typeof client_id === "function") {
            callback = client_id;
            client_id = null;
        } else if (typeof force === "function") {
            callback = force;
            force = null;
        }

        var session = new sixpack.Session(client_id);
        session.participate(experiment_name, alternatives, force, function (err, res) {
            if (on_node) {
                return callback(err, res && res.alternative);
            } else {
                return callback(err.alternative);
            }
        });
    };

    sixpack.simple_convert = function (experiment_name, client_id, callback) {
        var session = new sixpack.Session(client_id);
        session.convert(experiment_name, function (err, res) {
            if (on_node) {
                return callback(err, res && res.status);
            } else {
                return callback(err.status);
            }
        });
    }

    sixpack.generate_client_id = function () {
        // from http://stackoverflow.com/questions/105034
        return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
            var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
            return v.toString(16);
        });
    };

    sixpack.Session = function (client_id, host, port) {
        this.client_id = client_id || sixpack.generate_client_id();
        this.host = host || sixpack.host;
        this.port = port || sixpack.port;
    };

    sixpack.Session.prototype = {
        participate: function(experiment_name, alternatives, force, callback) {
            if (typeof force === "function") {
                callback = force;
                force = null;
            }

            if (!(/^[a-z0-9][a-z0-9\-_ ]*$/).test(experiment_name)) {
                return _handle_error(callback, new Error("Bad experiment_name"));
            }

            if (alternatives.length < 2) {
                return _handle_error(callback, new Error("Must specify at least 2 alternatives"));
            }

            for (var i = 0; i < alternatives.length; i += 1) {
                if (!(/^[a-z0-9][a-z0-9\-_ ]*$/).test(alternatives[i])) {
                    return _handle_error(callback, new Error("Bad alternative name: " + alternatives[i]));
                }
            }
            var params = {client_id: this.client_id,
                          experiment: experiment_name,
                          alternatives: alternatives};
            if (force != null && _in_array(alternatives, force)) {
                params.force = force;
            }
            return _request("/participate", params, callback);
        },
        convert: function(experiment_name, callback) {
            var params = {client_id: this.client_id,
                          experiment: experiment_name};
            return _request("/convert", params, callback);
        }
    };

    var _handle_error = function(callback, error) {
        if (on_node) {
            return callback(error);
        }
        throw error;
    }

    var counter = 0;

    var _request = function(endpoint, params, callback) {
        if (!on_node) {
            var cb = "callback" + (++counter);
            params.callback = "sixpack." + cb
            sixpack[cb] = callback;
        }
        var url = _request_uri(endpoint, params);
        if (!on_node) {
{'fraction_non_alphanumeric': 0.1252336448598131, 'fraction_numerical': 0.008811748998664886, 'mean_word_length': 1.7560706401766004, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 4, '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': '4283082', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2034, 'n_words': 480}