Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Nächste Überarbeitung | Vorhergehende Überarbeitung | ||
wiki:software:beuthbot:deconcentrator-js [22.07.2020 17:55] Lukas Danckwerth angelegt |
wiki:software:beuthbot:deconcentrator-js [22.07.2020 19:20] (aktuell) Lukas Danckwerth [Requirements Analysis] |
||
---|---|---|---|
Zeile 1: | Zeile 1: | ||
===== Deconcentrator-JS ===== | ===== Deconcentrator-JS ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | > BeuthBot deconcentrator written in JavaScript | ||
+ | |||
+ | ==== Feature ==== | ||
+ | |||
+ | The deconcentrator uses different NLU processors to compare their results and tries to choose an best fitting answer. The NLU processors like RASA must know their domain on their own. The deconcentrator simply compares the confidence score of the intents given from the processors and returns the intent with the highest score. | ||
+ | |||
+ | ==== Getting Started ==== | ||
+ | |||
+ | == Prerequisites == | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | == Clone Repository == | ||
+ | |||
+ | < | ||
+ | # clone project | ||
+ | $ git clone https:// | ||
+ | |||
+ | # change into directory | ||
+ | $ cd deconcentrator-js | ||
+ | |||
+ | # copy environment file and edit properly | ||
+ | $ cp .env.sample .env | ||
+ | </ | ||
+ | |||
+ | == Install == | ||
+ | |||
+ | There are two different ways running the deconcentrator. First is with `Node.js`' | ||
+ | |||
+ | == Install with npm == | ||
+ | Using npm you simply type in the following command. | ||
+ | < | ||
+ | # install dependencies | ||
+ | $ npm install | ||
+ | |||
+ | # start running the deconcentrator at localhost: | ||
+ | $ npm start run | ||
+ | </ | ||
+ | |||
+ | This will run the deconcentrator on it's default port `8338` and with the default RASA service url `http:// | ||
+ | |||
+ | == Install with docker-compose.yml == | ||
+ | |||
+ | Using docker-compose is prossibly the easiest way of running the deconcentrator. Simply type | ||
+ | < | ||
+ | $ docker-compose up | ||
+ | </ | ||
+ | to run a container with the deconcentrator. The docker-compose file also uses port `8338` as a default one. The endpoint of RASA is taken from the `.env`. Make sure to edit it to your needs. Have a look at the sample file `.env.sample` and the section [.env](# | ||
+ | |||
+ | ==== Overview ==== | ||
+ | |||
+ | === Structure === | ||
+ | |||
+ | ^ Location | ||
+ | | `.documentation/ | ||
+ | | `model/ | ||
+ | | `.env.sample` | ||
+ | | `deconcentrator.js` | ||
+ | | `.gitignore` | ||
+ | | `docker-compose.yml` | Defines the deconcentrator-js service. | ||
+ | | `Dockerfile` | ||
+ | | `package.json` | ||
+ | | `README.md` | ||
+ | |||
+ | |||
+ | |||
+ | === Functionality === | ||
+ | |||
+ | |||
+ | <uml> | ||
+ | @startuml | ||
+ | |||
+ | participant " | ||
+ | |||
+ | box " | ||
+ | participant " | ||
+ | participant " | ||
+ | participant " | ||
+ | participant " | ||
+ | participant " | ||
+ | end box | ||
+ | |||
+ | GW -> DC: request\nwith message | ||
+ | activate DC | ||
+ | DC -> DC: create and fill queue | ||
+ | DC -> PQ: run | ||
+ | activate PQ | ||
+ | PQ -> RP: (async) request | ||
+ | activate RP | ||
+ | PQ -> P1: (async) request | ||
+ | activate P1 | ||
+ | RP -> PQ: interpretation | ||
+ | deactivate RP | ||
+ | PQ -> P2: (async) request | ||
+ | activate P2 | ||
+ | P1 -> PQ: interpretation | ||
+ | deactivate P1 | ||
+ | P2 -> PQ: interpretation | ||
+ | deactivate P2 | ||
+ | PQ -> DC: all\ninterpretations | ||
+ | deactivate PQ | ||
+ | DC -> DC: filter out\nbest intent | ||
+ | DC -> GW: response\nwith intent | ||
+ | deactivate DC | ||
+ | |||
+ | @enduml | ||
+ | </ | ||
+ | |||
+ | |||
+ | == deconcentrator.js == | ||
+ | |||
+ | Uses an express application to listen for incoming messages. For an incoming message it then creates a processor-queue. The processor to can be specified with the `processors` property of an message. See [Request Schema - `Message`](Request-Schema ---Message) for more information. After all processor are done with interpretation the result with a confidence score which is too low are filtered out. | ||
+ | |||
+ | == processor-queue.js == | ||
+ | |||
+ | For every incoming message the deconcentrator creates a new `ProcessorQueue` (defined in `processor-queue.js`) and adds all available processors to it. When calling the `.interpretate(message)` function of the queue it starts requesting the processors for an interpretation. The number of asynchronous requests can be set with the `numOfSynchronProcessors` property of the queue. | ||
+ | |||
+ | == processor.js == | ||
+ | |||
+ | Defines the interface of a NLU processor. | ||
+ | |||
+ | == Implemented Processors == | ||
+ | * [[https:// | ||
+ | * ... | ||
+ | |||
+ | === Add new NLU processor === | ||
+ | |||
+ | == Setp 1: == | ||
+ | Create a new NLU processor service. | ||
+ | |||
+ | == Step 2: == | ||
+ | Create a new `PROCESSOR_NAME-processor.js` file in the `model` directory of the project. | ||
+ | |||
+ | == Step 3: == | ||
+ | |||
+ | Implement the `name` property and the `interpretate` function. Make sure the response looks like the one from rasa or the demo processor. | ||
+ | |||
+ | == Step 4: == | ||
+ | |||
+ | Add the name of the processor to the `default_processors` in the `deconcentrator.js` file. | ||
+ | |||
+ | ==== API ==== | ||
+ | |||
+ | The following lists the resources that can be requested with the deconcentrator API. | ||
+ | |||
+ | < | ||
+ | GET | ||
+ | </ | ||
+ | |||
+ | Returns a live sign of the deconcentrator. | ||
+ | |||
+ | < | ||
+ | POST http:// | ||
+ | </ | ||
+ | |||
+ | === Request Schema - `Message` === | ||
+ | |||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Whereas the specification of the `min_confidence_score` and the`processors` is optional. If not minimum confidence score is given a default one is used (by now this is `0.8`). For now there is only the usage of RASA implemented so there is no effect of specifying the `processors` property. | ||
+ | |||
+ | == Class Diagramm == | ||
+ | |||
+ | <uml> | ||
+ | @startuml | ||
+ | |||
+ | class Message { | ||
+ | text: String | ||
+ | min_confidence_score: | ||
+ | processors: Array< | ||
+ | } | ||
+ | |||
+ | @enduml | ||
+ | </ | ||
+ | |||
+ | === Response Schema - `Answer` === | ||
+ | The response for a successfully processed request to the deconcentrator contains the following information. | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | " | ||
+ | " | ||
+ | }, | ||
+ | " | ||
+ | } | ||
+ | ], | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | The response for a unsuccessfully processed request to the deconcentrator or when an error occures contains the following information. | ||
+ | < | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | == Class Diagramm == | ||
+ | |||
+ | <uml> | ||
+ | @startuml | ||
+ | |||
+ | class Answer { | ||
+ | text: String | ||
+ | intent: Intent | ||
+ | entities: Array< | ||
+ | error: String | ||
+ | } | ||
+ | |||
+ | class Intent { | ||
+ | name: String | ||
+ | confidence: Float | ||
+ | } | ||
+ | |||
+ | class Entity { | ||
+ | start: Int | ||
+ | end: Int | ||
+ | text: String | ||
+ | value: String | ||
+ | confidence: Float | ||
+ | additional_info: | ||
+ | entity: String | ||
+ | } | ||
+ | |||
+ | class AdditionalInfo { | ||
+ | value: String | ||
+ | grain: String | ||
+ | type: String | ||
+ | values: Dictionary< | ||
+ | } | ||
+ | |||
+ | Answer *--- Intent | ||
+ | Answer *--- Entity | ||
+ | Entity *--- AdditionalInfo | ||
+ | |||
+ | @enduml | ||
+ | </ | ||
+ | |||
+ | ==== Implemented and connected NLU processors ==== | ||
+ | |||
+ | ^ Provider ^BeuthBot Project ^ Processor File ^ | ||
+ | | [[https:// | ||
+ | |||
+ | === More NLU processors candidates === | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | |||
+ | ==== .env ==== | ||
+ | |||
+ | With the `.env` file the deconcentrator can be configured. The following demonstrates a sample file. The same content can be found in the`.env.sample` file of the project. | ||
+ | |||
+ | < | ||
+ | RASA_ENDPOINT=http:// | ||
+ | |||
+ | # Optional | ||
+ | MIN_CONFIDENCE_SCORE=0.85 | ||
+ | </ | ||
+ | |||
+ | |||
+ | |||
+ | ==== Requirements Analysis ==== | ||
+ | |||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [x] ''/ | ||
+ | * [ ] ''/ | ||
+ | |||
+ |