1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-11 10:25:40 +03:00

feat(server): slot filling PoC (tmp wip)

This commit is contained in:
louistiti 2022-03-21 00:01:44 +08:00
parent 2b03d981ab
commit 95bfcfe422
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
5 changed files with 39 additions and 11 deletions

View File

@ -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

View File

@ -13,8 +13,8 @@ load_dotenv(dotenv_path)
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()

View File

@ -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
@ -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

View File

@ -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)
@ -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()

View File

@ -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()