Warm tip: This article is reproduced from serverfault.com, please click

c#-如何在Botframework的语言生成功能中从LG文件访问状态

(c# - How to access State from LG file in language generation feature of botframework)

发布于 2020-11-27 07:57:38

按照从LG文件这些文章,你应该能够直接访问机器人状态,没有通过值范围: https://docs.microsoft.com/en-us/composer/concept-language-generation https://开头的文档。 microsoft.com/zh-CN/azure/bot-service/bot-builder-concept-language-generation?view=azure-bot-service-4.0&tabs=csharp

即其提及:

语言生成是通过以下方式实现的:基于Markdown的.lg文件,其中包含模板及其组成。完全访问当前漫游器的内存,因此你可以将语言数据绑定到内存状态。

那里的示例之一看起来好像它们能够从UserState访问变量“ name”:

# greetingTemplate
- Hello ${user.name}, how are you?
- Good morning ${user.name}.It's nice to see you again.
- Good day ${user.name}. What can I do for you today?

我已经以几种方式对其进行了测试,但是我根本无法从LG文件访问UserState内存。那可能吗?

Questioner
Kuba K
Viewed
0
Dana V 2020-12-01 08:26:41

ķ

这并不是说你可以直接访问bot状态,而是自适应/合成器bot中的内存(及其作用域)以状态存储,并且可以通过作用域和LG进行存储和访问。你提供的文章摘录中的关键字是“内存”(在这种情况下,指的是自适应内存作用域及其值)。

例如,我可以提示用户输入他们的姓名并将其存储在中user.name但这并不相同turn.activity.from.name(这不是来自状态的东西,而是经常保存到状态中的东西)。user.name默认情况下不会填充。你当然可以从中获取turn.activity.from.name并存储该值user.name(可能取决于通道,或者具有其他逻辑,等等)。

你可以使用以下方法对此进行更多测试:

对话:

{
  "$kind": "Microsoft.AdaptiveDialog",
  "$designer": {
    "id": "7zj5aK",
    "name": "GatherUserInfo",
    "description": ""
  },
  "autoEndDialog": true,
  "defaultResultProperty": "dialog.result",
  "triggers": [
    {
      "$kind": "Microsoft.OnBeginDialog",
      "$designer": {
        "name": "BeginDialog",
        "description": "",
        "id": "A25t0H"
      },
      "actions": [
        {
          "$kind": "Microsoft.TextInput",
          "$designer": {
            "id": "SOE0Ku"
          },
          "disabled": false,
          "maxTurnCount": 3,
          "alwaysPrompt": false,
          "allowInterruptions": false,
          "prompt": "${TextInput_Prompt_SOE0Ku()}",
          "unrecognizedPrompt": "",
          "invalidPrompt": "",
          "defaultValueResponse": "",
          "property": "user.name"
        },
        {
          "$kind": "Microsoft.TextInput",
          "$designer": {
            "id": "3sNA0B"
          },
          "disabled": false,
          "maxTurnCount": 3,
          "alwaysPrompt": false,
          "allowInterruptions": false,
          "prompt": "${TextInput_Prompt_3sNA0B()}",
          "unrecognizedPrompt": "",
          "invalidPrompt": "",
          "defaultValueResponse": "",
          "property": "user.gender"
        },
        {
          "$kind": "Microsoft.NumberInput",
          "$designer": {
            "id": "SsEiOF"
          },
          "defaultLocale": "en-us",
          "disabled": false,
          "maxTurnCount": 3,
          "alwaysPrompt": false,
          "allowInterruptions": false,
          "prompt": "${NumberInput_Prompt_SsEiOF()}",
          "unrecognizedPrompt": "",
          "invalidPrompt": "",
          "defaultValueResponse": "",
          "property": "user.age"
        },
        {
          "$kind": "Microsoft.SendActivity",
          "$designer": {
            "id": "CD7TVN"
          },
          "activity": "${SendActivity_CD7TVN()}"
        }
      ]
    }
  ],
  "generator": "GatherUserInfo.lg",
  "recognizer": "GatherUserInfo.lu.qna",
  "id": "GatherUserInfo"
}

LG:

# TextInput_Prompt_SOE0Ku()
 - What is your name?
# TextInput_Prompt_3sNA0B()
 - What is your gender?
# NumberInput_Prompt_SsEiOF()
 - What is your age?
# SendActivity_CD7TVN()
 - Your name is ${user.name}, you are ${user.gender} and your age is ${user.age}. You are also ${turn.activity.from.name}

使用模拟器,你可能会在波斯菊中看到以下内容:

{
    "id": "emulator*2fusers*2fa1464f41-f237-42dd-ad01-ca8fb150b97a",
    "realId": "emulator/users/a1464f41-f237-42dd-ad01-ca8fb150b97a",
    "document": {
        "$type": "System.Collections.Generic.Dictionary`2[[System.String, System.Private.CoreLib],[System.Object, System.Private.CoreLib]], System.Private.CoreLib",
        "name": "DanaVCosmos",
        "gender": "MaleCosmos",
        "age": 45
    },