npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@chrimc62/botbuilder-lg

v4.1.20

Published

Bot Builder Language Generation is a library to help build sophisticated bot responses with multiple phrases and context-based expressions.

Downloads

26

Readme

Language Generation [PREVIEW]

Learning from our customers experiences and bringing together capabilities first implemented by Cortana and Cognition teams, we are introducing Language Generation; which allows the developer to extract the embedded strings from their code and resource files and manage them through a Language Generation runtime and file format. Language Generation enable customers to define multiple variations on a phrase, execute simple expressions based on context, refer to conversational memory, and over time will enable us to bring additional capabilities all leading to a more natural conversational experience.

At the core of language generation lies template expansion and entity substitution. You can provide one-of variation for expansion as well as conditionally expand a template. The output from language generation can be a simple text string or multi-line response or a complex object payload that a layer above language generation will use to construct a full blown activity.

Language generation is achieved through:

  • markdown based .lg file that describes the templates and their composition. See here for the .lg file format.
  • full access to current bots memory so you can data bind language to the state of memory.
  • parser and runtime libraries that help achieve runtime resolution. See here for API-reference.
# 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?

You can use language generation to:

  • achieve a coherent personality, tone of voice for your bot
  • separate business logic from presentation
  • include variations and sophisticated composition based resolution for any of your bot's replies
  • structured LG

structured LG

The type of LG output could be string or object, string is by default. But LG could generate a json object by Structured LG feature.

Example here:

    # HeroCardTemplate(buttonsCollection)
    [Herocard
        title=${TitleText())}
        subtitle=${SubText())}
        text=${DescriptionText())}
        images=${CardImages())}
        buttons=${buttonsCollection}
    ]

    # TitleText
    - Here are some ${TitleSuffix()}

    # TitleSuffix
    - cool photos
    - pictures
    - nice snaps

    # SubText
    - What is your favorite?
    - Don't they all look great?
    - sorry, some of them are repeats

    # DescriptionText
    - This is description for the hero card

    # CardImages
    - https://picsum.photos/200/200?image=100
    - https://picsum.photos/300/200?image=200
    - https://picsum.photos/200/200?image=400

the result could be:

{
  "lgType": "Herocard",
  "title": "Here are some pictures",
  "text": "This is description for the hero card",
  "images": "https://picsum.photos/200/200?image=100",
  "buttons": [
    "click to see",
    "back"
  ]
}

the structured name would be placed into property 'lgType'. See more tests here : structured LG test

By this, You can use the ActivityFactory.createActivity(lgResult) method to transform the lg output into a Bot Framework activity to post back to the user.

see more samples here: Structured LG to Activity

Language Generation in action

When building a bot, you can use language generation in several different ways. To start with, examine your current bot's code (or the new bot you plan to write) and create .lg file to cover all possible scenarios where you would like to use the language generation sub-system with your bot's replies to user.

Then make sure you include the platform specific language generation library.

For C#, add Microsoft.Bot.Builder.LanguageGeneration. For NodeJS, add botbuilder-lg

Load the template manager with your .lg file(s)

    // multi lg files
    let lgEngine = new TemplateEngine.addFiles(filePaths, importResolver?);

    // single lg file
    let lgEngine = new TemplateEngine.addFile(filePath, importResolver?);

When you need template expansion, call the templateEngine and pass in the relevant template name

    await turnContext.sendActivity(lgEngine.evaluateTemplate("<TemplateName>", entitiesCollection));

If your template needs specific entity values to be passed for resolution/ expansion, you can pass them in on the call to evaluateTemplate

    await turnContext.sendActivity(lgEngine.evaluateTemplate("WordGameReply", { GameName = "MarcoPolo" } ));