gpt4 book ai didi

flutter - 如何在 flutter 中创建带有响应选项的聊天机器人?

转载 作者:行者123 更新时间:2023-12-02 17:22:56 25 4
gpt4 key购买 nike

见下图: example

如何使用 DialogFlow 或 flutter 中的任何其他聊天机器人框架实现自动响应。

我只是想知道如何获得红色区域突出显示的所需结果。

最佳答案

编辑:使用dialogflow_v2看来你可以做这样的事情来获得自定义建议:

在 Dialogflow 控制台中,您可以向消息添加自定义负载,如下所示:

{"suggestions": ["Reply 1", "Reply 2"]}

创建一个 BotSuggestions 类:

class BotSuggestions {
List<String> suggestions = [];

BotSuggestions(List<dynamic> messages) {
messages.forEach((message) {
if (message['payload'] != null) {
List<dynamic> suggestionList = message['payload']['suggestions'];
suggestionList.forEach((suggestion) => suggestions.add(suggestion));
}
});
}
}

然后,你可以像这样使用它:

var botSuggestions = BotSuggestions(response.getListMessage());
print(botSuggestions.suggestions);
<小时/>

以下是如何使用它的完整示例:

var userMessage = "Hi!!!";
print('User: $userMessage');
response = await dialogflow.detectIntent(userMessage);
var botSuggestions = BotSuggestions(response.getListMessage());
print('Bot: ${response.getMessage()}');
print('Suggestions: ${botSuggestions.suggestions}');

userMessage = botSuggestions.suggestions.first;
print('User: $userMessage');
response = await dialogflow.detectIntent(userMessage);
botSuggestions = BotSuggestions(response.getListMessage());
print('Bot: ${response.getMessage()}');
print('Suggestions: ${botSuggestions.suggestions}');

这将是输出:

I/flutter ( 5917): User: Hi!!!

I/flutter ( 5917): Bot: Hi! How are you doing?

I/flutter ( 5917): Suggestions: [Reply 1, Reply 2]

I/flutter ( 5917): User: Reply 1

I/flutter ( 5917): Bot: Sorry, what was that?

I/flutter ( 5917): Suggestions: []

<小时/>

我在包存储库中询问了这一点,看看是否有其他方法可以做到这一点,在这里您可以按照线程:How to get suggestions in v2? .

关于flutter - 如何在 flutter 中创建带有响应选项的聊天机器人?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58341273/

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