gpt4 book ai didi

javascript - Alexa 技能 : Works for the first question but not the second question

转载 作者:行者123 更新时间:2023-12-03 01:12:23 27 4
gpt4 key购买 nike

Alexa 技能适用于第一个问题,但不适用于第二个问题。这是一个使用以下数组的困惑字母测验

var arr = [{"Q":"dcha","A":"chad"},{"Q":"goto","A":"togo"},{"Q":"alim","A":"mali"}];

enter image description here

但是第二个问题给出了错误的答案 enter image description here

多哥的 JSON 输出

{
"version": "1.0",
"session": {
"new": false,
"sessionId": "amzn1.echo-api.session.9dfd014c-e3b7-489c-bdeb-f5771de1ca6b",
"application": {
"applicationId": "amzn1.ask.skill.f2d596ad-f75b-48fc-a48e-c7eb48ad8415"
},
"attributes": {
"Game": {
"count": 3,
"score": 1,
"index": 1,
"end": 0
}
},
"user": {
"userId": "amzn1.ask.account.AETGLHBMP4M7D4AOVQ2ZHB74O7XLYO66NDYSYVOKWBF4TQCINSUCRQTIIPTV3LIIVONHKX3B5LYKCLDXRWWVZWMMMPJXVAZZML63IJDB3AD5FBP4MNOIPOKJLXGSPN6BFM4CJJI5NIMROXVML5EIRWYJBB6CQBQRMROWVNJPXI4MQCH6ITJEJIVSJFD3DW54DEZNQS4QWAJXHLY"
}
},
"context": {
"System": {
"application": {
"applicationId": "amzn1.ask.skill.f2d596ad-fa48e-c7eb48ad8415"
},
"user": {
"userId": "amzn1.ask.account.AETGLHBMP4M7D4AOVQ2ZHB74O7XLYO66NDYSYVOKWBF4TQCINSUCRQTIIPTV3LIIVONHKX3B5LYKCLDXRWWVZWMMMPJXVAZZML63IJDB3AD5FBP4MNOIPOKJLXGSPN6BFM4CJJI5NIMROXVML5EIRWYJBB6CQBQRMROWVNJQWAJXHLY"
},
"device": {
"deviceId": "amzn1.ask.device.AF2B7XVYMPUBHAESIYFYP7NNPRBBONKYO2Y6BEVNUZGCFAR3CHFFQS7CJVD4GYLJIC3VBJLMDWKSP4SWNY4QLJPHIBIY7LS3J43Y4VJIO45WERQHOXW6IKBPKAC7IHFGQ",
"supportedInterf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DroxmoHzjVfXKRPP02s6BCzWFbDmV1VrUDB0FRocGUHGOvhfnk-kLbdwnsRHLgutjaiXg"
}
},
"request": {
"type": "IntentRequest",
"requestId": "amzn1.echo-api.request.6864f5ff-45a9--58373e035519",
"timestamp": "2018-09-03T16:04:04Z",
"locale": "en-US",
"intent": {
"name": "AnswerIntent",
"confirmationStatus": "NONE",
"slots": {
"LetterOne": {
"name": "LetterOne",
"value": "T.",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.-f75b-48fc-a48e-c7eb48ad8415.Alphabets",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "t",
"id": "e358efa489f58062f10dd7316b65649e"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"Guess": {
"name": "Guess",
"value": "Togo",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.f2d596ad-f75b-48fc-a48e-c7eb48ad8415.Answers",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "togo",
"id": "da6f471bab1662dafc3e6845c312dd5f"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"LetterFour": {
"name": "LetterFour",
"value": "O.",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.-f75b-48fc-a48e-c7eb48ad8415.Alphabets",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "o",
"id": "d95679752134a2d9eb61dbd7b91c4bcc"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"LetterTwo": {
"name": "LetterTwo",
"value": "O.",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.-f75b-48fc-a48e-c7eb48ad8415.Alphabets",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "o",
"id": "d95679752134a2d9eb61dbd7b91c4bcc"
}
}
]
}
]
},
"confirmationStatus": "NONE"
},
"LetterThree": {
"name": "LetterThree",
"value": "g.",
"resolutions": {
"resolutionsPerAuthority": [
{
"authority": "amzn1.er-authority.echo-sdk.amzn1.ask.skill.-f75b-48fc-a48e-c7eb48ad8415.Alphabets",
"status": {
"code": "ER_SUCCESS_MATCH"
},
"values": [
{
"value": {
"name": "g",
"id": "b2f5ff47436671b6e533d8dc3614845d"
}
}
]
}
]
},
"confirmationStatus": "NONE"
}
}
}
}
}

"user strict";
var Alexa = require('alexa-sdk');
var arr = [{"Q":"dcha","A":"chad"},{"Q":"goto","A":"togo"},{"Q":"alim","A":"mali"}];

exports.handler = function(event,context,callback) {
var alexa = Alexa.handler(event,context, callback);
alexa.dynamoDBTableName = "CountryLetters";
alexa.appId = "amzn1.ask.skill.f2d596ad-c7eb48ad8415";
alexa.registerHandlers(handler);
initialize(event, function() {
alexa.execute();
});

};

function initialize(event, callback){
if(event.session.attributes.Game === undefined) {
event.session.attributes.Game = {};
}
callback();
}

function getWish() {
var myDate = new Date();
var hours = myDate.getUTCHours();
if (hours < 0) {
hours = hours + 24;
}

if (hours < 12) {
return "Morning ";
} else if (hours < 18) {
return "Afternoon ";
} else {
return "Evening ";
}
}

var handler = {
"start" : function(){
this.attributes.Game.score = 0;
this.attributes.Game.index = 0;
this.attributes.Game.count = 3;
var question = arr[0].Q;
var q = "<break time='0.5s'/>" + question.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
var qc = question.split('').join(" ") ;
var speech = "Welcome to Jumbled Letters, let's begin, here are your jumbled letters " + q + " . Guess the word, you have 3 attempts left ";
this.emit(":askWithCard",speech,speech,"Jumbled letters",qc);
},
"resume" : function(){
var index = this.attributes.Game.index;
var count = this.attributes.Game.count;
var question = arr[index].Q;
var q = "<break time='0.5s'/>" + question.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
var qc = question.split('').join(" ") ;
var speech = "Welcome back, here are your jumbled letters " + q + " . Guess the word, you have " + count + " attempts left ";
this.emit(":askWithCard",speech,speech,"Jumbled letters",qc);
},
"LaunchRequest": function(){
if(this.attributes.Game.score === undefined){
this.emit('start');
}else if(this.attributes.Game.end === 1){
var score = this.attributes.Game.score;
var speech1 = "I have asked all the questions that I have, you have scored " + score + " If you wish to delete this game and start over again, say delete my previous game.";
this.emit(":askWithCard",speech1,speech1,"The End","You have played all the thirty questions, to start over say, DELETE MY GAME");
}else{
var speech = "You have already played the game. Your score is " + this.attributes.Game.score + " . To resume your game say, resume my game, or to delete your previous game and start again, say delete my previous game ";
this.emit(':askWithCard',speech,speech,"Game Already Exists","To resume say, RESUME MY GAME or to delete say, DELETE MY GAME");
}
},
"AMAZON.StartOverIntent" : function(){
if(this.attributes.Game.score === undefined){
this.emit('start');
}else if(this.attributes.Game.end === 1){
var score = this.attributes.Game.score;
var speech1 = "I have asked all the questions that I have, you have scored " + score + " If you wish to delete this game and start over again, say delete my previous game.";
this.emit(":askWithCard",speech1,speech1,"The End","You have played all the thirty questions, to start over say, DELETE MY GAME");
}else{
var speech = "You have already played the game. Your score is " + this.attributes.Game.score + " . To resume your game say, resume my game, or to delete your previous game and start again, say delete my previous game ";
this.emit(':askWithCard',speech,speech,"Game Already Exists","To resume say, RESUME MY GAME or to delete say, DELETE MY GAME");
}
},
"AnswerIntent" : function(){
var guess = this.event.request.intent.slots.Guess.value;
var l1 = this.event.request.intent.slots.LetterOne.value;
var l2 = this.event.request.intent.slots.LetterTwo.value;
var l3 = this.event.request.intent.slots.LetterThree.value;
var l4 = this.event.request.intent.slots.LetterFour.value;
var index = this.attributes.Game.index;
var count = this.attributes.Game.count;
var answer = arr[index].A;
var a = answer.split('');
if(guess !== undefined && l1 !== undefined && l2 !== undefined && l3 !== undefined && l4 !== undefined){
l1 = l1.toLowerCase();
l2 = l2.toLowerCase();
l3 = l3.toLowerCase();
l4 = l4.toLowerCase();
if(guess === answer && (l1 === a[0] || l1 === a[0] + ".") && (l2 === a[1] || l2 === a[1] + ".") && (l3 === a[2] || l3 === a[2] + ".") && (l4 === a[3] || l4 === a[3] + ".") ){
this.attributes.Game.score += 1;
var score = this.attributes.Game.score;
var speech = "Good job, you have guessed it right in " + (4-count) + " attempts. Your score is " + score + " . Do you wish to play again? say Yes to play again and No to quit.";
this.emit(":askWithCard",speech,speech, "Good Job", "Score is " + score + ". To play again say, YES or to quit say, NO");
}else{
this.attributes.Game.count -= 1;
count = this.attributes.Game.count;
var question = arr[index].Q;
var q = "<break time='0.5s'/>" + question.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
if(count > 0){
var speech1 = "Please try again, your jumbled letters were " + q + ". You have " + count + " attempts left";
this.emit(":askWithCard",speech1,speech1,"Attempts Left: " + count, " Try again, your guess " + l1 + " "+ l2 + " "+l3 + " "+ l4 + " " + guess + " is incorrect");
}else{
var ans = "<break time='0.5s'/>" + answer.split('').join("<break time='0.5s'/>") + "<break time='0.5s'/>";
var speech2 = "Sorry, there are no attempts left, the correct word is " + ans + answer + ". Do you wish to play again? say Yes to play again and No to quit";
this.emit(":askWithCard",speech2,speech2,"NO MORE ATTEMPTS LEFT", "The correct word is " + answer);
}
}
}else{
this.emit(":askWithCard","Please guess by spelling out the word","Please guess by spelling out the word","Please Spell the Word","The guess should have the letters spelled out in the right order, followed by the word after that");
}
},
"AMAZON.YesIntent" : function(){
if(this.attributes.Game.index === arr.length - 1){
this.attributes.Game.end = 1;
var score = this.attributes.Game.score;
var speech = "I have asked all the questions that I have, you have scored " + score + " If you wish to delete this game and start over again, say delete my previous game.";
this.emit(":askWithCard",speech,speech,"The End","You have played all the thirty questions, to start over say, DELETE MY GAME");
}else{
this.attributes.Game.index += 1;
this.attributes.Game.count = 3;
this.emit('resume');
}
},
"AMAZON.NoIntent" : function(){
if(this.attributes.Game.index === arr.length - 1){
this.attributes.Game.end = 1;
this.emit(":tell","Thank You");
}else{
this.attributes.Game.index += 1;
this.attributes.Game.count = 3;
this.emit(":tell","Thank you");
}
},
"AMAZON.ResumeIntent" : function(){
if(this.attributes.Game.score === undefined){
var speech = "You have not started the game yet, to start the game say, start a game";
this.emit(":ask",speech,speech);
}
else if(this.attributes.Game.end === 1){
var score = this.attributes.Game.score;
var speech1 = "I have asked all the questions that I have, you have scored " + score + " If you wish to delete this game and start over again, say delete my previous game.";
this.emit(":askWithCard",speech1,speech1,"The End","You have played all the 10 questions, to start over say, DELETE MY GAME");
}else{
this.emit('resume');
}
},
"DeleteIntent" : function(){
if(this.attributes.Game.score === undefined){
var speech = "You have not started the game yet, to start the game say, start a game";
this.emit(":ask",speech,speech);
}else{
this.attributes.Game.end = 0;
this.emit('start');
}
},
"AMAZON.StopIntent" : function(){
this.emit(":tell","Thank you");
},
"AMAZON.CancelIntent" : function(){
this.emit(":tell","Thank you");
},
"AMAZON.HelpIntent" : function(){
this.emit(":askWithCard","I will spell out the jumbled letters of a meaningful word, you have to guess the word by spelling out the letters in the right order and also tell the word, to continue say, resume my game, or to start from the begining say, delete my previous game.","I will spell out the jumbled letters of a meaningful word, you have to guess the word by spelling out the letters in the right order and also tell the word, to continue say, resume my game, or to start from the begining say, delete my previous game.","Help","I will spell out the jumbled letters of a meaningful word, you should guess the word by spelling it out in the Right order and tell the word. For example, a guess should be like B A N K BANK");
},
'Unhandled' : function(){
this.emit("tell", "I did not get any response from you, please open the skill again");
}
};

检查了 Alexa 技能套件仪表板上的插槽值和类型,并确保它们与 3 个国家/地区匹配,也不适用于马里

最佳答案

我认为问题是你没有在正确答案上增加索引变量。给定您的示例对话框,如果您开始游戏,给出答案,然后再次开始游戏,而不说"is",索引将保持在 0。在这种情况下,下一个答案“togo”仍然与“chad”进行比较。

关于javascript - Alexa 技能 : Works for the first question but not the second question,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52162379/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com