Commit f71948d0 authored by henrik.prangel's avatar henrik.prangel
Browse files

JUT-58 & JUT-59 Add functionality to train bots

parent bd7065b6
......@@ -3,6 +3,7 @@ import axios from 'axios';
import { FAILURE, REQUEST, SUCCESS } from 'app/shared/reducers/action-type.util';
import { INSTITUTION_NAMES } from "app/modules/training-interface/training-interface.reducer";
import { AUTHORITIES } from "app/config/constants";
import { translate } from 'react-jhipster';
export const ACTION_TYPES = {
FETCH_INTENTS_LIST: 'intents/FETCH_INTENTS_LIST',
......@@ -13,6 +14,7 @@ export const ACTION_TYPES = {
POST_NLU_FILE: 'intents/POST_NLU_FILE',
POST_STORIES_FILE: 'intents/POST_STORIES_FILE',
SET_CURRENTLY_ACTIVE_FILE: 'intents/SET_CURRENTLY_ACTIVE_FILE',
TRAIN_CHATBOT: 'intents/TRAIN_CHATBOT',
};
export const RASA_FILE_TYPES = {
......@@ -181,6 +183,9 @@ export const postNLUFile = (userAuthorities, nluFile) => {
return {
type: ACTION_TYPES.POST_NLU_FILE,
payload: axios.post(requestUrl, nluFile),
meta: {
successMessage: translate('training.model.modelSaved'),
},
};
};
......@@ -190,6 +195,21 @@ export const postStoriesFile = (userAuthorities, storiesFile) => {
return {
type: ACTION_TYPES.POST_STORIES_FILE,
payload: axios.post(requestUrl, storiesFile, {headers: {['Content-Type']: 'text/plain'}}),
meta: {
successMessage: translate('training.model.modelSaved'),
},
};
};
export const trainBot = (userAuthorities) => {
const requestUrl = getBotUrlByUserAuthorities(userAuthorities, "train");
return {
type: ACTION_TYPES.TRAIN_CHATBOT,
payload: axios.post(requestUrl),
meta: {
successMessage: translate('training.model.trainingStarted'),
},
};
};
......
......@@ -8,7 +8,8 @@ import {
postStoriesFile,
setCurrentlyActiveFile,
updateNLUFile,
updateStoriesFile
updateStoriesFile,
trainBot
} from "app/modules/training-interface/intents/intents.reducer";
import { RASA_FILE_TYPES } from "app/modules/training-interface/intents/intents.reducer";
import Avatar from "app/shared/common-components/avatar/avatar";
......@@ -48,6 +49,10 @@ export const Intents = (props: IIntentsProp) => {
}
}
const trainChatBot = () => {
dispatch(trainBot(userAuthorities))
}
const setActiveIntentOnClick = (intent) => {
setActiveIntent(intent.name)
setIntentExampleList(intent.examples)
......@@ -176,10 +181,10 @@ export const Intents = (props: IIntentsProp) => {
<Translate contentKey="training.model.actions">Actions</Translate>
</span>
<hr className="divider"/>
<Button className="room-button" onClick={postCurrentlyActiveFile}>
<Button className="room-button" onClick={postCurrentlyActiveFile} disabled={!nluFile.length && !storiesFile.length}>
<Translate contentKey="training.model.saveChangesInModel">Save changes in model</Translate>
</Button>
<Button className="room-button train-button">
<Button className="room-button train-button" onClick={trainChatBot}>
<Translate contentKey="training.model.train">Train</Translate>
</Button>
</div>
......
......@@ -15,8 +15,10 @@
"getNLUFile": "Display chatbot intent's",
"getStoriesFile": "Display chatbot stories",
"saveChangesInModel": "Save changes into model",
"train": "Train chatbot with saved model",
"saveActiveFile": "Save"
"train": "Train chatbot",
"saveActiveFile": "Save",
"trainingStarted": "Training started",
"modelSaved": "Changes saved in model"
}
}
}
......@@ -15,8 +15,10 @@
"getNLUFile": "Kuva juturoboti intent'e",
"getStoriesFile": "Kuva juturoboti lugusid",
"saveChangesInModel": "Salvesta muudatused mudelisse",
"train": "Treeni vestlusrobot salvestatud mudeliga",
"saveActiveFile": "Salvesta"
"train": "Treeni mudeli põhjal",
"saveActiveFile": "Salvesta",
"trainingStarted": "Treenimine alustatud",
"modelSaved": "Muudatused salvestatud mudelisse"
}
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment