<commit_before># frozen_string_literal: true
require 'net/http'
config_file = 'config/mse_router_info.yml'

REPORT_MISSING_CONFIG_KEY = -> (key) {
  raise ArgumentError, "Missing key #{key} in #{config_file}"
}

unless File.file?(config_file)
  raise IOError, 'No router configuration YAML file found'
end

config_data = YAML.load_file(config_file)

service_name = config_data.fetch 'name', &REPORT_MISSING_CONFIG_KEY
service_url = config_data.fetch 'uri', &REPORT_MISSING_CONFIG_KEY
router_url = config_data.fetch 'router_uri', &REPORT_MISSING_CONFIG_KEY
security_token = config_data.fetch 'security_token', &REPORT_MISSING_CONFIG_KEY
router_url = router_url + '/services/register'

res = Net::HTTP.post_form(
  URI.parse(router_url),
  name: service_name,
  url: service_url,
  models: config_data['accessible_models'],
  security_token: security_token
)

raise 'The router API response was invalid' if res.code != '200'<commit_msg>Disable router check-in with an environment variable<commit_after># frozen_string_literal: true
require 'net/http'
config_file = 'config/mse_router_info.yml'

REPORT_MISSING_CONFIG_KEY = -> (key) {
  raise ArgumentError, "Missing key #{key} in #{config_file}"
}

unless ENV['DISABLE_ROUTER_CHECKIN']

  unless File.file?(config_file)
    raise IOError, 'No router configuration YAML file found'
  end

  config_data = YAML.load_file(config_file)

  service_name = config_data.fetch 'name', &REPORT_MISSING_CONFIG_KEY
  service_url = config_data.fetch 'uri', &REPORT_MISSING_CONFIG_KEY
  router_url = config_data.fetch 'router_uri', &REPORT_MISSING_CONFIG_KEY
  security_token = config_data.fetch 'security_token', &REPORT_MISSING_CONFIG_KEY
  router_url = router_url + '/services/register'

  res = Net::HTTP.post_form(
    URI.parse(router_url),
    name: service_name,
    url: service_url,
    models: config_data['accessible_models'],
    security_token: security_token
  )

  raise 'The router API response was invalid' if res.code != '200'
end
{'fraction_non_alphanumeric': 0.10136157337367625, 'fraction_numerical': 0.0030257186081694403, 'mean_word_length': 6.035460992907802, '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': '933226', 'n_tokens_mistral': 687, 'n_tokens_neox': 660, 'n_words': 146}