mirror of
https://github.com/leon-ai/leon.git
synced 2024-11-24 04:31:31 +03:00
feat: transfer language from core to skills + support thematics on Akinator skill
This commit is contained in:
parent
76cae42fde
commit
b35a249bf6
@ -17,6 +17,7 @@ def main():
|
||||
skill = import_module('skills.' + intent_obj['domain'] + '.' + intent_obj['skill'] + '.src.actions.' + intent_obj['action'])
|
||||
|
||||
params = {
|
||||
'lang': intent_obj['lang'],
|
||||
'utterance': intent_obj['utterance'],
|
||||
'current_entities': intent_obj['current_entities'],
|
||||
'entities': intent_obj['entities'],
|
||||
|
@ -289,7 +289,6 @@ class Nlu {
|
||||
|
||||
// Ensure expected items are in the utterance, otherwise clean context and reprocess
|
||||
if (!hasMatchingEntity && !hasMatchingResolver) {
|
||||
console.log('HEREEEEEEE1')
|
||||
this.brain.talk(`${this.brain.wernicke('random_context_out_of_topic')}.`)
|
||||
this.conv.cleanActiveContext()
|
||||
await this.process(utterance, opts)
|
||||
@ -302,7 +301,6 @@ class Nlu {
|
||||
if (processedData.core?.restart === true) {
|
||||
const { originalUtterance } = this.conv.activeContext
|
||||
|
||||
console.log('HEREEEEEEE2')
|
||||
this.conv.cleanActiveContext()
|
||||
await this.process(originalUtterance, opts)
|
||||
return null
|
||||
@ -313,7 +311,6 @@ class Nlu {
|
||||
* and there is an explicit stop of the loop from the skill
|
||||
*/
|
||||
if (!processedData.action.next_action && processedData.core?.isInActionLoop === false) {
|
||||
console.log('HEREEEEEEE3')
|
||||
this.conv.cleanActiveContext()
|
||||
return null
|
||||
}
|
||||
@ -536,7 +533,6 @@ class Nlu {
|
||||
|
||||
const newContextName = `${this.nluResultObj.classification.domain}.${skillName}`
|
||||
if (this.conv.activeContext.name !== newContextName) {
|
||||
console.log('HEREEEEEEE4')
|
||||
this.conv.cleanActiveContext()
|
||||
}
|
||||
this.conv.activeContext = {
|
||||
@ -560,7 +556,6 @@ class Nlu {
|
||||
|
||||
// Prepare next action if there is one queuing
|
||||
if (processedData.nextAction) {
|
||||
console.log('HEREEEEEEE5')
|
||||
this.conv.cleanActiveContext()
|
||||
this.conv.activeContext = {
|
||||
lang: this.brain.lang,
|
||||
@ -659,13 +654,11 @@ class Nlu {
|
||||
}
|
||||
}
|
||||
|
||||
console.log('HEREEEEEEE6')
|
||||
this.conv.cleanActiveContext()
|
||||
|
||||
return this.brain.execute(this.nluResultObj, { mute: opts.mute })
|
||||
}
|
||||
|
||||
console.log('HEREEEEEEE7')
|
||||
this.conv.cleanActiveContext()
|
||||
return null
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
import utils
|
||||
from ..lib import akinator, db
|
||||
|
||||
# TODO: emit suggestion on each question of the loop
|
||||
# TODO: catch network error
|
||||
# TODO: timeout on question/answer
|
||||
|
||||
@ -21,30 +22,30 @@ def guess(params):
|
||||
|
||||
aki = akinator.Akinator()
|
||||
|
||||
new_session = db.get_new_session()
|
||||
response = new_session['response']
|
||||
session = db.get_session()
|
||||
response = session['response']
|
||||
formatted_response = aki._parse_response(response)
|
||||
aki.session = new_session['session']
|
||||
aki.signature = new_session['signature']
|
||||
aki.progression = new_session['progression']
|
||||
aki.uri = new_session['uri']
|
||||
aki.timestamp = new_session['timestamp']
|
||||
aki.server = new_session['server']
|
||||
aki.child_mode = new_session['child_mode']
|
||||
aki.frontaddr = new_session['frontaddr']
|
||||
aki.question_filter = new_session['question_filter']
|
||||
aki.session = session['session']
|
||||
aki.signature = session['signature']
|
||||
aki.progression = session['progression']
|
||||
aki.uri = session['uri']
|
||||
aki.timestamp = session['timestamp']
|
||||
aki.server = session['server']
|
||||
aki.child_mode = session['child_mode']
|
||||
aki.frontaddr = session['frontaddr']
|
||||
aki.question_filter = session['question_filter']
|
||||
|
||||
resp = aki._parse_response(response)
|
||||
aki._update(resp, '"step":"0"' in response)
|
||||
|
||||
if new_session['progression'] > 80:
|
||||
if session['progression'] > 80:
|
||||
aki.win()
|
||||
# name; description; absolute_picture_path
|
||||
return utils.output('end', aki.first_guess['name'])
|
||||
|
||||
aki.answer(answer)
|
||||
|
||||
db.create_new_session({
|
||||
db.upsert_session({
|
||||
'response': aki.response,
|
||||
'session': aki.session,
|
||||
'signature': aki.signature,
|
||||
|
@ -5,11 +5,19 @@ import utils
|
||||
from ..lib import akinator, db
|
||||
|
||||
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()
|
||||
|
||||
q = aki.start_game('en')
|
||||
q = aki.start_game(theme_lang)
|
||||
|
||||
db.create_new_session({
|
||||
db.upsert_session({
|
||||
'response': aki.response,
|
||||
'session': aki.session,
|
||||
'progression': aki.progression,
|
||||
|
@ -5,19 +5,20 @@ import utils
|
||||
# Skill database
|
||||
db = utils.db()['db']
|
||||
|
||||
table = utils.db()['table']
|
||||
|
||||
# Session table
|
||||
session_table = db.table('session')
|
||||
|
||||
# Time stamp
|
||||
timestamp = int(time())
|
||||
|
||||
def create_new_session(session):
|
||||
"""Creation new session"""
|
||||
def upsert_session(session):
|
||||
"""Save progress/info about the session"""
|
||||
|
||||
session_table.insert(session)
|
||||
session_table.upsert(table.Document(session, doc_id=0))
|
||||
|
||||
def get_new_session():
|
||||
"""Get the newly created session"""
|
||||
def get_session():
|
||||
"""Get current session progress data"""
|
||||
|
||||
|
||||
return session_table.all()[-1]
|
||||
return session_table.get(doc_id=0)
|
||||
|
@ -7,7 +7,7 @@ from ..lib import db
|
||||
def guess(params):
|
||||
"""Check whether the given number matches the chosen number"""
|
||||
|
||||
entities, slots = params['entities'], params['slots']
|
||||
entities = params['entities']
|
||||
given_nb = -1
|
||||
nb_to_guess = db.get_new_game()['nb']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user