Skip to content

Commit

Permalink
memo policy
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgolabek committed Nov 29, 2018
1 parent 11972d5 commit b7c0ac6
Show file tree
Hide file tree
Showing 14 changed files with 22 additions and 19 deletions.
Binary file modified doc/core-analyze.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/core-chat.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/core-conversations.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/core-domain_file.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/core-memoization_policy.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/core-stories_files.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/nlu-md_files.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/RasaHost/RasaHost/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RasaHost:
nlu_path = os.path.join(current_dir, "data/nlu/")
stories_path = os.path.join(current_dir, "data/stories/")
domain_path = os.path.join(current_dir, "data/domain.yml")
memoization_policy_path = os.path.join(current_dir, "models/current/dialogue/policy_1_MemoizationPolicy")
host = environ.get('SERVER_HOST', '0.0.0.0')
port = 5555
agent = None
Expand Down
5 changes: 3 additions & 2 deletions src/RasaHost/RasaHost/controllers/models_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@

@app.route('/models/MemoizationPolicy')
def models_memoization_policy():
MemoizationPolicyService(host.memoization_policy_path).decode()
return render_template(
'models/memoization_policy.html',
title='MemoizationPolicy',
)

@app.route('/api/models/MemoizationPolicy/lookups/decode', methods=['POST'])
def api_models_memoization_policy_lookups_decode():
MemoizationPolicyService('C:\\Projects\\GSA\\Investec.Bot\\Investec.Bot\\models\\current\\dialogue\\policy_1_MemoizationPolicy').decode()
MemoizationPolicyService(host.memoization_policy_path).decode()
return jsonify({"result":"ok"})


@app.route('/api/models/MemoizationPolicy/lookups', methods=['GET'])
def api_models_memoization_policy_lookups():
query = request.args.get('q')
last_index = int(request.args.get('i', 0))
result = MemoizationPolicyService('C:\\Projects\\GSA\\Investec.Bot\\Investec.Bot\\models\\current\\dialogue\\policy_1_MemoizationPolicy').find(query, last_index)
result = MemoizationPolicyService(host.memoization_policy_path).find(query, last_index)
return jsonify({"result": result})
14 changes: 10 additions & 4 deletions src/RasaHost/RasaHost/services/memoization_policy_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,28 @@ class MemoizationPolicyService(object):

def __init__(self, path = None, *args, **kwargs):
self.path = path
self.memorized_turns_path = os.path.join(self.path, 'memorized_turns.json')
self.memorized_turns_lookups_path = os.path.join(self.path, 'memorized_turns_lookups.txt')
pass

def decode(self):
with open(os.path.join(self.path, 'memorized_turns.json')) as f_encoded:
if not os.path.exists(self.memorized_turns_path):
return
with open(self.memorized_turns_path) as f_encoded:
memorized_turns = json.load(f_encoded)
with open(os.path.join(self.path, 'memorized_turns_lookups.txt'), 'a+') as f_decoded:
with open(self.memorized_turns_lookups_path, 'a+') as f_decoded:
for lookup in memorized_turns["lookup"]:
b64decoded = base64.b64decode(lookup)
decompressed = zlib.decompress(bytes(b64decoded))
text = decompressed.decode("utf-8")
f_decoded.write(text + "\n")

def find(self, query, last_index):
if not os.path.exists(self.memorized_turns_lookups_path):
return []
lookups = []
current_last_index = 0
with open(os.path.join(self.path, 'memorized_turns_lookups.txt'), 'r') as f_decoded:
with open(self.memorized_turns_lookups_path, 'r') as f_decoded:
for index, line in enumerate(f_decoded):
current_last_index = index
if current_last_index > last_index:
Expand All @@ -44,7 +50,7 @@ def parse_lookup(self, lookup):

def parse(self):
lookups = []
with open(os.path.join(self.path, 'memorized_turns.json')) as f_encoded:
with open(self.memorized_turns_path) as f_encoded:
memorized_turns = json.load(f_encoded)
with Pool() as p:
lookups = p.map(parse_lookup, memorized_turns["lookup"])
Expand Down
15 changes: 5 additions & 10 deletions src/RasaHost/RasaHost/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ <h6 class="sidebar-heading px-3 mt-4 mb-1 text-muted">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text" color="#384047"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg> analyze
</a>
</li>
<li class="nav-item">
<a href="/models/MemoizationPolicy" class="nav-link {{"active" if request.path.lower().startswith("/models/memoizationpolicy") else "" }}">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text" color="#384047"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg> memoization policy
</a>
</li>
</ul>
<h6 class="sidebar-heading px-3 mt-4 mb-1 text-muted">
<span class="text-secondary">Other</span>
Expand All @@ -104,16 +109,6 @@ <h6 class="sidebar-heading px-3 mt-4 mb-1 text-muted">
</a>
</li>
</ul>
<h6 class="sidebar-heading px-3 mt-4 mb-1 text-muted d-none">
<span class="text-secondary">Model</span>
</h6>
<ul class="nav flex-column d-none">
<li class="nav-item">
<a href="/models/MemoizationPolicy" class="nav-link">
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-file-text" color="#384047"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path><polyline points="14 2 14 8 20 8"></polyline><line x1="16" y1="13" x2="8" y2="13"></line><line x1="16" y1="17" x2="8" y2="17"></line><polyline points="10 9 9 9 8 9"></polyline></svg> Memoization Policy
</a>
</li>
</ul>
</nav>
<main role="main" class="col main">
{% block content %}{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{% raw %}
<div id="app" v-cloak>
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pb-2 mb-3 pt-1">
<h1 class="h4">Models - Memoization Policy</h1>
<h1 class="h4">core - memoization policy</h1>
<div class="btn-toolbar mb-2 mb-md-0">
<div class="input-group">
<input v-model="query" v-on:keyup.enter="search" type="text" class="form-control form-control-sm" placeholder="Search...">
Expand All @@ -14,9 +14,9 @@ <h1 class="h4">Models - Memoization Policy</h1>
</div>
</div>
</div>
<a v-on:click.stop.prevent="decode()" href="#" class="icon text-muted ml-3">
<!--<a v-on:click.stop.prevent="decode()" href="#" class="icon text-muted ml-3">
Decode <div v-if="isDecoding" class="loader"></div>
</a>
</a>-->
</div>
<div class="row">
<div class="col-md-12">
Expand Down
Binary file modified src/RasaHost/dist/rasa-host-0.3.0.tar.gz
Binary file not shown.
Binary file modified src/RasaHost/dist/rasa_host-0.3.0-py3-none-any.whl
Binary file not shown.

0 comments on commit b7c0ac6

Please sign in to comment.