diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index c4f1b21f..9499d55b 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -4,8 +4,8 @@ To add a new module, follow these steps: 1. Fork the repo 2. Create a new branch (`git checkout -b my-new-feature`) -3. Add a new file in `modules/src/` folder (define `match` and `process` functions) -4. Add some tests in `modules/tests/` folder (run them locally with `py.test`) +3. Add a new file in `modules/src/` folder (define `process` function) +4. Add some tests in `modules/tests/` folder 5. Add the module name in `src/__init__.py` 6. Commit your changes (`git commit -am 'Add some feature'`) 7. Push to the branch (`git push origin my-new-feature`) @@ -23,8 +23,6 @@ To fix a bug or enhance an existing module, follow these steps: 6. Push to the branch (`git push origin improve-feature`) 7. Create a Pull Request -You may take this [commit](https://github.com/swapagarwal/JARVIS-on-Messenger/commit/ee974e44d027f8bdc4329a35e1d8410d7779acb2) as a reference. - Keep the code as simple as possible. No need of obfuscation / code golf. If you have to explain your code, you're doing it wrong! diff --git a/README.md b/README.md index d063b918..99036f7a 100644 --- a/README.md +++ b/README.md @@ -42,17 +42,17 @@ There are a lot of features that I've planned for JARVIS. Feel free to add to th Some advanced features: - [ ] Add templates support (Structured Messages) -- [ ] Integrate with [Wit.ai](https://wit.ai/swapagarwal/JARVIS-on-Messenger) to parse Natural Language +- [x] Integrate with [Wit.ai](https://wit.ai/swapagarwal/JARVIS-on-Messenger) to parse Natural Language - [ ] Retain context between queries ### Structure ```sh -├── modules/ # home for various features -├── modules/src/ # code goes here -├── modules/tests/ # tests go here -├── CONTRIBUTING.md # contributing guidelines -└── jarvis.py # the main bot +├── modules/ # home for various features +├── modules/src/ # code goes here +├── modules/tests/ # tests go here +├── CONTRIBUTING.md # contributing guidelines +└── jarvis.py # the main bot ``` ### Usage @@ -61,16 +61,11 @@ JARVIS is at your service [here](http://m.me/J.A.R.V.I.S.on.Messenger). Currentl ### Sample Queries -`Hi, Jarvis!` - -`Are you there?` - -`tell me a joke` - -`iron man movie` - -`cloud definition` - +`Hi, Jarvis!` +`Are you there?` +`tell me a joke` +`iron man movie` +`cloud definition` More examples can be found [here](https://github.com/swapagarwal/JARVIS-on-Messenger/tree/master/modules/tests). ### Local Development / Testing @@ -79,4 +74,14 @@ More examples can be found [here](https://github.com/swapagarwal/JARVIS-on-Messe 2. `sudo apt-get install python-dev libffi-dev libssl-dev` 3. `pip install -r requirements.txt` 4. `python jarvis.py` -5. Visit `http://localhost:5000/test/?q=` to see results. +5. Visit the following URLs to see results: +`http://localhost:5000/process/?q=` returns the intent of the query. +`http://localhost:5000/search/?q=` returns the search result of the query. + +### History + +I started out with rule-based model but it didn't scale well so now I've shifted to Natural Language Processing. +Rest assured, I'll strive to keep it as simple as possible so that you, yes you, can contribute! + +If you'd like to contribute to the old model, you are welcome to do so as well. +I've created a new branch [`legacy`](https://github.com/swapagarwal/JARVIS-on-Messenger/tree/legacy) for this purpose. I'll be accepting Pull Requests to this branch also. :smile: diff --git a/config.py b/config.py index 42002a8c..aa898cea 100644 --- a/config.py +++ b/config.py @@ -1,3 +1,3 @@ ACCESS_TOKEN = '' VERIFY_TOKEN = '' -WIT_AI_SERVER_ACCESS_TOKEN = '' +WIT_AI_ACCESS_TOKEN = 'IKJJJYYVR3X672DHFVS7U7C4L2MQSS2P' diff --git a/jarvis.py b/jarvis.py index 02ba3619..203fcd92 100644 --- a/jarvis.py +++ b/jarvis.py @@ -14,8 +14,12 @@ def about(): return 'Just A Rather Very Intelligent System, now on Messenger!' -@app.route('/test/') -def test(): +@app.route('/process/') +def process(): + return json.dumps(modules.process_query(request.args.get('q'))) + +@app.route('/search/') +def search(): return modules.search(request.args.get('q')) @app.route('/webhook/', methods=['GET', 'POST']) diff --git a/modules/__init__.py b/modules/__init__.py index 66018c03..a25fa8ca 100644 --- a/modules/__init__.py +++ b/modules/__init__.py @@ -4,12 +4,12 @@ import sys from src import * -WIT_AI_SERVER_ACCESS_TOKEN = os.environ.get('WIT_AI_SERVER_ACCESS_TOKEN', config.WIT_AI_SERVER_ACCESS_TOKEN) +WIT_AI_ACCESS_TOKEN = os.environ.get('WIT_AI_ACCESS_TOKEN', config.WIT_AI_ACCESS_TOKEN) def process_query(input): try: r = requests.get('https://api.wit.ai/message?v=20160420&q=' + input, headers={ - 'Authorization': 'Bearer %s' % WIT_AI_SERVER_ACCESS_TOKEN + 'Authorization': 'Bearer %s' % WIT_AI_ACCESS_TOKEN }) data = r.json() intent = data['outcomes'][0]['intent']