Skip to content

Commit

Permalink
Merge pull request #4989 from RasaHQ/empty-domain-for-nlu-models
Browse files Browse the repository at this point in the history
use empty domain in case Domain is None (e.g. if it's a NLU only model)
  • Loading branch information
wochinge authored Dec 18, 2019
2 parents 89e5a4c + 0ffe17e commit 1d9fc56
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 2 additions & 0 deletions changelog/4989.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Use an empty domain in case a model is loaded which has no domain
(avoids errors when accessing ``agent.doman.<some attribute>``).
4 changes: 2 additions & 2 deletions rasa/core/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def update_model(
interpreter: Optional[NaturalLanguageInterpreter] = None,
model_directory: Optional[Text] = None,
) -> None:
self.domain = domain
self.domain = self._create_domain(domain)
self.policy_ensemble = policy_ensemble

if interpreter:
Expand Down Expand Up @@ -858,7 +858,7 @@ def create_processor(
)

@staticmethod
def _create_domain(domain: Union[Domain, Text]) -> Domain:
def _create_domain(domain: Union[Domain, Text, None]) -> Domain:

if isinstance(domain, str):
domain = Domain.load(domain)
Expand Down
7 changes: 2 additions & 5 deletions tests/core/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,10 @@ def test_two_stage_fallback_without_deny_suggestion(domain, policy_config):
async def test_agent_update_model_none_domain(trained_model: Text):
agent = await load_agent(model_path=trained_model)
agent.update_model(
Domain.empty(),
None,
agent.fingerprint,
agent.interpreter,
agent.model_directory,
None, None, agent.fingerprint, agent.interpreter, agent.model_directory
)

assert agent.domain is not None
sender_id = "test_sender_id"
message = UserMessage("hello", sender_id=sender_id)
await agent.handle_message(message)
Expand Down

0 comments on commit 1d9fc56

Please sign in to comment.