<commit_before>require 'quartz'
require 'base64'


module Babl
  def self.bin_path
    system = `which babl-rpc`.strip
    if system.empty?
      bin = 'babl-rpc_'
      bin += "linux_amd64" if RUBY_PLATFORM =~ /linux/
      bin += "darwin_amd64" if RUBY_PLATFORM =~ /darwin/
      File.expand_path("../../bin/#{bin}", __FILE__)
    else
      system
    end
  end

  def self.version
    `#{bin_path} -version`.strip
  end

  def self.client
    puts "Using bin '#{bin_path}'"
    @client ||= Quartz::Client.new(bin_path: bin_path)
  end

  def self.module name, opts = {}
    params = {'Name' => name}
    if opts[:in]
      params['Stdin'] = Base64.encode64(opts[:in])
    end
    if opts[:env]
      params['Env'] = opts[:env].inject({}) { |h, (k,v)| h[k.to_s] = v; h }
    end
    res = client[:babl].call('Module', params)
    Base64.decode64(res["Stdout"])
  end
end
<commit_msg>Strip trailing newline of base64 encoding<commit_after>require 'quartz'
require 'base64'


module Babl
  def self.bin_path
    system = `which babl-rpc`.strip
    if system.empty?
      bin = 'babl-rpc_'
      bin += "linux_amd64" if RUBY_PLATFORM =~ /linux/
      bin += "darwin_amd64" if RUBY_PLATFORM =~ /darwin/
      File.expand_path("../../bin/#{bin}", __FILE__)
    else
      system
    end
  end

  def self.version
    `#{bin_path} -version`.strip
  end

  def self.client
    puts "Using bin '#{bin_path}'"
    @client ||= Quartz::Client.new(bin_path: bin_path)
  end

  def self.module name, opts = {}
    params = {'Name' => name}
    if opts[:in]
      params['Stdin'] = Base64.encode64(opts[:in]).strip
    end
    if opts[:env]
      params['Env'] = opts[:env].inject({}) { |h, (k,v)| h[k.to_s] = v; h }
    end
    res = client[:babl].call('Module', params)
    Base64.decode64(res["Stdout"])
  end
end

{'fraction_non_alphanumeric': 0.16555924695459578, 'fraction_numerical': 0.016611295681063124, 'mean_word_length': 2.74120082815735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2673053', 'n_tokens_mistral': 700, 'n_tokens_neox': 673, 'n_words': 153}