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

Fix user ID always default on every shell session. #5117

Merged
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
08eda89
Fix user ID always default on every shell session.
VictorCoCo Jan 23, 2020
4eda4ed
add changelog record.
VictorCoCo Jan 26, 2020
7d093a8
Update rasa/core/channels/console.py
VictorCoCo Jan 26, 2020
984c702
Update rasa/core/channels/console.py
VictorCoCo Jan 26, 2020
1622793
Update rasa/core/channels/console.py
VictorCoCo Jan 26, 2020
0034e33
Update changelog/5117.improvement.rst
VictorCoCo Jan 26, 2020
a5b185c
Update changelog/5117.improvement.rst
VictorCoCo Jan 26, 2020
3dee8fd
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Jan 28, 2020
88a3c09
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Jan 29, 2020
cc2f1cc
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Jan 29, 2020
bf9945e
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Jan 30, 2020
a1351f5
Fix rasa core channels test.
VictorCoCo Jan 30, 2020
529c2e9
Add --sender-id argument to rasa shell.
VictorCoCo Feb 3, 2020
6c93b3f
Change sell --sender-id argument name to --conversation-id
VictorCoCo Feb 3, 2020
af2b561
Adjust rasa shell help test to changes.
VictorCoCo Feb 6, 2020
2f40740
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Feb 6, 2020
cc76148
Add new line at the end of rasa consts file.
VictorCoCo Feb 9, 2020
0bc6078
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Feb 9, 2020
368efe6
Remove unnecessary line at the end of the rasa constants.
VictorCoCo Feb 9, 2020
a148933
Fix channels test format.
VictorCoCo Feb 9, 2020
0397e4d
Reformat rasa cli shell.py
VictorCoCo Feb 9, 2020
dd52f11
Update rasa/cli/shell.py
VictorCoCo Feb 10, 2020
d0115ab
Update rasa/cli/shell.py
VictorCoCo Feb 10, 2020
c5fb40c
Change changelog record according to the new changes.
VictorCoCo Feb 10, 2020
ec6590e
Use const as default --conversation-id argument value.
VictorCoCo Feb 10, 2020
f50d0c0
Update rasa/core/channels/console.py
VictorCoCo Feb 10, 2020
b7ab04d
Update rasa/core/run.py
VictorCoCo Feb 10, 2020
cc5e7b7
Update rasa/core/run.py
VictorCoCo Feb 10, 2020
af501c7
Update rasa/core/run.py
VictorCoCo Feb 10, 2020
f01166c
Update rasa/core/run.py
VictorCoCo Feb 10, 2020
2104ec3
Update rasa/core/channels/console.py
VictorCoCo Feb 10, 2020
63fcf89
Fix unresolved reference for UserMessage.
VictorCoCo Feb 10, 2020
823379a
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Feb 11, 2020
d2454b0
Update changelog/5117.improvement.rst
VictorCoCo Feb 11, 2020
927a272
Update changelog/5117.improvement.rst
VictorCoCo Feb 11, 2020
bd38b69
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Feb 14, 2020
f4cd9e8
Merge branch 'master' into fix-user-id-always-default-on-shell-session
ricwo Feb 18, 2020
32be2b3
Merge branch 'master' into fix-user-id-always-default-on-shell-session
tmbo Feb 21, 2020
ecf01b6
Change --coversation-id to be random by default.
VictorCoCo Feb 23, 2020
ea75052
Add conversation_id arg to interactive test.
VictorCoCo Feb 23, 2020
b1d32cb
Add default conversation id value on core.run functions.
VictorCoCo Feb 23, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog/5117.improvement.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
New command-line argument --conversation-id will be added and wiil give the ability to
set custom conversation ID for each shell session.
11 changes: 10 additions & 1 deletion rasa/cli/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from rasa.cli.arguments import shell as arguments
from rasa.cli.utils import print_error
from rasa.exceptions import ModelNotFound

from rasa.constants import DEFAULT_SENDER_ID

logger = logging.getLogger(__name__)

Expand All @@ -26,14 +26,23 @@ def add_subparser(
)
shell_parser.set_defaults(func=shell)

shell_parser.add_argument(
"--conversation-id",
default=DEFAULT_SENDER_ID,
required=False,
help="Set the conversation ID.",
)

run_subparsers = shell_parser.add_subparsers()

shell_nlu_subparser = run_subparsers.add_parser(
"nlu",
parents=parents,
conflict_handler="resolve",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
help="Interprets messages on the command line using your NLU model.",
)

shell_nlu_subparser.set_defaults(func=shell_nlu)

arguments.set_shell_arguments(shell_parser)
Expand Down
2 changes: 2 additions & 0 deletions rasa/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,5 @@

DEFAULT_SESSION_EXPIRATION_TIME_IN_MINUTES = 60
DEFAULT_CARRY_OVER_SLOTS_TO_NEW_SESSION = True

DEFAULT_SENDER_ID = "default"
Copy link
Contributor

