如果AWS Lex总是进入Fallback Intent(回退意图),可能是因为你的Intent未被正确匹配或者出现了一些不可预知的情况。
以下几种情况可能会导致Fallback Intent被触发:
在处理意图时,可以添加特定的词汇和上下文,这样可以减少触发Fallback Intent的可能性。但是,如果所有尝试都失败了,需要设置Fallback Intent,该Intent将负责将用户转移到其他Intent、引导用户、或执行默认操作。
以下是一个示例,可使用AWS Python SDK构建Bot,并将Fallback Intent指定为默认回退Intent:
import boto3
lex_client = boto3.client('lex-models')
def create_fallback_intent(bot_name):
response = lex_client.create_intent(
name='FallbackIntent',
description='Fallback Intent for bot: '+bot_name,
sampleUtterances=[
'{query}',
'I meant {query}',
'I said {query}',
'Can you help me',
"I don't know what to do",
],
conclusionStatement={
'messages': [
{
'contentType': 'PlainText',
'content': "Sorry, I could not understand. Can you please rephrase or try later."
},
],
'responseCard': 'Sorry, I could not understand. Can you please rephrase or try later.'
}
)
return response['name']
bot_name = "TestBot"
fallback_intent_name = create_fallback_intent(bot_name)
response = lex_client.put_bot(
name=bot_name,
intents=[
{
'intentName': fallback_intent_name,
'intentVersion': '$LATEST'
}
],
)
在这个示例中,Fallback Intent包含样例文本和一个简单的