Coder Social home page Coder Social logo

nlg-server's Introduction

NLG Server

NLG Server is an example for a simple, Rasa-compatible NLG Server that exposes static responses loaded from a JSON file through a REST API.

Because it does not perform Natural Language Generation itself, its purpose is currently limited to separating the responses from your Rasa model to allow changes of the responses without having to retrain and upload a new model.

The exposed API follows the format defined by Rasa. See Rasa NLG Servers

Usage

The NLG server loads the responses from a given JSON file or from a directory consisting of multiple response JSON files. Using further nested directories is also supported.

Features

  • Load static response JSON files (single files or from a directory)
  • Use templates in your responses in the form {slotName} or $slotName (see examples section)
  • Randomly chose a response from a set of given response variations
  • Can be used with Rasa (Last tested with Rasa 3.2.1)

Environment Variable

reponses=<path to our json response file or to a directory of multiple response files>

Response File

The responses have to be defined as JSON in the following format

{
  "response_name": "This is an example response.",
  "example_response": "Test 1 2 3.",
  "response_with_variations": [
    "first_variation", 
    "second_variation"
  ]
}

Endpoint

address:port/nlg

The default port is 8080

Request Format

{
  "response":"example2",
  "arguments":{
    
  },
  "tracker":{
  }
} 

Response Format

{
    "text": "Some text",
}

Examples

Slot Template Filling Example

Response JSON file

{
  "example": "This is an example response.",
  "test": "Test 1 2 3.",
  "utter_template": "Your number is {number}."
}

Request

{
    "response": "utter_template",
    "tracker": {
        "sender_id": "user_42",
        "slots": {
            "number": "80"
        }
    }
}

Response

{
    "text": "Your number is 80."
}

Docker

Build an Image

To build the NLG server as a docker container you can use the provided dockerfile as an example

Replace the responses folder with your folder name

docker build -t nlg-server .

Run the container

Your build container can be run (exposed over port 8082) with the following command or your add it to a docker-compose file.

docker run -p 8082:8080 nlg-server

Resources

The POJOs for the Rasa Request and Responses have been generated with https://www.jsonschema2pojo.org/

nlg-server's People

Contributors

kai-karren avatar

Watchers

 avatar

nlg-server's Issues

Increase the unit test coverage

I have been lazy with unit tests for this project. There should be unit tests for all non-autogenerated classes that contain logic.

Implement slot template filling

The current implementation of NLG does not yet support slot template filling in the responses. I kind of forgot that.
To enable this, the NLG Server has to receive slots from the Dialogue Engine as part of the request.

Example

"I understood that you said $number"  with slot number = 42 => "I understood that you said 42"
"I understood that you are {name}" with slot name = "Kai Karren" => "I understood that you are Kai Karren"

Requirements

  • โœ”๏ธ Slot template filling of the responses has been implemented and tested

Expected Behavior

When no slots are given in the request but the response contains a template, the template should be filled with an empty String.

Slot Template Configuration for number slots

To have more control over how numbers are formatted when slot templates are filled, a configuration should be possible.
E.g
22 22 45 56 instead of 22224556
2 2 2 2 instead of 2222 and so on.

Evaluate support for other file formats aside from JSON

Currently, the responses can only be provided as JSON key-value pairs. To extend this also to other formats like YAML or a custom format could be a good addition. This should be evaluated and how this could look like.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.