Skip to content

Commit

Permalink
feat(server): slot filling PoC (tmp wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
louistiti committed Mar 20, 2022
1 parent 2b03d98 commit 95bfcfe
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
6 changes: 3 additions & 3 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ LEON_HTTP_API_LANG=en-US
# Enable/disable collaborative logger
LEON_LOGGER=true

# Python WebSocket server
LEON_PY_WS_SERVER_HOST=0.0.0.0
LEON_PY_WS_SERVER_PORT=1342
# Python TCP server
LEON_PY_TCP_SERVER_HOST=0.0.0.0
LEON_PY_TCP_SERVER_PORT=1342

# Path to the Pipfile
PIPENV_PIPFILE=bridges/python/Pipfile
Expand Down
4 changes: 2 additions & 2 deletions bridges/python/tcp_server/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

nlp.load_spacy_model()

tcp_server_host = os.environ.get('LEON_PY_WS_SERVER_HOST', '0.0.0.0')
tcp_server_port = os.environ.get('LEON_PY_WS_SERVER_PORT', 1342)
tcp_server_host = os.environ.get('LEON_PY_TCP_SERVER_HOST', '0.0.0.0')
tcp_server_port = os.environ.get('LEON_PY_TCP_SERVER_PORT', 1342)

tcp_server = TCPServer(tcp_server_host, tcp_server_port)
tcp_server.init()
18 changes: 16 additions & 2 deletions scripts/train.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default () => new Promise(async (resolve, reject) => {

const nlp = container.get('nlp')
const nluManager = container.get('nlu-manager')
// const slotManager = container.get('slot-manager')
// const slotManager = container.get('SlotManager')

nluManager.settings.log = false
nluManager.settings.trainByDomain = true
Expand Down Expand Up @@ -72,12 +72,26 @@ export default () => new Promise(async (resolve, reject) => {
for (let k = 0; k < actionsKeys.length; k += 1) {
const actionName = actionsKeys[k]
const actionObj = actions[actionName]
const intent = `${skillName}.${actionName}`
const { utterance_samples: utteranceSamples, answers } = actionObj

nlp.assignDomain(lang, `${skillName}.${actionName}`, currentDomain.name)

/**
* TODO:
* 1. Merge person, location and organization to the
* NER before processing NLU (cf. line 210 in nlu.js)
* 2. Grab intents with slots
* 3. .addSlot() as per the slots config
*/
if (intent === 'guess_the_number.start') {
console.log('iiin')
// nlp.slotManager.addSlot(intent, 'number', true, { [lang]: 'How many players?' })
nlp.slotManager.addSlot(intent, 'person', true, { [lang]: 'How many players?' })
}

for (let l = 0; l < utteranceSamples.length; l += 1) {
nlp.addDocument(lang, utteranceSamples[l], `${skillName}.${actionName}`)
nlp.addDocument(lang, utteranceSamples[l], intent)
}

// Train NLG if the skill has a dialog type
Expand Down
18 changes: 16 additions & 2 deletions server/src/core/nlu.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,8 @@ class Nlu {
global.tcpServerProcess = spawn(`pipenv run python bridges/python/tcp_server/main.py ${locale}`, { shell: true })

global.tcpClient = new TcpClient(
process.env.LEON_PY_WS_SERVER_HOST,
process.env.LEON_PY_WS_SERVER_PORT
process.env.LEON_PY_TCP_SERVER_HOST,
process.env.LEON_PY_TCP_SERVER_PORT
)

global.tcpClient.ee.removeListener('connected', connectedHandler)
Expand Down Expand Up @@ -207,6 +207,20 @@ class Nlu {
}

try {
const [{ entity, resolution }] = obj.entities
const testoEntity = {
[entity]: {
options: {
[resolution.value]: [resolution.value]
}
}
}
this.nlp.addEntities(testoEntity, this.brain.lang)

const result2 = await this.nlp.process(utterance)

console.log('result2', result2)

// Inject action entities with the others if there is
const data = await this.brain.execute(obj, { mute: opts.mute })
const processingTimeEnd = Date.now()
Expand Down
4 changes: 2 additions & 2 deletions server/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import server from '@/core/http-server/server'
global.tcpServerProcess = spawn(`pipenv run python bridges/python/tcp_server/main.py ${lang.getShortCode(process.env.LEON_LANG)}`, { shell: true })

global.tcpClient = new TcpClient(
process.env.LEON_PY_WS_SERVER_HOST,
process.env.LEON_PY_WS_SERVER_PORT
process.env.LEON_PY_TCP_SERVER_HOST,
process.env.LEON_PY_TCP_SERVER_PORT
)

await server.init()
Expand Down

0 comments on commit 95bfcfe

Please sign in to comment.