├── .gitignore ├── LICENSE ├── MockPortal ├── .gitignore └── app.py ├── PortalAPIforPythonFlask ├── README.md ├── RemoteAgent.py └── server.py ├── PortalNodeAPIs ├── README.md ├── api │ ├── bot │ │ └── toyBot.js │ └── routes │ │ └── nodeapiRoutes.js ├── package.json └── server.js ├── README.md ├── _config.yml ├── _includes └── image.html └── images ├── flow.png ├── fsm.png └── overview.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | local_settings.py 55 | 56 | # Flask stuff: 57 | instance/ 58 | .webassets-cache 59 | 60 | # Scrapy stuff: 61 | .scrapy 62 | 63 | # Sphinx documentation 64 | docs/_build/ 65 | 66 | # PyBuilder 67 | target/ 68 | 69 | # IPython Notebook 70 | .ipynb_checkpoints 71 | 72 | # pyenv 73 | .python-version 74 | 75 | # celery beat schedule file 76 | celerybeat-schedule 77 | 78 | # dotenv 79 | .env 80 | 81 | # virtualenv 82 | venv/ 83 | ENV/ 84 | 85 | # Spyder project settings 86 | .spyderproject 87 | 88 | # Rope project settings 89 | .ropeproject 90 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /MockPortal/.gitignore: -------------------------------------------------------------------------------- 1 | # Created by .ignore support plugin (hsz.mobi) 2 | ### Python template 3 | # Byte-compiled / optimized / DLL files 4 | __pycache__/ 5 | *.py[cod] 6 | *$py.class 7 | 8 | # C extensions 9 | *.so 10 | 11 | # Distribution / packaging 12 | .Python 13 | env/ 14 | build/ 15 | develop-eggs/ 16 | dist/ 17 | downloads/ 18 | eggs/ 19 | .eggs/ 20 | lib/ 21 | lib64/ 22 | parts/ 23 | sdist/ 24 | var/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *,cover 48 | .hypothesis/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | local_settings.py 57 | 58 | # Flask stuff: 59 | instance/ 60 | .webassets-cache 61 | 62 | # Scrapy stuff: 63 | .scrapy 64 | 65 | # Sphinx documentation 66 | docs/_build/ 67 | 68 | # PyBuilder 69 | target/ 70 | 71 | # IPython Notebook 72 | .ipynb_checkpoints 73 | 74 | # pyenv 75 | .python-version 76 | 77 | # celery beat schedule file 78 | celerybeat-schedule 79 | 80 | # dotenv 81 | .env 82 | 83 | # virtualenv 84 | venv/ 85 | ENV/ 86 | 87 | # Spyder project settings 88 | .spyderproject 89 | 90 | # Rope project settings 91 | .ropeproject 92 | .idea 93 | 94 | -------------------------------------------------------------------------------- /MockPortal/app.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | # Author: Tiancheng Zhao 3 | # Date: 1/22/18 4 | 5 | import requests 6 | import json 7 | import uuid 8 | import datetime 9 | 10 | AGENT_URL = "http://localhost:3000" 11 | KEY_WORD = "hello world" 12 | 13 | def run_server(): 14 | print("Welcome to DialPortal Mock Portal. \nThis program simulates the process" 15 | "a user talking to the Portal and the Portal redirect the user to your agent.") 16 | print("Simulation starting now. Type EXIT to quit.\n") 17 | print("Hi, I am the Portal from. What can I do for you?") 18 | state = "in_portal" 19 | sess_id = None 20 | 21 | while True: 22 | usr_input = raw_input("You can say '{}' to activate your system\n".format(KEY_WORD)) 23 | 24 | if usr_input == 'EXIT': 25 | break 26 | 27 | try: 28 | if state == 'in_portal': 29 | if usr_input.strip() == KEY_WORD: 30 | state = "in_agent" 31 | sess_id = str(uuid.uuid4()) 32 | # start a new session with your agent 33 | body = {'sessionID': sess_id, 34 | 'timeStamp':datetime.datetime.now().__str__()} 35 | resp = requests.post(AGENT_URL + '/init', data=json.dumps(body)) 36 | resp = json.loads(resp.text) 37 | print("Agent: {}".format(resp['sys'])) 38 | 39 | # if the remote agent just finish 1 turn, stop 40 | if resp['terminal']: 41 | state = 'in_portal' 42 | else: 43 | body = {'sessionID': sess_id, 44 | 'timeStamp': datetime.datetime.now().__str__(), 45 | 'text': usr_input, 46 | 'asrConf': 0.9} 47 | 48 | resp = requests.post(AGENT_URL + '/next', data=json.dumps(body)) 49 | resp = json.loads(resp.text) 50 | print("Agent: {}".format(resp['sys'])) 51 | 52 | # if the remote agent just finish 1 turn, stop 53 | if resp['terminal']: 54 | state = 'in_portal' 55 | sess_id = None 56 | except Exception as e: 57 | print(e) 58 | print("!!You agent is not working yet. Please debug and try agin.") 59 | 60 | 61 | if __name__ == "__main__": 62 | run_server() -------------------------------------------------------------------------------- /PortalAPIforPythonFlask/README.md: -------------------------------------------------------------------------------- 1 | # PortalAPI for Python Flask 2 | A zoo of API wrapper for connecting to DialPort (Python Flask version) 3 | 4 | # Code 5 | 6 | ```python 7 | from flask import Flask, request, jsonify 8 | app = Flask(__name__) 9 | from datetime import datetime 10 | from RemoteAgent import * # Import your bot 11 | 12 | usrStacks = {} 13 | date_format = "%Y-%m-%d'T'%H%-%M-%S.SSS" 14 | @app.route('/', methods=['GET', 'POST']) 15 | def add_message(uuid): 16 | if uuid == "init": 17 | content = request.json 18 | #A message from DialPort: sessionID, timeStamp 19 | sessionID = content["sessionID"] 20 | timeStamp = content["timeStamp"] 21 | 22 | # Assign an instance to Dictionary 23 | usrStacks[sessionID] = API() 24 | 25 | #A message to DialPort: sessionID, version, terminal, sys, and imageurl 26 | Output = {} 27 | Output["sessionID"] = sessionID # DialPort will send sessionID. 28 | Output["version"] = "0.1" # Please provide your system version. 29 | Output["terminal"] = False 30 | Output["timeStamp"] = datetime.now().isoformat() 31 | Output["sys"] = "Welcome to Mybot... " # Introduction Message 32 | Output["imageurl"] = "https://skylar.speech.cs.cmu.edu/image/movie.jpg" # Put an image url to show on the screen." 33 | return jsonify(Output) 34 | 35 | if uuid == "next": 36 | content = request.json 37 | #A message from DialPort: sessionID, text (an user input), asrConf, timeStamp 38 | sessionID = content["sessionID"] 39 | text = content["text"] 40 | asrConf = content["asrConf"] 41 | timeStamp = content["timeStamp"] 42 | 43 | # A reponse from your bot 44 | response = usrStacks[sessionID].GetResponse(text) 45 | 46 | # A message to DialPort: sessionID, version, sys (system utterance), terminal (true if the end of the dialog), imageurl 47 | Output = {} 48 | Output["sessionID"] = sessionID 49 | Output["timeStamp"] = datetime.now().isoformat() 50 | Output["version"] = "0.1" 51 | if response["slu"]["act"] == "exit": 52 | Output["sys"] = "Goodbye. See you later" 53 | Output["terminal"] = True # At the end of the dialog, please send us True 54 | del usrStacks[sessionID] 55 | else: 56 | Output["imageurl"] = response["imageurl"] 57 | Output["terminal"] = False 58 | Output["sys"] = response["sys"] 59 | return jsonify(Output) 60 | 61 | if uuid == "end": #Terminate a session with your system 62 | content = request.json 63 | #A message from DialPort: sessionID, timeStamp 64 | sessionID = content["sessionID"] 65 | timeStamp = content["timeStamp"] 66 | 67 | # A message to DialPort: sessionID, version, sys (system utterance), terminal (true if the end of the dialog) 68 | Output = {} 69 | Output["sessionID"] = sessionID 70 | Output["timeStamp"] = datetime.now().isoformat() 71 | Output["version"] = "0.1" 72 | Output["sys"] = "Goodbye. See you later" 73 | Output["terminal"] = True # At the end of the dialog, please send us True 74 | del usrStacks[sessionID] 75 | return jsonify(Output) 76 | 77 | if __name__ == '__main__': 78 | app.run(host= '0.0.0.0',port= 3000, debug=True) 79 | ``` 80 | 81 | # Dependency 82 | - python2.7 83 | - [flask](http://flask.pocoo.org/) 84 | 85 | 86 | # Run 87 | ``` 88 | python server.py 89 | ``` 90 | 91 | -------------------------------------------------------------------------------- /PortalAPIforPythonFlask/RemoteAgent.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Author: Kyusong Lee 3 | email: kyusongl@cs.cmu.edu 4 | Date created: 09/21/2017 5 | Date last modified: 09/21/201 6 | Description: An Example code for DialPort Connection 7 | Python Version: 2.7 8 | ''' 9 | 10 | class API(object): 11 | def __init__(self): 12 | self.history = [] 13 | 14 | def GetResponse(self,text): 15 | slu = {"act":"dialog_act","slot":"named_entity"} 16 | sysUtter = "sysUtter" 17 | imageurl = "imageurl" 18 | return {"slu":slu,"sys":sysUtter,"imageurl":imageurl} 19 | -------------------------------------------------------------------------------- /PortalAPIforPythonFlask/server.py: -------------------------------------------------------------------------------- 1 | ''' 2 | Author: Kyusong Lee 3 | email: kyusongl@cs.cmu.edu 4 | Date created: 09/21/2017 5 | Date last modified: 09/21/201 6 | Description: An Example code for DialPort Connection 7 | Python Version: 2.7 8 | ''' 9 | 10 | from flask import Flask, request, jsonify 11 | app = Flask(__name__) 12 | from datetime import datetime 13 | from RemoteAgent import * # Import your bot 14 | 15 | usrStacks = {} 16 | date_format = "%Y-%m-%d'T'%H%-%M-%S.SSS" 17 | @app.route('/', methods=['GET', 'POST']) 18 | def add_message(uuid): 19 | if uuid == "init": #Create a new session 20 | content = request.json 21 | #A message from DialPort: sessionID, timeStamp 22 | sessionID = content["sessionID"] 23 | timeStamp = content["timeStamp"] 24 | 25 | # Assign an instance to Dictionary 26 | usrStacks[sessionID] = API() 27 | 28 | #A message to DialPort: sessionID, version, terminal, sys, and imageurl 29 | Output = {} 30 | Output["sessionID"] = sessionID # DialPort will send sessionID. 31 | Output["version"] = "0.1" # Please provide your system version. 32 | Output["terminal"] = False 33 | Output["timeStamp"] = datetime.now().isoformat() 34 | Output["sys"] = "Welcome to Mybot... " # Introduction Message 35 | Output["imageurl"] = "https://skylar.speech.cs.cmu.edu/image/movie.jpg" # Put an image url to show on the screen." 36 | return jsonify(Output) 37 | 38 | if uuid == "next": #Get your system's next response 39 | content = request.json 40 | #A message from DialPort: sessionID, text (an user input), asrConf, timeStamp 41 | sessionID = content["sessionID"] 42 | text = content["text"] 43 | asrConf = content["asrConf"] 44 | timeStamp = content["timeStamp"] 45 | 46 | # A reponse from your bot 47 | response = usrStacks[sessionID].GetResponse(text) 48 | 49 | # A message to DialPort: sessionID, version, sys (system utterance), terminal (true if the end of the dialog), imageurl 50 | Output = {} 51 | Output["sessionID"] = sessionID 52 | Output["timeStamp"] = datetime.now().isoformat() 53 | Output["version"] = "0.1" 54 | if response["slu"]["act"] == "exit": 55 | Output["sys"] = "Goodbye. See you later" 56 | Output["terminal"] = True # At the end of the dialog, please send us True 57 | del usrStacks[sessionID] 58 | else: 59 | Output["imageurl"] = response["imageurl"] 60 | Output["terminal"] = False 61 | Output["sys"] = response["sys"] 62 | return jsonify(Output) 63 | 64 | if uuid == "end": #Terminate a session with your system 65 | content = request.json 66 | #A message from DialPort: sessionID, timeStamp 67 | sessionID = content["sessionID"] 68 | timeStamp = content["timeStamp"] 69 | 70 | # A message to DialPort: sessionID, version, sys (system utterance), terminal (true if the end of the dialog) 71 | Output = {} 72 | Output["sessionID"] = sessionID 73 | Output["timeStamp"] = datetime.now().isoformat() 74 | Output["version"] = "0.1" 75 | Output["sys"] = "Goodbye. See you later" 76 | Output["terminal"] = True # At the end of the dialog, please send us True 77 | del usrStacks[sessionID] 78 | return jsonify(Output) 79 | 80 | if __name__ == '__main__': 81 | app.run(host= '0.0.0.0',port= 3000, debug=True) 82 | -------------------------------------------------------------------------------- /PortalNodeAPIs/README.md: -------------------------------------------------------------------------------- 1 | # PortalAPI for NodeJS 2 | A zoo of API wrapper for connecting to DialPort (Node version) 3 | 4 | # What you need to do: 5 | 6 | All you need to do is go to the /api/bot folder and put your bot in it just as the toy example, then change the namings accordingly. Everything else should've been taken care of by us. :) 7 | 8 | # Run 9 | ``` 10 | npm install 11 | npm start 12 | ``` 13 | 14 | Then Portal can POST on 3000 for your bot. 15 | 16 | -------------------------------------------------------------------------------- /PortalNodeAPIs/api/bot/toyBot.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var example_return = { 4 | sessionID: "USR_001", 5 | sys: "This is a toy example for you.", 6 | terminal: false, 7 | timeStamp: "yyyy-MM-dd'T'HH-mm-ss.SSS" 8 | }; 9 | 10 | exports.init = function(req, res) { 11 | // what you get from portal 12 | console.log("Portal just initialized a new session."); 13 | console.log("sessionID is: " + req.body.sessionID); 14 | console.log("timeStamp is: " + req.body.timeStamp); 15 | 16 | // what you send back 17 | example_return.sessionID = req.body.sessionID; 18 | example_return.sys = "Hello! (Portal just initialized a new session.)"; 19 | 20 | res.json(example_return); 21 | }; 22 | 23 | 24 | exports.next = function(req, res) { 25 | // what you get from portal 26 | console.log("Portal just send a message from user: " + req.body.text); 27 | console.log("sessionID is: " + req.body.sessionID); 28 | console.log("timeStamp is: " + req.body.timeStamp); 29 | 30 | // what you send back 31 | example_return.sessionID = req.body.sessionID; 32 | example_return.sys = "Sorry, I am just a toy!"; 33 | 34 | res.json(example_return); 35 | }; 36 | 37 | 38 | exports.end = function(req, res) { 39 | // what you get from portal 40 | console.log("Portal will end the current session: " + req.body.sessionID); 41 | console.log("sessionID is: " + req.body.sessionID); 42 | console.log("timeStamp is: " + req.body.timeStamp); 43 | 44 | // what you send back 45 | example_return.sessionID = req.body.sessionID; 46 | example_return.sys = "Goodbye!"; 47 | example_return.terminal = true; 48 | 49 | res.json(example_return); 50 | }; -------------------------------------------------------------------------------- /PortalNodeAPIs/api/routes/nodeapiRoutes.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | module.exports = function(app) { 3 | var yourchatbot = require('../bot/toyBot'); 4 | 5 | // nodeapi Routes 6 | app.route('/init') 7 | .post(yourchatbot.init); 8 | 9 | app.route('/next') 10 | .post(yourchatbot.next); 11 | 12 | app.route('/end') 13 | .post(yourchatbot.end); 14 | }; -------------------------------------------------------------------------------- /PortalNodeAPIs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "nodeapis", 3 | "version": "1.0.0", 4 | "description": "An example toy server for Portal connection", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "Yulun Du", 10 | "license": "ISC", 11 | "devDependencies": { 12 | "nodemon": "^1.12.1" 13 | }, 14 | "dependencies": { 15 | "body-parser": "^1.18.1", 16 | "express": "^4.15.4" 17 | }, 18 | "start": "nodemon server.js" 19 | } 20 | -------------------------------------------------------------------------------- /PortalNodeAPIs/server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'), 2 | app = express(), 3 | port = process.env.PORT || 3000; 4 | bodyParser = require('body-parser'); 5 | 6 | //app.use(bodyParser.urlencoded({ extended: true })); 7 | app.use(bodyParser.json()); 8 | 9 | var routes = require('./api/routes/nodeapiRoutes'); //importing route 10 | routes(app); //register the route 11 | 12 | app.listen(port); 13 | 14 | console.log('Portal Node example RESTful API server started on: ' + port); -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DialPort Portal Tutorial 2 | 3 | * [Introduction](#introduction) 4 | * [How the portal Works](#how-the-portal-works) 5 | * [Development Cycle](#development-cycle) 6 | * [API Documentations:](#api-documentations) 7 | * [1\. Create a new session](#1-create-a-new-session) 8 | * [2\. Get your system's next response](#2-get-your-systems-next-response) 9 | * [3\. Terminate a session with your system](#3-terminate-a-session-with-your-system) 10 | * [Extra Parameters](#extra-parameters) 11 | * [Timezone](#timezone) 12 | * [Example Server Templates](#example-server-templates) 13 | * [Interested in working with us?](#interested-in-working-with-us) 14 | 15 | 16 | ## Introduction 17 | The advent of Siri and other agents has generated interest in spoken dialog research, sparking the imagination of many and leading them to believe in the usefulness of speaking to intelligent agents. The research community can profit from this interest to gather much-needed real user data by joining a general Portal that serves the general public. The Portal is the front end of several different academic dialog systems. by having many systems it is able to serve a diverse set of requests. The data gathered from the Portal can make the connected systems more robust and can be used to carry out comparative studies. 18 | 19 | Industry has collected large data sets and sometimes retains pools of real users. They are viewed as strategic competitive resources and so are not shared with the research community. Much fundamental research still remains to be done, such as signal processing in noisy conditions’ recognition of groups of difficult users (like the elderly and non-natives), management of complex dialogs (such as multi party meetings, negotiations, and multimodal interaction), and the automatic use of meta linguistic information such as prosody. 20 | 21 | It is difficult for any one group to collect a significant amount of real user data. The users must be found and their interest maintained. At the same time, the interface must be kept up to date. By having one data-gathering Portal that all dialog systems can connect to, the task for each participating site is easier while the portal is more interesting to potential users. Potential users find a variety of applications and can choose the ones that fulfill their needs at any given time. Also, with one central site (the Portal), only the researchers maintaining the Portal itself are tasked with attracting the users. 22 | 23 | ## How the dialport Works 24 | ![Image](images/overview.png) 25 | 26 | **Figure 1** 27 | 28 | Figure 1 shows an overview about the relations between the Portal and agents. Agents here are defined as any remote dailog systems that have joined Portal. 29 | 30 | The Portal is responsible for facing the users via web or mobile interfaces. It will also provide the following services to all the agents: 31 | 32 | - ASR/TTS 33 | - Meta Dialog Management 34 | - Domain Tracking 35 | - Context Keeping 36 | - Agent Selection 37 | 38 | As for an agent, it has to implement an HTTP API server that supports 3 Portal APIs /init, /next, /end. (defined below). 39 | 40 | Generally speaking, the Portal and an agent will interact as follows: 41 | 42 | 1. The Portal will first interact with a user to find out what the user is interested in (*domain tracking*). 43 | 2. Portal will try to select an remote agent that matches the user's needs the best (*agent selection*). 44 | 3. Portal then starts a new remote session with the selected agent via (*/init*). 45 | 4. Portal will then pass every user utterances to the selected agent via (*/next*). The user is effectively talking to the selected agent. 46 | 5. After the selected agent decides to finish the conversation, the control is back to the Portal and we go back to *Step 1*. 47 | 6. Rarely, the remote agent does not perform well. Portal will end the session via (*/end*) and go back to *Step 1*. 48 | 49 | The above transitions can be compactly represented in the finite-state machine in Figure 2. 50 | 51 | ![Image](images/fsm.png) 52 | 53 | **Figure 2** 54 | 55 | ## Development Cycle 56 | 57 | ![Image](images/flow.png) 58 | 59 | **Figure 3** 60 | 61 | Figure 3 shows the steps that you need to take to become a part of DialPort Portal. 62 | 63 | ## API Documentations: 64 | For a remote agent, all it needs to do is to implement the following 3 API interfaces. They are: 65 | 66 | 1. /init 67 | 2. /next 68 | 3. /end 69 | 70 | Very simple! 71 | 72 | ### 1. Create a new session ### 73 | 74 | Start a new session with your dialog system. If successful, the server will return an JSON containing the session ID. 75 | 76 | **URL** 77 | 78 | /init 79 | 80 | **Method:** 81 | 82 | `POST` 83 | 84 | **Body Data** 85 | 86 | { "sessionID": "USR_1234", 87 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS" 88 | } 89 | 90 | **Success Response (200):** 91 | 92 | { 93 | "sessionID": "USR_1234", 94 | "sys": "This word starts with A", 95 | "version": "1.0-xxx", 96 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS", 97 | "terminal": false 98 | } 99 | 100 | ### 2. Get your system's next response 101 | 102 | For an ongoing session, the portal will use this API to obtain the next system response from your dialog system. 103 | 104 | **URL** 105 | 106 | /next 107 | 108 | **Method:** 109 | 110 | `POST` 111 | 112 | **Body Data** 113 | 114 | { 115 | "sessionID": "USR_1234", 116 | "text": "I guess the answer is APPLE", 117 | "asrConf": 0.9, 118 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS" 119 | } 120 | 121 | **Success Response (200):** 122 | 123 | { 124 | "sessionID": "USR_1234", 125 | "sys": "This word starts with A", 126 | "version": "1.0-xxx", 127 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS", 128 | "terminal": false 129 | } 130 | 131 | ### 3. Terminate a session with your system ### 132 | 133 | The portal sometimes (very rarely) wants to terminate an ongoing session with your dialog system (e.g. due to a lost connection, conversation failure etc.) 134 | 135 | **URL** 136 | 137 | /end 138 | 139 | **Method:** 140 | 141 | `POST` 142 | 143 | **Body Data** 144 | 145 | { 146 | "sessionID": "USR_1234", 147 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS" 148 | } 149 | 150 | **Success Response (200):** 151 | 152 | { 153 | "sessionID": "USR_1234", 154 | "sys": "Goodbye", 155 | "version": "1.0-xxx", 156 | "timeStamp": "yyyy-MM-dd'T'HH-mm-ss.SSS", 157 | "terminal": true 158 | } 159 | 160 | ### Extra Parameters 161 | We are open to any system expecting extra input parameters or returning extra parameters for better interaction purpose. 162 | Here are some example extra parameters: 163 | 164 | Input: initial domain that user is looking for, user profile and etc. 165 | 166 | Output: nonverbal behavior of the agent. Multimedia outputs (photo links, meta information and etc.) 167 | 168 | ### Timezone 169 | For easier synchronization with the DialPort server logging system. Use UTC-4 timezone for all time stamps. 170 | 171 | 172 | ### Example Server Templates 173 | We provide server templates implemented in 3 popular frameworks for your convenience. 174 | 175 | Java: [JAVA Spark Framework](https://github.com/DialRC/RestMrClue) 176 | 177 | Python: [Flask](https://github.com/DialRC/PortalAPI/tree/master/PortalAPIforPythonFlask) 178 | 179 | Javascript: [Nodejs](https://github.com/DialRC/PortalAPI/tree/master/PortalNodeAPIs) 180 | 181 | ## Interested in working with us? 182 | We are happy to hear that you'd like to connect to DialPort. 183 | 184 | **Please read the overall process of connecting to DialPort:** 185 | 186 | 1) Please email Dr. Maxine Eskenazi (max at cs dot cmu dot edu) and include the following description of your system : 187 | 188 | (An Example) 189 | > Organization: Carnegie Mellon University 190 | > 191 | > Contact person in your organization: Kyusong Lee (email: kyusonglee at gmail dot com) 192 | > 193 | > Domain (for example, weather, restaurants) : open domain 194 | > 195 | > Language: English 196 | > 197 | > Name of your system: Qubot 198 | > 199 | > Description: Qubot is a chat-oriented dialog system. ..... 200 | > 201 | > Interface (Describe the interface you presently use - microphone, camera, avatar, 3D, etc.): Just a text input using keyboard. 202 | > 203 | > Keywords: chatbot, question answering, 204 | > 205 | > Examples of utterances that your system would handle: who is the president of United States?, what is the highest mountain in the world?.., 206 | > 207 | > Schedule (when can we try your system, when could you try a connection): We would like to contribute the system in late June. Currently our system is being tested internally. 208 | 209 | 2) When we accept to have you join the Portal, we will give the detailed explanation and some sample code for DialPort integration 210 | 211 | 3) First the system will connect to the Dev version of DialPort and be tested internally by both the DialPort team and your group. 212 | 213 | 4) When the system is robust enough, the system will be promoted to the master version. 214 | 215 | 5) In order to be promoted to the Master version, you must demonstrate that you have IRB permission from your institution. To do this, you should contact Dr. Eskenazi and she will give you the CMU IRB application as well as the present consent form. You are repsonsible for gathering, maintaining and distributing the data corresponding to all of the dialog that users have with your system. 216 | 217 | 218 | If you have any questions, please feel free to contact us. 219 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-dinky -------------------------------------------------------------------------------- /_includes/image.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |
{{ include.description }}
{{ include.description }}
5 | -------------------------------------------------------------------------------- /images/flow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DialRC/PortalAPI/a8cf7d858da8e00d0d20ef0a7ba8a8ac2344991c/images/flow.png -------------------------------------------------------------------------------- /images/fsm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DialRC/PortalAPI/a8cf7d858da8e00d0d20ef0a7ba8a8ac2344991c/images/fsm.png -------------------------------------------------------------------------------- /images/overview.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DialRC/PortalAPI/a8cf7d858da8e00d0d20ef0a7ba8a8ac2344991c/images/overview.png --------------------------------------------------------------------------------