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

Add core and nlu additional params to training endpoint #8132

Merged
merged 14 commits into from
Mar 22, 2021

Conversation

theanht1
Copy link
Contributor

@theanht1 theanht1 commented Mar 6, 2021

Proposed changes:

Status (please check what you already did):

  • added some tests for the functionality
  • updated the documentation
  • updated the changelog (please check changelog for instructions)
  • reformat files using black (please check Readme for instructions)

@CLAassistant
Copy link

CLAassistant commented Mar 6, 2021

CLA assistant check
All committers have signed the CLA.

@theanht1
Copy link
Contributor Author

theanht1 commented Mar 6, 2021

@wochinge please review this, I'll update the changelog later

@sara-tagger sara-tagger requested a review from amn41 March 8, 2021 07:00
@sara-tagger
Copy link
Collaborator

Thanks for submitting a pull request 🚀 @amn41 will take a look at it as soon as possible ✨

Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this clean and concise change! 🚀

Can you please also add a changelog entry?

rasa/server.py Outdated
@@ -69,7 +69,7 @@
from rasa.core.utils import AvailableEndpoints
from rasa.nlu.emulators.no_emulator import NoEmulator
from rasa.nlu.test import run_evaluation, CVEvaluationResult
from rasa.utils.endpoints import EndpointConfig
from rasa.utils.endpoints import EndpointConfig, bool_arg, float_arg, int_arg
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have some internal code convention where we say that don't want to import functions directly in favor of explictly referring to it by module. So it would be great if you could also refer to bool_arg etc. using rasa.utils.endpoints.bool_arg 🙌🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

rasa/utils/endpoints.py Show resolved Hide resolved
def int_arg(
request: Request, key: Text, default: Optional[int] = None
) -> Optional[int]:
"""Return a passed argument cast as an int or None.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also describe the other paramaters and then return values using Args: and Returns:?

Suggested change
"""Return a passed argument cast as an int or None.
"""Returns a passed argument cast as an int or None.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added for bool_arg, float_arg and int_arg

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Minor comment: Could you please change Return to Returns? We try to use descriptive docstrings in the codebase.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I forgot to update this one

rasa/utils/endpoints.py Show resolved Hide resolved
docs/static/spec/rasa.yml Show resolved Hide resolved
* Use argument casting functions from endpoints module
* Update docstring
* Add tests for argument casting functions
* Add changelog
@wochinge wochinge removed the request for review from amn41 March 15, 2021 08:43
docs/static/spec/rasa.yml Show resolved Hide resolved
("true", False, True),
],
)
def test_bool_arg(value, default, expected_result):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you please add type annotations to the test parameters? (same for the other test functions) 🙌🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

({"augmentation": "25"}, {"augmentation_factor": 25}),
],
)
def test_training_payload_from_yaml_core_arguments(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be more robust to test with an actual http request (e.g. like done in this test function). This has the advantange that the test focuses on the functionality and less on the specific implementation (_training_payload_from_yaml)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use monkeypatch to mock the actual training, you can test whether the parameters were passed correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! I think we can even delete this and the ones after this then.

Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few tiny comments 💯

def int_arg(
request: Request, key: Text, default: Optional[int] = None
) -> Optional[int]:
"""Return a passed argument cast as an int or None.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Minor comment: Could you please change Return to Returns? We try to use descriptive docstrings in the codebase.

async def test_train_with_yaml_with_params(
monkeypatch: MonkeyPatch,
rasa_app: SanicASGITestClient,
tmpdir: pathlib.Path,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tmpdir is of type LocalPath which is slightly different. I suggest using tmp_path

Suggested change
tmpdir: pathlib.Path,
tmp_path: pathlib.Path,

future = asyncio.Future()
future.set_result(TrainingResult(model=fake_model_path))
mock_train = Mock(return_value=future)
monkeypatch.setattr(sys.modules["rasa.train"], "train_async", mock_train)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we recently moved this:

Suggested change
monkeypatch.setattr(sys.modules["rasa.train"], "train_async", mock_train)
monkeypatch.setattr(rasa.model_training, "train_async", mock_train)

({"augmentation": "25"}, {"augmentation_factor": 25}),
],
)
def test_training_payload_from_yaml_core_arguments(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome! I think we can even delete this and the ones after this then.

@theanht1 theanht1 force-pushed the 4596-server-train-params branch from 24a0db3 to 7ff917f Compare March 20, 2021 05:22
Copy link
Contributor

@wochinge wochinge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

tests/test_server.py Outdated Show resolved Hide resolved
@wochinge wochinge enabled auto-merge March 22, 2021 20:41
@wochinge wochinge merged commit de34781 into RasaHQ:main Mar 22, 2021
@theanht1
Copy link
Contributor Author

Cool, thanks @wochinge, it's my pleasure to have contributions to this project

@theanht1 theanht1 deleted the 4596-server-train-params branch March 23, 2021 03:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants