Skip to content

Commit

Permalink
Merge branch 'main' into 8569-drop-py36-support
Browse files Browse the repository at this point in the history
  • Loading branch information
m-vdb authored Jul 29, 2021
2 parents 11f163a + d3084a1 commit 20bd14c
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/ci-model-regression-on-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ jobs:
OUTPUT="${OUTPUT//$'\n'/'%0A'}"
OUTPUT="${OUTPUT//$'\r'/'%0D'}"
OUTPUT="$(echo $OUTPUT | sed 's|`|\\`|g')"
echo "::set-output name=report_description::${OUTPUT}"
IS_DROPPED=false
Expand Down Expand Up @@ -493,12 +494,17 @@ jobs:
# do not use GITHUB_TOKEN here because it wouldn't trigger subsequent workflows
github-token: ${{ secrets.RASABOT_GITHUB_TOKEN }}
script: |
// Prepare issue body
let issue_body = '*This PR is automatically created by the Scheduled Model Regression Test workflow. Checkout the Github Action Run [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).* <br> --- <br> **Description of Problem:** <br> Some test performance scores **decreased**. Please look at the following table for more details. <br>'
issue_body += `${{ steps.performance.outputs.report_description }}`
// Open issue
var issue = await github.issues.create({
owner: context.repo.owner,
repo: context.repo.repo,
title: '${{ env.GITHUB_ISSUE_TITLE }}',
labels: ${{ env.GITHUB_ISSUE_LABELS }},
body: '"*This PR is automatically created by the Scheduled Model Regression Test workflow. Checkout the Github Action Run [here](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}).* <br> --- <br> **Description of Problem:** <br> Some test performance scores **decreased**. Please look at the following table for more details. <br> ${{ steps.performance.outputs.report_description }}"'
body: issue_body
})
return issue.data.number
Expand Down
1 change: 1 addition & 0 deletions changelog/9193.improvement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added debug message that logs when a response condition is used.
27 changes: 26 additions & 1 deletion rasa/core/nlg/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,17 @@ def _random_response_for(
)

if suitable_responses:
return np.random.choice(suitable_responses)
selected_response = np.random.choice(suitable_responses)
condition = selected_response.get(RESPONSE_CONDITION)
if condition:
formatted_response_conditions = self._format_response_conditions(
condition
)
logger.debug(
"Selecting response variation with conditions:"
f"{formatted_response_conditions}"
)
return selected_response
else:
return None
else:
Expand Down Expand Up @@ -177,3 +187,18 @@ def _response_variables(
response_vars = filled_slots.copy()
response_vars.update(kwargs)
return response_vars

@staticmethod
def _format_response_conditions(response_conditions: List[Dict[Text, Any]]) -> Text:
formatted_response_conditions = [""]
for index, condition in enumerate(response_conditions):
constraints = []
constraints.append(f"type: {str(condition['type'])}")
constraints.append(f"name: {str(condition['name'])}")
constraints.append(f"value: {str(condition['value'])}")

condition_message = " | ".join(constraints)
formatted_condition = f"[condition {str(index + 1)}] {condition_message}"
formatted_response_conditions.append(formatted_condition)

return "\n".join(formatted_response_conditions)
43 changes: 43 additions & 0 deletions tests/core/nlg/test_response.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Text, Any

import logging
import pytest
from _pytest.logging import LogCaptureFixture

from rasa.core.nlg.response import TemplatedNaturalLanguageGenerator
from rasa.shared.core.domain import Domain
Expand Down Expand Up @@ -398,3 +400,44 @@ async def test_nlg_conditional_edgecases(slots, channel, expected_response):
tracker = DialogueStateTracker(sender_id="test", slots=slots)
r = await t.generate("utter_action", tracker, channel)
assert r.get("text") == expected_response


async def test_nlg_conditional_response_variations_condition_logging(
caplog: LogCaptureFixture,
):
domain = Domain.from_yaml(
"""
version: "2.0"
responses:
utter_action:
- text: "example"
condition:
- type: slot
name: test_A
value: A
- type: slot
name: test_B
value: B
- text: "default"
"""
)
t = TemplatedNaturalLanguageGenerator(domain.responses)
slot_A = TextSlot(name="test_A", initial_value="A", influence_conversation=False)
slot_B = TextSlot(name="test_B", initial_value="B", influence_conversation=False)
tracker = DialogueStateTracker(sender_id="test", slots=[slot_A, slot_B])

with caplog.at_level(logging.DEBUG):
await t.generate("utter_action", tracker=tracker, output_channel="")

assert any(
"Selecting response variation with conditions:" in message
for message in caplog.messages
)
assert any(
"[condition 1] type: slot | name: test_A | value: A" in message
for message in caplog.messages
)
assert any(
"[condition 2] type: slot | name: test_B | value: B" in message
for message in caplog.messages
)

0 comments on commit 20bd14c

Please sign in to comment.