1
1
mirror of https://github.com/leon-ai/leon.git synced 2024-09-19 22:07:10 +03:00

feat(skill/mbti): main logic backbone

This commit is contained in:
louistiti 2022-07-02 23:21:46 +08:00
parent 6ed88a5946
commit 33109a4c8b
No known key found for this signature in database
GPG Key ID: 7ECA3DD523793FE6
4 changed files with 35 additions and 17 deletions

View File

@ -299,8 +299,11 @@ class Nlu {
return null
}
// In case there is no next action to prepare anymore
if (!processedData.action.next_action) {
/**
* In case there is no next action to prepare anymore
* and there is an explicit stop of the loop from the skill
*/
if (!processedData.action.next_action && processedData.core?.isInActionLoop === false) {
this.conv.cleanActiveContext()
return null
}

View File

@ -1,14 +1,11 @@
{
"actions": {
"setup": {
"type": "dialog",
"type": "logic",
"utterance_samples": [
"I want to know my MBTI personality type",
"Start a personality type [quiz|questionnaire|test]"
],
"answers": [
"Alright, let's go!<br><br>1/20<br>At a party do you:<ul><li>a. Interact with many, including strangers</li><li>b. Interact with a few, known to you</li></ul>"
],
"next_action": "quiz"
},
"quiz": {
@ -56,6 +53,7 @@
}
},
"answers": {
"1": ["%question%/20<br>At a party do you:<ul><li>a. Interact with many, including strangers</li><li>b. Interact with a few, known to you</li></ul>"],
"2": ["%question%/20<br>Is it worse to:<ul><li>a. Have your \"head in the clouds\"</li><li>b. Be \"in a rut\"</li></ul>"],
"3": ["%question%/20<br>Is it worse to:<ul><li>a. Have your \"head in the clouds\"</li><li>b. Be \"in a rut\"</li></ul>"]
}

View File

@ -5,26 +5,24 @@ import utils
from ..lib import db
def quiz(params):
"""TODO"""
"""Loop over the questions and track choices"""
resolvers = params['resolvers']
for resolver in resolvers:
if resolver['name'] == 'mbti_quiz':
answer = resolver['value']
if resolver['name'] == 'form':
choice = resolver['value']
session = db.get_session()
current_question = 1
if session != None:
current_question = session['current_question']
current_question = session['current_question'] + 1
db.upsert_session(current_question)
current_question += 1
if current_question == 20:
# TODO
return utils.output('end', 'Your personality type is...', { 'isInActionLoop': False })
return utils.output('end', { 'key': current_question, 'data': { 'question': current_question }})
return utils.output('end', { 'key': str(current_question),
'data': {
'question': str(current_question)
}
})

View File

@ -0,0 +1,19 @@
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import utils
from ..lib import db
def setup(params):
"""Initialize session"""
session = db.get_session()
current_question = 1
db.upsert_session(current_question)
return utils.output('end', { 'key': str(current_question),
'data': {
'question': str(current_question)
}
})