1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-11-28 04:04:58 +03:00

feat: transfer language from core to skills + support thematics on Akinator skill

This commit is contained in:
louistiti 2022-07-10 09:21:43 +08:00
parent 76cae42fde
commit b35a249bf6
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
6 changed files with 34 additions and 30 deletions

View File

@ -17,6 +17,7 @@ def main():
skill = import_module('skills.' + intent_obj['domain'] + '.' + intent_obj['skill'] + '.src.actions.' + intent_obj['action']) skill = import_module('skills.' + intent_obj['domain'] + '.' + intent_obj['skill'] + '.src.actions.' + intent_obj['action'])
params = { params = {
'lang': intent_obj['lang'],
'utterance': intent_obj['utterance'], 'utterance': intent_obj['utterance'],
'current_entities': intent_obj['current_entities'], 'current_entities': intent_obj['current_entities'],
'entities': intent_obj['entities'], 'entities': intent_obj['entities'],

View File

@ -289,7 +289,6 @@ class Nlu {
// Ensure expected items are in the utterance, otherwise clean context and reprocess // Ensure expected items are in the utterance, otherwise clean context and reprocess
if (!hasMatchingEntity && !hasMatchingResolver) { if (!hasMatchingEntity && !hasMatchingResolver) {
console.log('HEREEEEEEE1')
this.brain.talk(`${this.brain.wernicke('random_context_out_of_topic')}.`) this.brain.talk(`${this.brain.wernicke('random_context_out_of_topic')}.`)
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
await this.process(utterance, opts) await this.process(utterance, opts)
@ -302,7 +301,6 @@ class Nlu {
if (processedData.core?.restart === true) { if (processedData.core?.restart === true) {
const { originalUtterance } = this.conv.activeContext const { originalUtterance } = this.conv.activeContext
console.log('HEREEEEEEE2')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
await this.process(originalUtterance, opts) await this.process(originalUtterance, opts)
return null return null
@ -313,7 +311,6 @@ class Nlu {
* and there is an explicit stop of the loop from the skill * and there is an explicit stop of the loop from the skill
*/ */
if (!processedData.action.next_action && processedData.core?.isInActionLoop === false) { if (!processedData.action.next_action && processedData.core?.isInActionLoop === false) {
console.log('HEREEEEEEE3')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
return null return null
} }
@ -536,7 +533,6 @@ class Nlu {
const newContextName = `${this.nluResultObj.classification.domain}.${skillName}` const newContextName = `${this.nluResultObj.classification.domain}.${skillName}`
if (this.conv.activeContext.name !== newContextName) { if (this.conv.activeContext.name !== newContextName) {
console.log('HEREEEEEEE4')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
} }
this.conv.activeContext = { this.conv.activeContext = {
@ -560,7 +556,6 @@ class Nlu {
// Prepare next action if there is one queuing // Prepare next action if there is one queuing
if (processedData.nextAction) { if (processedData.nextAction) {
console.log('HEREEEEEEE5')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
this.conv.activeContext = { this.conv.activeContext = {
lang: this.brain.lang, lang: this.brain.lang,
@ -659,13 +654,11 @@ class Nlu {
} }
} }
console.log('HEREEEEEEE6')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
return this.brain.execute(this.nluResultObj, { mute: opts.mute }) return this.brain.execute(this.nluResultObj, { mute: opts.mute })
} }
console.log('HEREEEEEEE7')
this.conv.cleanActiveContext() this.conv.cleanActiveContext()
return null return null
} }

View File

@ -4,6 +4,7 @@
import utils import utils
from ..lib import akinator, db from ..lib import akinator, db
# TODO: emit suggestion on each question of the loop
# TODO: catch network error # TODO: catch network error
# TODO: timeout on question/answer # TODO: timeout on question/answer
@ -21,30 +22,30 @@ def guess(params):
aki = akinator.Akinator() aki = akinator.Akinator()
new_session = db.get_new_session() session = db.get_session()
response = new_session['response'] response = session['response']
formatted_response = aki._parse_response(response) formatted_response = aki._parse_response(response)
aki.session = new_session['session'] aki.session = session['session']
aki.signature = new_session['signature'] aki.signature = session['signature']
aki.progression = new_session['progression'] aki.progression = session['progression']
aki.uri = new_session['uri'] aki.uri = session['uri']
aki.timestamp = new_session['timestamp'] aki.timestamp = session['timestamp']
aki.server = new_session['server'] aki.server = session['server']
aki.child_mode = new_session['child_mode'] aki.child_mode = session['child_mode']
aki.frontaddr = new_session['frontaddr'] aki.frontaddr = session['frontaddr']
aki.question_filter = new_session['question_filter'] aki.question_filter = session['question_filter']
resp = aki._parse_response(response) resp = aki._parse_response(response)
aki._update(resp, '"step":"0"' in response) aki._update(resp, '"step":"0"' in response)
if new_session['progression'] > 80: if session['progression'] > 80:
aki.win() aki.win()
# name; description; absolute_picture_path # name; description; absolute_picture_path
return utils.output('end', aki.first_guess['name']) return utils.output('end', aki.first_guess['name'])
aki.answer(answer) aki.answer(answer)
db.create_new_session({ db.upsert_session({
'response': aki.response, 'response': aki.response,
'session': aki.session, 'session': aki.session,
'signature': aki.signature, 'signature': aki.signature,

View File

@ -5,11 +5,19 @@ import utils
from ..lib import akinator, db from ..lib import akinator, db
def setup(params): def setup(params):
"""Initialize new session"""
slots, lang = params['slots'], params['lang']
thematic = slots['thematic']['resolution']['value']
theme_lang = lang
if thematic != 'characters':
theme_lang = lang + '_' + thematic
aki = akinator.Akinator() aki = akinator.Akinator()
q = aki.start_game('en') q = aki.start_game(theme_lang)
db.create_new_session({ db.upsert_session({
'response': aki.response, 'response': aki.response,
'session': aki.session, 'session': aki.session,
'progression': aki.progression, 'progression': aki.progression,

View File

@ -5,19 +5,20 @@ import utils
# Skill database # Skill database
db = utils.db()['db'] db = utils.db()['db']
table = utils.db()['table']
# Session table # Session table
session_table = db.table('session') session_table = db.table('session')
# Time stamp # Time stamp
timestamp = int(time()) timestamp = int(time())
def create_new_session(session): def upsert_session(session):
"""Creation new session""" """Save progress/info about the session"""
session_table.insert(session) session_table.upsert(table.Document(session, doc_id=0))
def get_new_session(): def get_session():
"""Get the newly created session""" """Get current session progress data"""
return session_table.get(doc_id=0)
return session_table.all()[-1]

View File

@ -7,7 +7,7 @@ from ..lib import db
def guess(params): def guess(params):
"""Check whether the given number matches the chosen number""" """Check whether the given number matches the chosen number"""
entities, slots = params['entities'], params['slots'] entities = params['entities']
given_nb = -1 given_nb = -1
nb_to_guess = db.get_new_game()['nb'] nb_to_guess = db.get_new_game()['nb']