Skip to content

Commit

Permalink
Merge branch '2.0.x' into copyedits-playground
Browse files Browse the repository at this point in the history
  • Loading branch information
rasabot committed Oct 7, 2020
2 parents 848f194 + 60228ec commit 90c2fc8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
31 changes: 31 additions & 0 deletions data/test_config/config_with_comment_between_suggestions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
language: en
pipeline:
# # No configuration for the NLU pipeline was provided. The following default pipeline was used to train your model.
# # If you'd like to customize it, uncomment and adjust the pipeline.
# # See https://rasa.com/docs/rasa/tuning-your-model for more information.
# - name: WhitespaceTokenizer
# - name: RegexFeaturizer
# - name: LexicalSyntacticFeaturizer
# - name: CountVectorsFeaturizer
# - name: CountVectorsFeaturizer
# analyzer: char_wb
# min_ngram: 1
# max_ngram: 4
# - name: DIETClassifier
# epochs: 100
# - name: EntitySynonymMapper
# - name: ResponseSelector
# epochs: 100
# - name: FallbackClassifier
# threshold: 0.3
# ambiguity_threshold: 0.1
# some other comment in here
policies:
# # No configuration for policies was provided. The following default policies were used to train your model.
# # If you'd like to customize them, uncomment and adjust the policies.
# # See https://rasa.com/docs/rasa/policies for more information.
# - name: MemoizationPolicy
# - name: TEDPolicy
# max_history: 5
# epochs: 100
# - name: RulePolicy
17 changes: 9 additions & 8 deletions rasa/shared/importers/autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import os
from enum import Enum
from pathlib import Path
from typing import Text, Dict, Any, List, Set, Optional

import rasa.shared.constants
Expand Down Expand Up @@ -165,14 +166,14 @@ def _dump_config(

autoconfig_lines = _get_commented_out_autoconfig_lines(config, auto_configured_keys)

with open(
config_file_path, "r+", encoding=rasa.shared.utils.io.DEFAULT_ENCODING
) as f:
lines = f.readlines()
updated_lines = _get_lines_including_autoconfig(lines, autoconfig_lines)
f.seek(0)
for line in updated_lines:
f.write(line)
current_config_content = rasa.shared.utils.io.read_file(config_file_path)
current_config_lines = current_config_content.splitlines(keepends=True)

updated_lines = _get_lines_including_autoconfig(
current_config_lines, autoconfig_lines
)

rasa.shared.utils.io.write_text_file("".join(updated_lines), config_file_path)

auto_configured_keys = rasa.shared.utils.common.transform_collection_to_sentence(
auto_configured_keys
Expand Down
16 changes: 16 additions & 0 deletions tests/shared/importers/test_autoconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,19 @@ def test_get_configuration_for_different_training_types(
expected = rasa.shared.utils.io.read_file(str(CONFIG_FOLDER / expected_file))

assert actual == expected


def test_comment_causing_invalid_autoconfig(tmp_path: Path):
"""Regression test for https://github.com/RasaHQ/rasa/issues/6948."""

config_file = tmp_path / "config.yml"
shutil.copyfile(
str(CONFIG_FOLDER / "config_with_comment_between_suggestions.yml"), config_file
)

_ = autoconfig.get_configuration(str(config_file))

# This should not throw
dumped = rasa.shared.utils.io.read_yaml_file(config_file)

assert dumped

0 comments on commit 90c2fc8

Please sign in to comment.