Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
Initialize repository
Browse files Browse the repository at this point in the history
Signed-off-by: denim2x <[email protected]>
  • Loading branch information
denim2x committed May 31, 2019
0 parents commit 5d78f96
Show file tree
Hide file tree
Showing 28 changed files with 1,993 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.gitignore
LICENSE
README.md
vcap-local.json
node_modules
.settings
.git
.project
.pydevproject
*tmp-browserify*
71 changes: 71 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Logs
logs
*.log

# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
bin/
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
/lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# python virtual environment/compiled files
venv/
*.pyc

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Intellij/PyCharm config
.idea/

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml

# Translations
*.mo
*.pot

# PyBuilder
target/

# Mac files
*.DS_Store

vcap-local.json
node_modules
.settings
.project
.pydevproject
config.yaml
*tmp-browserify*
7 changes: 7 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2019 denim2x <[email protected]> (denim2x.ml)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: python3 main.py
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Whizbot
Engage into interesting conversations with this multi-purpose chatbot

## Description
This project aims to develop an interesting conversational agent with the following capabilities:
- describes itself, its abilities and others;
- answers open-ended questions with information from Wikipedia;
- displays Weather data;
- shows Chuck Norris jokes.

## Architecture
### Frontend
- HTML5
- JavaScript (ES6)
- CSS3
- Rivets.js
- Domtastic

### Backend
- Web server developed in Python3 with BareASGI, hosted on CloudFoundry service;
- Watson Assistant, for classifying intents and modeling appropriate responses;
- Weather Company Data for IBM Bluemix - for retrieving weather information;
- Wikipedia Search API - for retrieving answers to open-ended questions;
- Chuck Norris jokes API.

10 changes: 10 additions & 0 deletions _bareasgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import bareasgi as _bareasgi
from bareasgi import *

def json_response(data, status=200, headers={}):
headers = [] # FIXME
return _bareasgi.json_response(status, headers, data)

def text_response(text, status=200, headers={}):
headers = []
return _bareasgi.text_response(status, headers, text)
136 changes: 136 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
'use strict';
/*jslint node: true */
/*jslint esversion: 6 */
/* globals $: true */
/* eqeqeq: false */
/* -W041: false */
const type = require('type-of');
const request = require('superagent');
const h = require('hyperscript-string');
const $ = require('domtastic');
const rivets = require('rivets');

$.fn.clear = function() {
this.forEach((e) => {
e.innerHTML = '';
});
return this;
};

$.fn.outerHTML = function() {
return this.prop('outerHTML');
};

const state = {
message: '',
knowledge: [],
conversation: [],
error: false
};

function _error(method, url, { response: res }) {
res = res ? [res.status, res.text] : [];
console.warn(`[${method} ${url}]`, ...res);
}

function send_message(text='', cb) {
request.post('/message').send(text).then(({ body }) => {
state.conversation.push({ text: body });
}, (e) => {
_error('POST', '/message', e);
cb && cb();
});
}

send_message();

$('.Conversation-input')
.on('keydown', (e) => {
let message = state.message;
if (e.code == 'Enter' && !e.shiftKey && !e.altKey && !e.ctrlKey) {
if (message == '')
return;
state.message = '';
state.conversation.push({ text: message.split(/\s*[\n\r]+\s*/g), is_user: true });
send_message(message, () => {
state.error = true;
});
return false;
}
})
.on('paste', (e) => {
e.preventDefault();
let text = e.clipboardData.getData("text/plain");
document.execCommand("insertHTML", false, text);
return false;
});

function _const(self, key, value) {
Object.defineProperty(self, key, {
value, writable: false, enumerable: true, configurable: true
});
return self;
}

const { Binding } = rivets._;
rivets._.Binding = class extends Binding {
parseTarget() {
if (this.binder.parseTarget) {
Object.assign(this, this.binder.parseTarget(this.keypath));
}
return super.parseTarget();
}

publish() {
_const(this, 'state', 'publish');
let ret = super.publish();
_const(this, 'state');
}
};

rivets.binders['input'] = {
parseTarget(keypath) {
let empty_class;
[keypath, empty_class] = keypath.trim().split(/\s*\?\s*/);
return { keypath, empty_class };
},

bind: function(el) {
this._empty = true;
$(el).on('input.rv-input', this.publish);
this._watch = () => {
el.innerHTML = '';
if (el.innerHTML == '') {
clearInterval(this._watcher);
}
};
},

unbind: function(el) {
$(el).off('.rv-input');
clearInterval(this._watcher);
},

routine: function(el, value) {
if (this.state != 'publish') {
clearInterval(this._watcher);
el.innerText = value;
}
state.error = false;
this._empty = value == '';
if (this._empty) {
this._watcher = setInterval(this._watch, 30);
}
if (this.empty_class) {
$(el).toggleClass(this.empty_class, this._empty);
}
},

getValue : function(el) {
return el.innerText.trim();
}
};

global.$state = state;

rivets.bind(document.body, state);
Loading

0 comments on commit 5d78f96

Please sign in to comment.