Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass message metadata to interpreter when parsing #6275

Merged
merged 10 commits into from
Sep 22, 2020
1 change: 1 addition & 0 deletions changelog/6275.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add optional metadata argument to ``NaturalLanguageInterpreter``'s parse method.
2 changes: 2 additions & 0 deletions rasa/core/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async def parse(
text: Text,
message_id: Optional[Text] = None,
tracker: Optional[DialogueStateTracker] = None,
metadata: Optional[Dict] = None,
) -> Dict[Text, Any]:
"""Parse a text message.

Expand Down Expand Up @@ -132,6 +133,7 @@ async def parse(
text: Text,
message_id: Optional[Text] = None,
tracker: Optional[DialogueStateTracker] = None,
metadata: Optional[Dict] = None,
) -> Dict[Text, Any]:
"""Parse a text message.

Expand Down
4 changes: 3 additions & 1 deletion rasa/core/processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,9 @@ async def parse_message(
text, message.message_id, tracker
)
else:
parse_data = await self.interpreter.parse(text, message.message_id, tracker)
parse_data = await self.interpreter.parse(
text, message.message_id, tracker, metadata=message.metadata
)

logger.debug(
"Received user message '{}' with intent '{}' "
Expand Down
2 changes: 2 additions & 0 deletions rasa/shared/nlu/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ async def parse(
text: Text,
message_id: Optional[Text] = None,
tracker: Optional[DialogueStateTracker] = None,
metadata: Optional[Dict] = None,
) -> Dict[Text, Any]:
raise NotImplementedError(
"Interpreter needs to be able to parse messages into structured output."
Expand Down Expand Up @@ -130,6 +131,7 @@ async def parse(
text: Text,
message_id: Optional[Text] = None,
tracker: Optional[DialogueStateTracker] = None,
metadata: Optional[Dict] = None,
) -> Dict[Text, Any]:
"""Parse a text message."""

Expand Down
2 changes: 1 addition & 1 deletion tests/core/test_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ async def test_http_parsing():
assert r


async def mocked_parse(self, text, message_id=None, tracker=None):
async def mocked_parse(self, text, message_id=None, tracker=None, metadata=None):
"""Mock parsing a text message and augment it with the slot
value from the tracker's state."""

Expand Down