简体   繁体   English

azure 聊天机器人有什么方法可以查询数据库并从数据库返回答案? 可能正在使用 qna maker 或 luis?

[英]is there any way that a azure chatbot can query the databse and return answer from the database? may be using qna maker or luis?

I am trying to build a chat bot which queries a database and returns answer from the database depending on the question asked.我正在尝试构建一个聊天机器人,它查询数据库并根据所提出的问题从数据库中返回答案。 is there any way to connect the azure chat bot to the database say azure SQL database?有什么方法可以将 azure 聊天机器人连接到数据库,比如 azure SQL 数据库?

Per your additional information, I have changed my answer.根据您的附加信息,我已更改答案。 The original suggestion using QnA Maker is below.使用 QnA Maker 的原始建议如下。 If you need to retrieve data from a database, such as student scores the best way to do this is with a slot-filling dialog.如果您需要从数据库中检索数据,例如学生成绩,最好的方法是使用插槽填充对话框。 Personally, I use and prefer waterfall dialogs initiated by intent recognition with LUIS, but there are other ways to do it.就个人而言,我使用并更喜欢通过 LUIS 的意图识别启动的瀑布对话,但还有其他方法可以做到这一点。

  • First, use LUIS to identify the user intent and start the appropriate dialog.首先,使用 LUIS 识别用户意图并启动相应的对话。 I like the DispatchBot sample for showing how to do basic intent recognition (but that sample has the dialogs in the same.js file, which I do not like. I prefer keep my dialogs in separate files).我喜欢DispatchBot 示例,它展示了如何进行基本的意图识别(但该示例在 same.js 文件中包含对话框,我不喜欢。我更喜欢将对话框保存在单独的文件中)。
  • If possible, you'll want to try to extract the relevant entities so that the user doesn't have to retype them.如果可能,您将尝试提取相关实体,以便用户不必重新键入它们。 There are numerous tutorials on how to do this but here is a good one .有很多关于如何做到这一点的教程,但这里有一个很好的
  • Use the dialog to collect all the required information to make your database call.使用该对话框收集所有必需的信息以进行数据库调用。 The multi-turn prompt sample is a good example of how to do this. 多轮提示示例是如何执行此操作的一个很好的示例。 You also need to account in your code for the entity extraction so you don't reprompt the user.您还需要在代码中考虑实体提取,这样您就不会再次提示用户。 I do this via an if statment: if the entity exists, return that to the next step;我通过 if 语句执行此操作:如果实体存在,则将其返回到下一步; else prompt the user for the entity.否则提示用户输入实体。 Here is an example.这是一个例子。
if (step._info.options.entities.orderNumber) {
    return await step.next(step._info.options.entities.orderNumber[0].toUpperCase());
} else {
    return await step.prompt(ORDER_PROMPT, {
        prompt: 'Please provide your order number.',
        retryPrompt: 'Please enter a valid order number.',
    });
}
  • You'll need to temporarily store the value somewhere.您需要将值临时存储在某处。 The easiest thing to do is store it in the step context (I call mine step ) of your waterfall.最简单的方法是将其存储在瀑布的 step 上下文中(我称之为我的step )。 For example, the step following the one above you would store the order number in my example via step.values.orderNumber = step.result;例如,在上述步骤之后的步骤中,您将通过step.values.orderNumber = step.result;在我的示例中存储订单号。 ( or step.result.value if returning a choice selection). (或step.result.value如果返回选项选择)。
  • Once you have all the values you can query your DB.一旦你有了所有的值,你就可以查询你的数据库。 The method for doing that will depend on which DB you are using.执行此操作的方法取决于您使用的数据库。 But if we assume you are doing that via some sort of helper, you would just call something like const score = await queryMyDb(student, subject) .但是,如果我们假设您是通过某种帮手来做到这一点的,那么您只需调用类似const score = await queryMyDb(student, subject)类的东西。 Then you can reply with the score to the user.然后您可以将分数回复给用户。

This should give you enough to make an attempt at retrieving the information.这应该足以让您尝试检索信息。 If you try and still have trouble, you can open a separate request showing your code and the specific problems you are encountering.如果您尝试但仍然遇到问题,您可以打开一个单独的请求,显示您的代码和您遇到的具体问题。


Previous answer before additional context received:收到附加上下文之前的先前答案:

Assuming you are just wanting to retrieve answers to questions in a single question-answer pair, it sounds like you just need to deploy QnA Maker and create a bot to utilize it.假设您只想在单个问答对中检索问题的答案,听起来您只需要部署 QnA Maker 并创建一个机器人来使用它。 Microsoft provides good instructions on how to Create, train, and publish your QnA Maker knowledge base . Microsoft 提供了有关如何创建、培训和发布 QnA Maker 知识库的良好说明。 Give it a try and if you have any issues, come back and ask via a separate question along with the code you've tried.试一试,如果您有任何问题,请返回并通过单独的问题以及您尝试过的代码提出问题。

QnA Maker can support prompts for multi-turn conversations as well. QnA Maker 也可以支持多轮对话的提示 You're still dealing with single question-answer pairs, but you can provide a easy selection for users to bring up related answers with a click of a button.您仍在处理单个问答对,但您可以为用户提供一个简单的选择,以便通过单击按钮来显示相关答案。

If you are using azure storage like table storage or blob.如果您使用 azure 存储,例如表存储或 blob。 I suggest using Azure search service.我建议使用 Azure 搜索服务。 This will help you solve your problem, but it will certainly add up the cost.这将帮助您解决问题,但肯定会增加成本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App Maker 可以连接到 Azure 中的 MS SqlServer 数据库吗? - Can Google App Maker connect to MS SqlServer Database in Azure? 有什么方法可以在不使用 Azure SQL 中的外部表的情况下从两个不同的数据库中查询两个表? - Is there any way to querying two tables from two different database without using external table in Azure SQL? 有没有办法对Azure SQL数据库更改做出反应? - Is there any way to react on Azure SQL Database changes? 有没有办法使用 Azure DevOps Pipelines 从 SQL 项目生成用于部署到 Azure SQL 数据库的 SQL 脚本? - Is there a way to generate a SQL script for deploying to Azure SQL database from a SQL Project using Azure DevOps Pipelines? 使用托管身份从本地Azure功能查询Azure SQL数据库 - Query Azure SQL Database from local Azure Function using Managed Identities 使用视图索引的Azure数据库查询优化器 - Azure Database Query Optimizer using View Indices 如何从js中的Azure函数查询数据库 - How to query a database from an Azure function in js Given a query ID for a SQL query on a SQL database in Azure, is there a way to go back and trace who initiated the query? - Given a query ID for a SQL query on a SQL database in Azure, is there a way to go back and trace who initiated the query? Azure Sql数据库查询 - Azure Sql Database query Azure 数据库 -> Excel 查询 - Azure Database -> Excel Query
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM