gpt4 book ai didi

node.js - 如何在同一步骤中组合 ChoicePrompt 和 TextPrompt

转载 作者:太空宇宙 更新时间:2023-11-03 23:14:28 24 4
gpt4 key购买 nike

我在 node.js 中使用 Microsoft Bot Framework V4。在对话框的一个步骤中,我们需要使用 ChoicePrompt 对象以及 TextPrompt 来组合按钮。如果用户单击按钮,将触发建议的操作,如果用户编写纯文本,我们会使用 LUIS 和某些意图来处理该操作。问题在于将这两种操作结合​​起来。

我试图在使用 ChoicePrompt 时避免重新提示,但我无法做到。我还寻找其他可以直接组合按钮和文本的提示,但似乎没有。

首先,我声明我在提示中使用的对象:

class ExampleDialog extends LogoutDialog {
constructor(userState, logger) {
super(EXAMPLE_DIALOG);

this.addDialog(new TextPrompt(TEXT_PROMPT));
this.addDialog(new ChoicePrompt(CHOICE_PROMPT));

其次,在步骤中,我使用之前声明的提示:

async firstStep(step) {    
const promptOptions = {
prompt: 'Text to prompt',
retryPrompt: 'Retry text prompt',
choices: ChoiceFactory.toChoices(['option1', 'option2', 'option3'])
};

const promptAction = await step.prompt(A_PROMPT_ID, promptOptions);

return promptAction;
}

async secondStep(step) {
const thePreviousStepResult = step.result.values
}

最佳答案

当您想要接受任何字符串时,可以使用文本提示。请记住,您可以包含任何事件作为提示选项的 prompt 属性,并且该事件可以包含附件、建议的操作等。您可以在 source code 中看到选择提示只需调用 Prompt.appendChoices,它使用 ChoiceFactory 为其事件生成按钮。你也可以做同样的事情:

const promptOptions = {
prompt: ChoiceFactory.forChannel(step.context, ['option1', 'option2', 'option3'], 'Text to prompt')
// You can also include a retry prompt if you like,
// but there's no need to include the choices property in a text prompt
};

const promptAction = await step.prompt(TEXT_PROMPT, promptOptions);

return promptAction;

Step 1

Step 2

关于node.js - 如何在同一步骤中组合 ChoicePrompt 和 TextPrompt,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57288710/

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