-
Notifications
You must be signed in to change notification settings - Fork 0
/
4-train.js
52 lines (49 loc) · 1.39 KB
/
4-train.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved.
*/
const {
FIREBASE_CONFIG,
queryWit,
interactive,
firstEntity,
validateSamples,
} = require('../shared');
const firebase = require('firebase');
const N = 3;
const THRESHOLD = 0.7;
function handleMessage(question, readline) {
return queryWit(question, N).then(({entities}) => {
const intents = entities['intent'] || [];
const bestIntent = intents[0];
const dateTime = firstEntity(entities, 'datetime') || {};
if (!bestIntent || bestIntent.confidence < THRESHOLD) {
console.log('🤖 what would you like to do?');
intents.forEach(intent => console.log(`\n -- ${intent.value}`));
readline.question('choice > ', choice => {
validateSamples([
{
text: question,
entities: [
{
entity: 'intent',
value: choice,
},
],
},
]).then(({n}) => console.log(`validated ${n}!`));
console.log(`🤖 okay, running > ${choice}`);
});
return;
}
return firebase
.database()
.ref(`answers/${bestIntent.value}`)
.once('value')
.then(snapshot => {
const val = snapshot.val();
console.log(`🤖 ${val || bestIntent.value}`, dateTime);
});
});
}
firebase.initializeApp(FIREBASE_CONFIG);
interactive(handleMessage);