-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyborg_http.py
52 lines (40 loc) · 1.13 KB
/
pyborg_http.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import bottle
import baker
from bottle import request
from pyborg.pyborg import pyborg
our_pyborg = pyborg()
@bottle.route("/")
def index():
return "<h1>Welcome to Pyborg/http</h1>"
# Basic API
@bottle.route("/learn", method="POST")
def learn():
body = request.POST.get("body")
our_pyborg.learn(body)
return "OK"
@bottle.route("/reply", method="POST")
def reply():
body = request.POST.get("body")
return our_pyborg.reply(body)
# Advanced API
class DumbyIOMod(object):
message = None
"""fake IO mod for pyborg interop"""
def output(self, message, args):
self.message = message
self.args = args
@bottle.route("/process", method="POST")
def process():
body = request.POST.get("body")
reply_rate = request.POST.get("reply_rate")
learning = request.POST.get("learning")
owner = request.POST.get("owner")
io = DumbyIOMod()
our_pyborg.process_msg(io, body, reply_rate, learning, None, owner)
if io.message:
return io.message
else:
return ""
if __name__ == '__main__':
bottle.run(host="localhost", port=2001, reloader=True)
our_pyborg.save_all()