Choose a reason for hiding this comment

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

@ricwo Would it be better to default to generating a random ID when rasa shell is called instead of fixing it here as a constant?

The reason for this suggestion is: If you have a persistent tracker store and run rasa shell, you would want to start from scratch with a new conversation id and not at whichever state the last session with a default id was in.
(We were also discussing that in the PR that adds such an argument for rasa interactive: #5243.)

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 agree, It was the way I first changed it. @ricwo @erohmensing I am ok with changing it, What is your opinion?

Copy link
Contributor

Choose a reason for hiding this comment

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

@chkoss yes but this is a separate functionality and should probably be controlled with a different command-line argument, something like --assign-random-conversation-id

@VictorCoCo your initial implementation assigned a random user ID with every new shell session, and made it impossible to use a deterministic one. being able to define a conversation ID as a command-line argument and having the script choose a random one are two separate issues. whatever the default behaviour, there needs to remain the possibility of a deterministic conversation ID

4 changes: 2 additions & 2 deletions rasa/core/channels/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

from rasa.cli import utils as cli_utils
from rasa.core import utils
from rasa.constants import DEFAULT_SENDER_ID
from rasa.core.channels.channel import RestInput
from rasa.core.channels.channel import UserMessage
from rasa.core.constants import DEFAULT_SERVER_URL
from rasa.core.interpreter import INTENT_MESSAGE_PREFIX
from rasa.utils.io import DEFAULT_ENCODING
Expand Down Expand Up @@ -111,7 +111,7 @@ async def send_message_receive_stream(
async def record_messages(
server_url=DEFAULT_SERVER_URL,
auth_token="",
sender_id=UserMessage.DEFAULT_SENDER_ID,
sender_id=DEFAULT_SENDER_ID,
max_message_limit=None,
use_response_stream=True,
) -> int:
Expand Down
8 changes: 6 additions & 2 deletions rasa/core/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import rasa.utils.common
import rasa.utils.io
from rasa import model, server
from rasa.constants import ENV_SANIC_BACKLOG
from rasa.constants import ENV_SANIC_BACKLOG, DEFAULT_SENDER_ID
from rasa.core import agent, channels, constants
from rasa.core.agent import Agent
from rasa.core.brokers.broker import EventBroker
Expand Down Expand Up @@ -87,6 +87,7 @@ def configure_app(
port: int = constants.DEFAULT_SERVER_PORT,
endpoints: Optional[AvailableEndpoints] = None,
log_file: Optional[Text] = None,
conversation_id: Optional[Text] = DEFAULT_SENDER_ID,
):
"""Run the agent."""
from rasa import server
Expand Down Expand Up @@ -125,7 +126,8 @@ async def run_cmdline_io(running_app: Sanic):
"""Small wrapper to shut down the server once cmd io is done."""
await asyncio.sleep(1) # allow server to start
await console.record_messages(
server_url=constants.DEFAULT_SERVER_FORMAT.format("http", port)
server_url=constants.DEFAULT_SERVER_FORMAT.format("http", port),
sender_id=conversation_id,
)

logger.info("Killing Sanic server now.")
Expand Down Expand Up @@ -153,6 +155,7 @@ def serve_application(
ssl_keyfile: Optional[Text] = None,
ssl_ca_file: Optional[Text] = None,
ssl_password: Optional[Text] = None,
conversation_id: Optional[Text] = DEFAULT_SENDER_ID,
):
from rasa import server

Expand All @@ -171,6 +174,7 @@ def serve_application(
port=port,
endpoints=endpoints,
log_file=log_file,
conversation_id=conversation_id,
)

ssl_context = server.create_ssl_context(
Expand Down
7 changes: 4 additions & 3 deletions tests/cli/test_rasa_shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
def test_shell_help(run: Callable[..., RunResult]):
output = run("shell", "--help")

help_text = """usage: rasa shell [-h] [-v] [-vv] [--quiet] [-m MODEL] [--log-file LOG_FILE]
[--endpoints ENDPOINTS] [-p PORT] [-t AUTH_TOKEN]
[--cors [CORS [CORS ...]]] [--enable-api]
help_text = """usage: rasa shell [-h] [-v] [-vv] [--quiet]
[--conversation-id CONVERSATION_ID] [-m MODEL]
[--log-file LOG_FILE] [--endpoints ENDPOINTS] [-p PORT]
[-t AUTH_TOKEN] [--cors [CORS [CORS ...]]] [--enable-api]
[--remote-storage REMOTE_STORAGE]
[--ssl-certificate SSL_CERTIFICATE]
[--ssl-keyfile SSL_KEYFILE] [--ssl-ca-file SSL_CA_FILE]
Expand Down
4 changes: 3 additions & 1 deletion tests/core/test_channels.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ async def test_console_input():
)

await console.record_messages(
server_url="https://example.com", max_message_limit=3
server_url="https://example.com",
max_message_limit=3,
sender_id="default",
)

r = latest_request(
Expand Down