This repository has been archived by the owner on Jun 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* cloudbot refactor Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * duplicate requirements purge Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * wa skills refactor Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * add remote server Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * tested without z Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * dummy config Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * merge ready Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * added try prefix in suggestion Signed-off-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com> * Update README.md * Update README.md * Create README.md Co-authored-by: Tathagata Chakraborti <tathagata.chakraborti1@ibm.com>
- Loading branch information
1 parent
736a30d
commit 6c1ce12
Showing
20 changed files
with
308 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[DEFAULT] | ||
name=nlc2cmd | ||
description=This skill helps you compress and uncompress archives using natural language commands. | ||
description=This skill helps you compress archives, find files, etc. using English commands. | ||
default=yes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
web: python3 run.py > stdout.txt 2>stderr.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## Remote WA router | ||
|
||
This flask application is a router for requests to the watson assistant instance | ||
that processes most of the `nlc2cmd` use cases. To bring up the server: | ||
|
||
1. Fill in the details of your assistant and skill in `config.json` | ||
2. Run `>> python3 run.py` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"i_am_id" : "", | ||
"skills" : { | ||
|
||
"tarbot" : "", | ||
"grepbot" : "", | ||
"zosbot" : "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
applications: | ||
- name: nlc2cmd | ||
memory: 1G | ||
path: . | ||
buildpacks: | ||
- python_buildpack |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Flask==0.12.2 | ||
ibm-watson>=4.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#!/usr/bin/env python3 | ||
|
||
''' | ||
imports | ||
''' | ||
from flask import Flask, request, render_template | ||
from typing import Dict | ||
|
||
from ibm_watson import AssistantV2 | ||
from ibm_cloud_sdk_core.authenticators import IAMAuthenticator | ||
|
||
import json | ||
import os | ||
import inspect | ||
|
||
''' | ||
globals | ||
''' | ||
|
||
config = json.loads( open('config.json').read() ) | ||
|
||
authenticator = IAMAuthenticator(config["i_am_id"]) | ||
assistant = AssistantV2( | ||
version='2020-13-05', | ||
authenticator=authenticator | ||
) | ||
|
||
assistant.set_service_url('https://gateway.watsonplatform.net/assistant/api') | ||
|
||
'''''' | ||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
return "Welcome to the router for the WA instances for the nlc2cmd skill in CLAI." | ||
|
||
''' | ||
endpoint for tarbot | ||
''' | ||
@app.route("/tarbot", methods=['GET', 'POST', 'PUT']) | ||
def tarbot(): | ||
return get_response( | ||
assistant_id = config["skills"][inspect.stack()[0][3]], | ||
data = json.loads(request.get_data().decode('utf-8')) ) | ||
|
||
''' | ||
endpoint for grepbot | ||
''' | ||
@app.route("/grepbot", methods=['GET', 'POST', 'PUT']) | ||
def grepbot(): | ||
return get_response( | ||
assistant_id = config["skills"][inspect.stack()[0][3]], | ||
data = json.loads(request.get_data().decode('utf-8')) ) | ||
|
||
''' | ||
endpoint for zosbot | ||
''' | ||
@app.route("/zosbot", methods=['GET', 'POST', 'PUT']) | ||
def zosbot(): | ||
return get_response( | ||
assistant_id = config["skills"][inspect.stack()[0][3]], | ||
data = json.loads(request.get_data().decode('utf-8')) ) | ||
|
||
|
||
''' get response from WA workspace ''' | ||
def get_response(assistant_id: str, data: Dict) -> Dict: | ||
|
||
try: | ||
|
||
session_info = assistant.create_session(assistant_id=assistant_id).get_result() | ||
response = assistant.message( | ||
assistant_id=assistant_id, | ||
session_id=session_info['session_id'], | ||
input={ | ||
'message_type': 'text', | ||
'text': data['text'], | ||
'options' : {'alternate_intents' : True} | ||
} | ||
).get_result() | ||
|
||
return json.dumps( { 'result' : 'success', 'response' : response } ) | ||
|
||
except Exception as e: | ||
return json.dumps( { 'result' : str(e) } ) | ||
|
||
|
||
''' main ''' | ||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', port=int(os.getenv('PORT', 3456))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
python-3.6.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"cloudbot" : "https://ibmcloud-helper.mybluemix.net/message", | ||
"tarbot" : "http://nlc2cmd.mybluemix.net/tarbot", | ||
"grepbot" : "http://nlc2cmd.mybluemix.net/grepbot", | ||
"zosbot" : "http://nlc2cmd.mybluemix.net/zosbot" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.