<commit_before>//All NLU specific functions and routes.
var request = require('request');
const db = require('../../db/db')
const NodeCache = require( "node-cache" );
//https://github.com/mpneuried/nodecache
const nluParseLogCache = new NodeCache();

function getRasaNluStatus(req, res, next) {
  console.log("Rasa NLU Status Request -> " + global.rasanluendpoint + "/status");
  request(global.rasanluendpoint + '/status', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function getRasaNluConfig(req, res, next) {
  console.log("Rasa NLU Config Request -> " + global.rasanluendpoint + "/config");
  request(global.rasanluendpoint + '/config', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function getRasaNluVersion(req, res, next) {
  console.log("Rasa NLU Version Request -> " + global.rasanluendpoint + "/version");
  request(global.rasanluendpoint + '/version', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function trainRasaNlu(req, res, next) {
  console.log("Rasa NLU Train Request -> " + global.rasanluendpoint + "/train?project=" + req.query.project);
  logRequest(req, "train", {project: req.query.project, agent: req.query.name, data: req.body});

  request({
    method: "POST",
    uri: global.rasanluendpoint + "/train?project=" + req.query.project,
    body: JSON.stringify(req.body)
  }, function (error, response, body) {
    if(error){
      console.log("Error Occured when posting data to nlu endpoint. " + error);<commit_msg>correct content type header allowing succesfull call to rasa nlu train endpoint<commit_after>//All NLU specific functions and routes.
var request = require('request');
const db = require('../../db/db')
const NodeCache = require( "node-cache" );
//https://github.com/mpneuried/nodecache
const nluParseLogCache = new NodeCache();

function getRasaNluStatus(req, res, next) {
  console.log("Rasa NLU Status Request -> " + global.rasanluendpoint + "/status");
  request(global.rasanluendpoint + '/status', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function getRasaNluConfig(req, res, next) {
  console.log("Rasa NLU Config Request -> " + global.rasanluendpoint + "/config");
  request(global.rasanluendpoint + '/config', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function getRasaNluVersion(req, res, next) {
  console.log("Rasa NLU Version Request -> " + global.rasanluendpoint + "/version");
  request(global.rasanluendpoint + '/version', function (error, response, body) {
    try {
      if (body !== undefined) sendOutput(200, res, body);
      else sendOutput(500, res, '{"error" : "Server Error"}');
    } catch (err) {
      console.log(err);
      sendOutput(500, res, '{"error" : ' + err + '}');
    }
  });
}

function trainRasaNlu(req, res, next) {
  console.log("Rasa NLU Train Request -> " + global.rasanluendpoint + "/train?project=" + req.query.project);
  logRequest(req, "train", {project: req.query.project, agent: req.query.name, data: req.body});

  request({
    method: "POST",
    uri: global.rasanluendpoint + "/train?project=" + req.query.project,
    json: req.body
  }, function (error, response, body) {
    if(error){
      console.log("Error Occured when posting data to nlu endpoint. " + error);
{'fraction_non_alphanumeric': 0.17510354348826507, 'fraction_numerical': 0.012425218591808559, 'mean_word_length': 3.6097560975609757, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 2, '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': '7233216', 'n_tokens_mistral': 1441, 'n_tokens_neox': 1402, 'n_words': 352}