Skip to content
This repository has been archived by the owner on Aug 22, 2019. It is now read-only.

Commit

Permalink
Merge branch 'master' into fix_interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Ghostvv committed Jan 25, 2019
2 parents 4921ac3 + 8a20228 commit 688e6e8
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.rst
Expand Up @@ -4,14 +4,27 @@ Change Log
All notable changes to this project will be documented in this file.
This project adheres to `Semantic Versioning`_ starting with version 0.2.0.

.. _master-release:

[Unreleased 0.13.1.aX] - `master`_
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. note:: This version is not yet released and is under active development.

Added
-----
- ``message_id`` can now be passed in the payload to the ``NLUHttpInterpreter``

Removed
-------

Changed
-------

Fixed
-----
- fix form validation question error in interactive learninig


.. _v0-13-0:

[0.13.0] - 2019-01-23
Expand Down
10 changes: 6 additions & 4 deletions rasa_core/interpreter.py
Expand Up @@ -174,18 +174,18 @@ def __init__(self,
else:
self.endpoint = EndpointConfig(constants.DEFAULT_SERVER_URL)

def parse(self, text):
def parse(self, text, message_id=None):
"""Parse a text message.
Return a default value if the parsing of the text failed."""

default_return = {"intent": {"name": "", "confidence": 0.0},
"entities": [], "text": ""}
result = self._rasa_http_parse(text)
result = self._rasa_http_parse(text, message_id)

return result if result is not None else default_return

def _rasa_http_parse(self, text):
def _rasa_http_parse(self, text, message_id=None):
"""Send a text message to a running rasa NLU http server.
Return `None` on failure."""
Expand All @@ -200,8 +200,10 @@ def _rasa_http_parse(self, text):
"token": self.endpoint.token,
"model": self.model_name,
"project": self.project_name,
"q": text
"q": text,
"message_id": message_id
}

url = "{}/parse".format(self.endpoint.url)
try:
result = requests.get(url, params=params)
Expand Down
25 changes: 24 additions & 1 deletion tests/test_interpreter.py
@@ -1,7 +1,11 @@
import pytest

import rasa_core
from rasa_core.interpreter import RegexInterpreter, INTENT_MESSAGE_PREFIX
from rasa_core.interpreter import (RegexInterpreter,
INTENT_MESSAGE_PREFIX,
RasaNLUHttpInterpreter)
from rasa_core.utils import EndpointConfig
from httpretty import httpretty


def test_regex_interpreter():
Expand Down Expand Up @@ -65,3 +69,22 @@ def test_regex_interpreter_adds_intent_prefix():
r = interpreter.parse('mood_greet{"name": "rasa"}')

assert r.get("text") == '/mood_greet{"name": "rasa"}'


def test_http_interpreter():

httpretty.register_uri(httpretty.GET,
'https://interpreter.com/parse')

endpoint = EndpointConfig('https://interpreter.com')
httpretty.enable()
interpreter = RasaNLUHttpInterpreter(endpoint=endpoint)
interpreter.parse(text='message_text', message_id='1134')

query = httpretty.last_request.querystring
httpretty.disable()
response = {'project': ['default'],
'q': ['message_text'],
'message_id': ['1134']}

assert query == response

0 comments on commit 688e6e8

Please sign in to comment.