diff --git a/README.md b/README.md index 01cc1d550..2afa8b3ae 100644 --- a/README.md +++ b/README.md @@ -87,13 +87,13 @@ import dff.script.conditions.std_conditions as cnd script = { GLOBAL: { TRANSITIONS: { - ("flow", "node_hi"): cnd.exact_match(Message(text="Hi")), + ("flow", "node_hi"): cnd.exact_match(Message("Hi")), ("flow", "node_ok"): cnd.true() } }, "flow": { - "node_hi": {RESPONSE: Message(text="Hi!")}, - "node_ok": {RESPONSE: Message(text="OK")}, + "node_hi": {RESPONSE: Message("Hi!")}, + "node_ok": {RESPONSE: Message("OK")}, }, } @@ -112,7 +112,7 @@ def turn_handler(in_request: Message, pipeline: Pipeline) -> Message: while True: in_request = input("Your message: ") - out_response = turn_handler(Message(text=in_request), pipeline) + out_response = turn_handler(Message(in_request), pipeline) print("Response: ", out_response.text) ``` diff --git a/dff/messengers/common/interface.py b/dff/messengers/common/interface.py index 13747b06c..ce6a506f6 100644 --- a/dff/messengers/common/interface.py +++ b/dff/messengers/common/interface.py @@ -164,7 +164,7 @@ def __init__( self._descriptor: Optional[TextIO] = out_descriptor def _request(self) -> List[Tuple[Message, Any]]: - return [(Message(text=input(self._prompt_request)), self._ctx_id)] + return [(Message(input(self._prompt_request)), self._ctx_id)] def _respond(self, responses: List[Context]): print(f"{self._prompt_response}{responses[0].last_response.text}", file=self._descriptor) diff --git a/dff/pipeline/pipeline/actor.py b/dff/pipeline/pipeline/actor.py index f62daabbf..fdddf542a 100644 --- a/dff/pipeline/pipeline/actor.py +++ b/dff/pipeline/pipeline/actor.py @@ -405,7 +405,7 @@ def validate_script(self, pipeline: Pipeline, verbose: bool = True): for flow_label, node_label, label, condition in zip(flow_labels, node_labels, labels, conditions): ctx = Context() ctx.validation = True - ctx.add_request(Message(text="text")) + ctx.add_request(Message("text")) label = label(ctx, pipeline) if callable(label) else normalize_label(label, flow_label) diff --git a/dff/script/core/message.py b/dff/script/core/message.py index 05f9974f9..9f530968b 100644 --- a/dff/script/core/message.py +++ b/dff/script/core/message.py @@ -200,6 +200,18 @@ class level variables to store message information. # state: Optional[Session] = Session.ACTIVE # ui: Optional[Union[Keyboard, DataModel]] = None + def __init__( + self, + text: Optional[str] = None, + commands: Optional[List[Command]] = None, + attachments: Optional[Attachments] = None, + annotations: Optional[dict] = None, + misc: Optional[dict] = None, + ): + super().__init__( + text=text, commands=commands, attachments=attachments, annotations=annotations, misc=misc + ) + def __eq__(self, other): if isinstance(other, Message): for field in self.model_fields: diff --git a/dff/utils/testing/common.py b/dff/utils/testing/common.py index b54bce9fe..607e7cda2 100644 --- a/dff/utils/testing/common.py +++ b/dff/utils/testing/common.py @@ -89,5 +89,5 @@ def run_interactive_mode(pipeline: Pipeline): # pragma: no cover print("Start a dialogue with the bot") while True: request = input(">>> ") - ctx = pipeline(request=Message(text=request), ctx_id=ctx_id) + ctx = pipeline(request=Message(request), ctx_id=ctx_id) print(f"<<< {repr(ctx.last_response)}") diff --git a/dff/utils/testing/toy_script.py b/dff/utils/testing/toy_script.py index f035df047..27e7f94be 100644 --- a/dff/utils/testing/toy_script.py +++ b/dff/utils/testing/toy_script.py @@ -11,24 +11,24 @@ "greeting_flow": { "start_node": { RESPONSE: Message(), - TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": exact_match(Message("Hi"))}, }, "node1": { - RESPONSE: Message(text="Hi, how are you?"), - TRANSITIONS: {"node2": exact_match(Message(text="i'm fine, how are you?"))}, + RESPONSE: Message("Hi, how are you?"), + TRANSITIONS: {"node2": exact_match(Message("i'm fine, how are you?"))}, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), - TRANSITIONS: {"node3": exact_match(Message(text="Let's talk about music."))}, + RESPONSE: Message("Good. What do you want to talk about?"), + TRANSITIONS: {"node3": exact_match(Message("Let's talk about music."))}, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about music now."), - TRANSITIONS: {"node4": exact_match(Message(text="Ok, goodbye."))}, + RESPONSE: Message("Sorry, I can not talk about music now."), + TRANSITIONS: {"node4": exact_match(Message("Ok, goodbye."))}, }, - "node4": {RESPONSE: Message(text="bye"), TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}}, + "node4": {RESPONSE: Message("bye"), TRANSITIONS: {"node1": exact_match(Message("Hi"))}}, "fallback_node": { - RESPONSE: Message(text="Ooops"), - TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}, + RESPONSE: Message("Ooops"), + TRANSITIONS: {"node1": exact_match(Message("Hi"))}, }, } } @@ -51,11 +51,11 @@ """ HAPPY_PATH = ( - (Message(text="Hi"), Message(text="Hi, how are you?")), - (Message(text="i'm fine, how are you?"), Message(text="Good. What do you want to talk about?")), - (Message(text="Let's talk about music."), Message(text="Sorry, I can not talk about music now.")), - (Message(text="Ok, goodbye."), Message(text="bye")), - (Message(text="Hi"), Message(text="Hi, how are you?")), + (Message("Hi"), Message("Hi, how are you?")), + (Message("i'm fine, how are you?"), Message("Good. What do you want to talk about?")), + (Message("Let's talk about music."), Message("Sorry, I can not talk about music now.")), + (Message("Ok, goodbye."), Message("bye")), + (Message("Hi"), Message("Hi, how are you?")), ) """ An example of a simple dialog. @@ -66,97 +66,97 @@ MULTIFLOW_SCRIPT = { "root": { "start": { - RESPONSE: Message(text="Hi"), + RESPONSE: Message("Hi"), TRANSITIONS: { - ("small_talk", "ask_some_questions"): exact_match(Message(text="hi")), - ("animals", "have_pets"): exact_match(Message(text="i like animals")), - ("animals", "like_animals"): exact_match(Message(text="let's talk about animals")), - ("news", "what_news"): exact_match(Message(text="let's talk about news")), + ("small_talk", "ask_some_questions"): exact_match(Message("hi")), + ("animals", "have_pets"): exact_match(Message("i like animals")), + ("animals", "like_animals"): exact_match(Message("let's talk about animals")), + ("news", "what_news"): exact_match(Message("let's talk about news")), }, }, - "fallback": {RESPONSE: Message(text="Oops")}, + "fallback": {RESPONSE: Message("Oops")}, }, "animals": { "have_pets": { - RESPONSE: Message(text="do you have pets?"), - TRANSITIONS: {"what_animal": exact_match(Message(text="yes"))}, + RESPONSE: Message("do you have pets?"), + TRANSITIONS: {"what_animal": exact_match(Message("yes"))}, }, "like_animals": { - RESPONSE: Message(text="do you like it?"), - TRANSITIONS: {"what_animal": exact_match(Message(text="yes"))}, + RESPONSE: Message("do you like it?"), + TRANSITIONS: {"what_animal": exact_match(Message("yes"))}, }, "what_animal": { - RESPONSE: Message(text="what animals do you have?"), + RESPONSE: Message("what animals do you have?"), TRANSITIONS: { - "ask_about_color": exact_match(Message(text="bird")), - "ask_about_breed": exact_match(Message(text="dog")), + "ask_about_color": exact_match(Message("bird")), + "ask_about_breed": exact_match(Message("dog")), }, }, - "ask_about_color": {RESPONSE: Message(text="what color is it")}, + "ask_about_color": {RESPONSE: Message("what color is it")}, "ask_about_breed": { - RESPONSE: Message(text="what is this breed?"), + RESPONSE: Message("what is this breed?"), TRANSITIONS: { - "ask_about_breed": exact_match(Message(text="pereat")), - "tell_fact_about_breed": exact_match(Message(text="bulldog")), - "ask_about_training": exact_match(Message(text="I don't know")), + "ask_about_breed": exact_match(Message("pereat")), + "tell_fact_about_breed": exact_match(Message("bulldog")), + "ask_about_training": exact_match(Message("I don't know")), }, }, "tell_fact_about_breed": { - RESPONSE: Message(text="Bulldogs appeared in England as specialized bull-baiting dogs. "), + RESPONSE: Message("Bulldogs appeared in England as specialized bull-baiting dogs. "), }, - "ask_about_training": {RESPONSE: Message(text="Do you train your dog? ")}, + "ask_about_training": {RESPONSE: Message("Do you train your dog? ")}, }, "news": { "what_news": { - RESPONSE: Message(text="what kind of news do you prefer?"), + RESPONSE: Message("what kind of news do you prefer?"), TRANSITIONS: { - "ask_about_science": exact_match(Message(text="science")), - "ask_about_sport": exact_match(Message(text="sport")), + "ask_about_science": exact_match(Message("science")), + "ask_about_sport": exact_match(Message("sport")), }, }, "ask_about_science": { - RESPONSE: Message(text="i got news about science, do you want to hear?"), + RESPONSE: Message("i got news about science, do you want to hear?"), TRANSITIONS: { - "science_news": exact_match(Message(text="yes")), - ("small_talk", "ask_some_questions"): exact_match(Message(text="let's change the topic")), + "science_news": exact_match(Message("yes")), + ("small_talk", "ask_some_questions"): exact_match(Message("let's change the topic")), }, }, "science_news": { - RESPONSE: Message(text="This is science news"), + RESPONSE: Message("This is science news"), TRANSITIONS: { - "what_news": exact_match(Message(text="ok")), - ("small_talk", "ask_some_questions"): exact_match(Message(text="let's change the topic")), + "what_news": exact_match(Message("ok")), + ("small_talk", "ask_some_questions"): exact_match(Message("let's change the topic")), }, }, "ask_about_sport": { - RESPONSE: Message(text="i got news about sport, do you want to hear?"), + RESPONSE: Message("i got news about sport, do you want to hear?"), TRANSITIONS: { - "sport_news": exact_match(Message(text="yes")), - ("small_talk", "ask_some_questions"): exact_match(Message(text="let's change the topic")), + "sport_news": exact_match(Message("yes")), + ("small_talk", "ask_some_questions"): exact_match(Message("let's change the topic")), }, }, "sport_news": { - RESPONSE: Message(text="This is sport news"), + RESPONSE: Message("This is sport news"), TRANSITIONS: { - "what_news": exact_match(Message(text="ok")), - ("small_talk", "ask_some_questions"): exact_match(Message(text="let's change the topic")), + "what_news": exact_match(Message("ok")), + ("small_talk", "ask_some_questions"): exact_match(Message("let's change the topic")), }, }, }, "small_talk": { "ask_some_questions": { - RESPONSE: Message(text="how are you"), + RESPONSE: Message("how are you"), TRANSITIONS: { - "ask_talk_about": exact_match(Message(text="fine")), - ("animals", "like_animals"): exact_match(Message(text="let's talk about animals")), - ("news", "what_news"): exact_match(Message(text="let's talk about news")), + "ask_talk_about": exact_match(Message("fine")), + ("animals", "like_animals"): exact_match(Message("let's talk about animals")), + ("news", "what_news"): exact_match(Message("let's talk about news")), }, }, "ask_talk_about": { - RESPONSE: Message(text="what do you want to talk about"), + RESPONSE: Message("what do you want to talk about"), TRANSITIONS: { - ("animals", "like_animals"): exact_match(Message(text="dog")), - ("news", "what_news"): exact_match(Message(text="let's talk about news")), + ("animals", "like_animals"): exact_match(Message("dog")), + ("news", "what_news"): exact_match(Message("let's talk about news")), }, }, }, diff --git a/docs/source/user_guides/basic_conceptions.rst b/docs/source/user_guides/basic_conceptions.rst index bdcab9c61..515b4ff49 100644 --- a/docs/source/user_guides/basic_conceptions.rst +++ b/docs/source/user_guides/basic_conceptions.rst @@ -89,14 +89,14 @@ Example flow & script RESPONSE: Message(), # the response of the initial node is skipped TRANSITIONS: { ("greeting_flow", "greeting_node"): - cnd.exact_match(Message(text="/start")), + cnd.exact_match(Message("/start")), }, }, "greeting_node": { - RESPONSE: Message(text="Hi!"), + RESPONSE: Message("Hi!"), TRANSITIONS: { ("ping_pong_flow", "game_start_node"): - cnd.exact_match(Message(text="Hello!")) + cnd.exact_match(Message("Hello!")) } }, "fallback_node": { @@ -108,17 +108,17 @@ Example flow & script }, "ping_pong_flow": { "game_start_node": { - RESPONSE: Message(text="Let's play ping-pong!"), + RESPONSE: Message("Let's play ping-pong!"), TRANSITIONS: { ("ping_pong_flow", "response_node"): - cnd.exact_match(Message(text="Ping!")), + cnd.exact_match(Message("Ping!")), }, }, "response_node": { - RESPONSE: Message(text="Pong!"), + RESPONSE: Message("Pong!"), TRANSITIONS: { ("ping_pong_flow", "response_node"): - cnd.exact_match(Message(text="Ping!")), + cnd.exact_match(Message("Ping!")), }, }, }, @@ -240,8 +240,8 @@ The latter allows you to customize the response based on the specific scenario a def sample_response(ctx: Context, _: Pipeline) -> Message: if ctx.misc["user"] == 'vegan': - return Message(text="Here is a list of vegan cafes.") - return Message(text="Here is a list of cafes.") + return Message("Here is a list of vegan cafes.") + return Message("Here is a list of cafes.") Handling Fallbacks ================== @@ -265,7 +265,7 @@ This ensures a smoother user experience even when the bot encounters unexpected if ctx.last_request is not None: if ctx.last_request.text != "/start" and ctx.last_label is None: # an empty last_label indicates start_node - return Message(text="You should've started the dialog with '/start'") + return Message("You should've started the dialog with '/start'") else: return Message( text=f"That was against the rules!\n" @@ -289,9 +289,9 @@ conversational service. .. code-block:: python happy_path = ( - (Message(text="/start"), Message(text="Hi!")), - (Message(text="Hello!"), Message(text="Let's play ping-pong!")), - (Message(text="Ping!"), Message(text="Pong!")) + (Message("/start"), Message("Hi!")), + (Message("Hello!"), Message("Let's play ping-pong!")), + (Message("Ping!"), Message("Pong!")) ) A special function is then used to ascertain complete identity of the messages taken from diff --git a/tests/messengers/telegram/test_types.py b/tests/messengers/telegram/test_types.py index cc50ae558..e5ecb184e 100644 --- a/tests/messengers/telegram/test_types.py +++ b/tests/messengers/telegram/test_types.py @@ -116,7 +116,7 @@ async def test_keyboard_remove(pipeline_instance, api_credentials, bot_user, ses attachments=Attachments(files=[video]), ), ), - (Message(text="test", attachments=Attachments(files=[document])),), + (Message("test", attachments=Attachments(files=[document])),), ], ) @pytest.mark.telegram @@ -150,7 +150,7 @@ async def test_telegram_attachment(generic_response, pipeline_instance, api_cred attachments=Attachments(files=2 * [video]), ), ), - (Message(text="test", attachments=Attachments(files=2 * [document])),), + (Message("test", attachments=Attachments(files=2 * [document])),), ], ) @pytest.mark.telegram diff --git a/tests/pipeline/test_messenger_interface.py b/tests/pipeline/test_messenger_interface.py index 8fd51aeb2..855efeb96 100644 --- a/tests/pipeline/test_messenger_interface.py +++ b/tests/pipeline/test_messenger_interface.py @@ -13,19 +13,19 @@ RESPONSE: { "text": "", }, - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Ping"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Ping"))}, }, "node1": { RESPONSE: { "text": "Pong", }, - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Ping"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Ping"))}, }, "fallback_node": { RESPONSE: { "text": "Ooops", }, - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Ping"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Ping"))}, }, } } @@ -60,4 +60,4 @@ def test_callback_messenger_interface(monkeypatch): pipeline.run() for _ in range(0, 5): - assert interface.on_request(Message(text="Ping"), 0).last_response == Message(text="Pong") + assert interface.on_request(Message("Ping"), 0).last_response == Message("Pong") diff --git a/tests/pipeline/test_parallel_processing.py b/tests/pipeline/test_parallel_processing.py index 2e2e5beb3..02f6349f6 100644 --- a/tests/pipeline/test_parallel_processing.py +++ b/tests/pipeline/test_parallel_processing.py @@ -11,12 +11,12 @@ async def test_parallel_processing(): async def fast_processing(ctx, _): processed_node = ctx.current_node await asyncio.sleep(1) - processed_node.response = Message(text=f"fast: {processed_node.response.text}") + processed_node.response = Message(f"fast: {processed_node.response.text}") async def slow_processing(ctx, _): processed_node = ctx.current_node await asyncio.sleep(2) - processed_node.response = Message(text=f"slow: {processed_node.response.text}") + processed_node.response = Message(f"slow: {processed_node.response.text}") toy_script = { GLOBAL: { @@ -25,7 +25,7 @@ async def slow_processing(ctx, _): "second": fast_processing, } }, - "root": {"start": {TRANSITIONS: {"main": cnd.true()}}, "main": {RESPONSE: Message(text="text")}}, + "root": {"start": {TRANSITIONS: {"main": cnd.true()}}, "main": {RESPONSE: Message("text")}}, } # test sequential processing diff --git a/tests/pipeline/test_update_ctx_misc.py b/tests/pipeline/test_update_ctx_misc.py index e1d5dd046..81803860b 100644 --- a/tests/pipeline/test_update_ctx_misc.py +++ b/tests/pipeline/test_update_ctx_misc.py @@ -12,9 +12,9 @@ def condition(ctx, _): toy_script = { "root": { "start": {TRANSITIONS: {"success": condition}}, - "success": {RESPONSE: Message(text="success"), TRANSITIONS: {"success": condition}}, + "success": {RESPONSE: Message("success"), TRANSITIONS: {"success": condition}}, "failure": { - RESPONSE: Message(text="failure"), + RESPONSE: Message("failure"), }, } } diff --git a/tests/script/conditions/test_conditions.py b/tests/script/conditions/test_conditions.py index d8087d0e2..c56e4aa39 100644 --- a/tests/script/conditions/test_conditions.py +++ b/tests/script/conditions/test_conditions.py @@ -7,17 +7,17 @@ def test_conditions(): label = ("flow", "node") ctx = Context() - ctx.add_request(Message(text="text", misc={})) + ctx.add_request(Message("text", misc={})) ctx.add_label(label) failed_ctx = Context() failed_ctx.add_request(Message()) failed_ctx.add_label(label) pipeline = Pipeline.from_script(script={"flow": {"node": {}}}, start_label=("flow", "node")) - assert cnd.exact_match(Message(text="text"))(ctx, pipeline) - assert cnd.exact_match(Message(text="text", misc={}))(ctx, pipeline) - assert not cnd.exact_match(Message(text="text", misc={1: 1}))(ctx, pipeline) - assert not cnd.exact_match(Message(text="text1"))(ctx, pipeline) + assert cnd.exact_match(Message("text"))(ctx, pipeline) + assert cnd.exact_match(Message("text", misc={}))(ctx, pipeline) + assert not cnd.exact_match(Message("text", misc={1: 1}))(ctx, pipeline) + assert not cnd.exact_match(Message("text1"))(ctx, pipeline) assert cnd.exact_match(Message())(ctx, pipeline) assert not cnd.exact_match(Message(), skip_none=False)(ctx, pipeline) @@ -25,17 +25,17 @@ def test_conditions(): assert not cnd.regexp("t.*t1")(ctx, pipeline) assert not cnd.regexp("t.*t1")(failed_ctx, pipeline) - assert cnd.agg([cnd.regexp("t.*t"), cnd.exact_match(Message(text="text"))], aggregate_func=all)(ctx, pipeline) - assert not cnd.agg([cnd.regexp("t.*t1"), cnd.exact_match(Message(text="text"))], aggregate_func=all)(ctx, pipeline) + assert cnd.agg([cnd.regexp("t.*t"), cnd.exact_match(Message("text"))], aggregate_func=all)(ctx, pipeline) + assert not cnd.agg([cnd.regexp("t.*t1"), cnd.exact_match(Message("text"))], aggregate_func=all)(ctx, pipeline) - assert cnd.any([cnd.regexp("t.*t1"), cnd.exact_match(Message(text="text"))])(ctx, pipeline) - assert not cnd.any([cnd.regexp("t.*t1"), cnd.exact_match(Message(text="text1"))])(ctx, pipeline) + assert cnd.any([cnd.regexp("t.*t1"), cnd.exact_match(Message("text"))])(ctx, pipeline) + assert not cnd.any([cnd.regexp("t.*t1"), cnd.exact_match(Message("text1"))])(ctx, pipeline) - assert cnd.all([cnd.regexp("t.*t"), cnd.exact_match(Message(text="text"))])(ctx, pipeline) - assert not cnd.all([cnd.regexp("t.*t1"), cnd.exact_match(Message(text="text"))])(ctx, pipeline) + assert cnd.all([cnd.regexp("t.*t"), cnd.exact_match(Message("text"))])(ctx, pipeline) + assert not cnd.all([cnd.regexp("t.*t1"), cnd.exact_match(Message("text"))])(ctx, pipeline) - assert cnd.neg(cnd.exact_match(Message(text="text1")))(ctx, pipeline) - assert not cnd.neg(cnd.exact_match(Message(text="text")))(ctx, pipeline) + assert cnd.neg(cnd.exact_match(Message("text1")))(ctx, pipeline) + assert not cnd.neg(cnd.exact_match(Message("text")))(ctx, pipeline) assert cnd.has_last_labels(flow_labels=["flow"])(ctx, pipeline) assert not cnd.has_last_labels(flow_labels=["flow1"])(ctx, pipeline) diff --git a/tests/script/core/test_actor.py b/tests/script/core/test_actor.py index 265ff9f08..362ec0719 100644 --- a/tests/script/core/test_actor.py +++ b/tests/script/core/test_actor.py @@ -151,7 +151,7 @@ async def test_call_limit(): PRE_RESPONSE_PROCESSING: {"rpl": check_call_limit(3, "ctx", "rpl")}, }, "node1": { - RESPONSE: check_call_limit(1, Message(text="r1"), "flow1_node1"), + RESPONSE: check_call_limit(1, Message("r1"), "flow1_node1"), PRE_TRANSITIONS_PROCESSING: {"tp1": check_call_limit(1, "ctx", "flow1_node1_tp1")}, TRANSITIONS: { check_call_limit(1, ("flow1", "node2"), "cond flow1_node2"): check_call_limit( @@ -163,7 +163,7 @@ async def test_call_limit(): PRE_RESPONSE_PROCESSING: {"rp1": check_call_limit(1, "ctx", "flow1_node1_rp1")}, }, "node2": { - RESPONSE: check_call_limit(1, Message(text="r1"), "flow1_node2"), + RESPONSE: check_call_limit(1, Message("r1"), "flow1_node2"), PRE_TRANSITIONS_PROCESSING: {"tp1": check_call_limit(1, "ctx", "flow1_node2_tp1")}, TRANSITIONS: { check_call_limit(1, ("flow2", "node1"), "cond flow2_node1"): check_call_limit( @@ -186,7 +186,7 @@ async def test_call_limit(): PRE_RESPONSE_PROCESSING: {"rpl": check_call_limit(2, "ctx", "rpl")}, }, "node1": { - RESPONSE: check_call_limit(1, Message(text="r1"), "flow2_node1"), + RESPONSE: check_call_limit(1, Message("r1"), "flow2_node1"), PRE_TRANSITIONS_PROCESSING: {"tp1": check_call_limit(1, "ctx", "flow2_node1_tp1")}, TRANSITIONS: { check_call_limit(1, ("flow2", "node2"), "label flow2_node2"): check_call_limit( @@ -198,7 +198,7 @@ async def test_call_limit(): PRE_RESPONSE_PROCESSING: {"rp1": check_call_limit(1, "ctx", "flow2_node1_rp1")}, }, "node2": { - RESPONSE: check_call_limit(1, Message(text="r1"), "flow2_node2"), + RESPONSE: check_call_limit(1, Message("r1"), "flow2_node2"), PRE_TRANSITIONS_PROCESSING: {"tp1": check_call_limit(1, "ctx", "flow2_node2_tp1")}, TRANSITIONS: { check_call_limit(1, ("flow1", "node1"), "label flow2_node2"): check_call_limit( @@ -214,7 +214,7 @@ async def test_call_limit(): # script = {"flow": {"node1": {TRANSITIONS: {"node1": true()}}}} pipeline = Pipeline.from_script(script=script, start_label=("flow1", "node1"), validation_stage=False) for i in range(4): - await pipeline._run_pipeline(Message(text="req1"), 0) + await pipeline._run_pipeline(Message("req1"), 0) if limit_errors: error_msg = repr(limit_errors) raise Exception(error_msg) diff --git a/tests/script/core/test_context.py b/tests/script/core/test_context.py index f86182afd..1910ded2c 100644 --- a/tests/script/core/test_context.py +++ b/tests/script/core/test_context.py @@ -11,9 +11,9 @@ def shuffle_dict_keys(dictionary: dict) -> dict: def test_context(): ctx = Context() for index in range(0, 30, 2): - ctx.add_request(Message(text=str(index))) + ctx.add_request(Message(str(index))) ctx.add_label((str(index), str(index + 1))) - ctx.add_response(Message(text=str(index + 1))) + ctx.add_response(Message(str(index + 1))) ctx.labels = shuffle_dict_keys(ctx.labels) ctx.requests = shuffle_dict_keys(ctx.requests) ctx.responses = shuffle_dict_keys(ctx.responses) @@ -21,9 +21,9 @@ def test_context(): ctx.misc[123] = 312 ctx.clear(5, ["requests", "responses", "misc", "labels", "framework_states"]) ctx.misc["1001"] = "11111" - ctx.add_request(Message(text=str(1000))) + ctx.add_request(Message(str(1000))) ctx.add_label((str(1000), str(1000 + 1))) - ctx.add_response(Message(text=str(1000 + 1))) + ctx.add_response(Message(str(1000 + 1))) assert ctx.labels == { 10: ("20", "21"), @@ -34,20 +34,20 @@ def test_context(): 15: ("1000", "1001"), } assert ctx.requests == { - 10: Message(text="20"), - 11: Message(text="22"), - 12: Message(text="24"), - 13: Message(text="26"), - 14: Message(text="28"), - 15: Message(text="1000"), + 10: Message("20"), + 11: Message("22"), + 12: Message("24"), + 13: Message("26"), + 14: Message("28"), + 15: Message("1000"), } assert ctx.responses == { - 10: Message(text="21"), - 11: Message(text="23"), - 12: Message(text="25"), - 13: Message(text="27"), - 14: Message(text="29"), - 15: Message(text="1001"), + 10: Message("21"), + 11: Message("23"), + 12: Message("25"), + 13: Message("27"), + 14: Message("29"), + 15: Message("1001"), } assert ctx.misc == {"1001": "11111"} assert ctx.current_node is None diff --git a/tests/script/core/test_normalization.py b/tests/script/core/test_normalization.py index 9fc1c1244..fc871b889 100644 --- a/tests/script/core/test_normalization.py +++ b/tests/script/core/test_normalization.py @@ -27,9 +27,9 @@ def std_func(ctx, pipeline): def create_env() -> Tuple[Context, Pipeline]: ctx = Context() - script = {"flow": {"node1": {TRANSITIONS: {repeat(): true()}, RESPONSE: Message(text="response")}}} + script = {"flow": {"node1": {TRANSITIONS: {repeat(): true()}, RESPONSE: Message("response")}}} pipeline = Pipeline.from_script(script=script, start_label=("flow", "node1"), fallback_label=("flow", "node1")) - ctx.add_request(Message(text="text")) + ctx.add_request(Message("text")) return ctx, pipeline @@ -82,20 +82,20 @@ def test_normalize_transitions(): def test_normalize_response(): assert callable(normalize_response(std_func)) - assert callable(normalize_response(Message(text="text"))) + assert callable(normalize_response(Message("text"))) def test_normalize_keywords(): node_template = { TRANSITIONS: {"node": std_func}, - RESPONSE: Message(text="text"), + RESPONSE: Message("text"), PRE_RESPONSE_PROCESSING: {1: std_func}, PRE_TRANSITIONS_PROCESSING: {1: std_func}, MISC: {"key": "val"}, } node_template_gold = { TRANSITIONS.name.lower(): {"node": std_func}, - RESPONSE.name.lower(): Message(text="text"), + RESPONSE.name.lower(): Message("text"), PRE_RESPONSE_PROCESSING.name.lower(): {1: std_func}, PRE_TRANSITIONS_PROCESSING.name.lower(): {1: std_func}, MISC.name.lower(): {"key": "val"}, @@ -109,14 +109,14 @@ def test_normalize_script(): # TODO: Add full check for functions node_template = { TRANSITIONS: {"node": std_func}, - RESPONSE: Message(text="text"), + RESPONSE: Message("text"), PRE_RESPONSE_PROCESSING: {1: std_func}, PRE_TRANSITIONS_PROCESSING: {1: std_func}, MISC: {"key": "val"}, } node_template_gold = { TRANSITIONS.name.lower(): {"node": std_func}, - RESPONSE.name.lower(): Message(text="text"), + RESPONSE.name.lower(): Message("text"), PRE_RESPONSE_PROCESSING.name.lower(): {1: std_func}, PRE_TRANSITIONS_PROCESSING.name.lower(): {1: std_func}, MISC.name.lower(): {"key": "val"}, diff --git a/tests/script/core/test_script.py b/tests/script/core/test_script.py index 87d82f863..72f6a0175 100644 --- a/tests/script/core/test_script.py +++ b/tests/script/core/test_script.py @@ -46,7 +46,7 @@ def node_creation(pre_response_proc): samples = { "transition": [std_func, "node", ("flow", "node"), ("node", 2.0), ("flow", "node", 2.0)], "condition": [std_func], - RESPONSE.name.lower(): [Message(text="text"), std_func, None], + RESPONSE.name.lower(): [Message("text"), std_func, None], pre_response_proc.name.lower(): [{}, {1: std_func}, None], PRE_TRANSITIONS_PROCESSING.name.lower(): [{}, {1: std_func}, None], MISC.name.lower(): [{}, {1: "var"}, None], @@ -110,7 +110,7 @@ def test_node_exec(): node = Node( **{ TRANSITIONS.name.lower(): {"node": std_func}, - RESPONSE.name.lower(): Message(text="text"), + RESPONSE.name.lower(): Message("text"), PRE_RESPONSE_PROCESSING.name.lower(): {1: std_func}, PRE_TRANSITIONS_PROCESSING.name.lower(): {1: std_func}, MISC.name.lower(): {"key": "val"}, @@ -126,7 +126,7 @@ def test_script(): def script_test(pre_response_proc): node_template = { TRANSITIONS: {"node": std_func}, - RESPONSE: Message(text="text"), + RESPONSE: Message("text"), pre_response_proc: {1: std_func}, PRE_TRANSITIONS_PROCESSING: {1: std_func}, MISC: {"key": "val"}, diff --git a/tests/tutorials/test_utils.py b/tests/tutorials/test_utils.py index 8587eb2d2..2ed14aa6b 100644 --- a/tests/tutorials/test_utils.py +++ b/tests/tutorials/test_utils.py @@ -9,7 +9,7 @@ def test_unhappy_path(): with pytest.raises(Exception) as e: - check_happy_path(pipeline, ((Message(text="Hi"), Message(text="false_response")),)) + check_happy_path(pipeline, ((Message("Hi"), Message("false_response")),)) assert e msg = str(e) assert msg diff --git a/tutorials/messengers/telegram/1_basic.py b/tutorials/messengers/telegram/1_basic.py index a4e9b4fce..f1bad3527 100644 --- a/tutorials/messengers/telegram/1_basic.py +++ b/tutorials/messengers/telegram/1_basic.py @@ -45,17 +45,17 @@ class and [telebot](https://pytba.readthedocs.io/en/latest/index.html) "greeting_flow": { "start_node": { TRANSITIONS: { - "greeting_node": cnd.exact_match(Message(text="/start")) + "greeting_node": cnd.exact_match(Message("/start")) }, }, "greeting_node": { - RESPONSE: Message(text="Hi"), + RESPONSE: Message("Hi"), TRANSITIONS: {lbl.repeat(): cnd.true()}, }, "fallback_node": { - RESPONSE: Message(text="Please, repeat the request"), + RESPONSE: Message("Please, repeat the request"), TRANSITIONS: { - "greeting_node": cnd.exact_match(Message(text="/start")) + "greeting_node": cnd.exact_match(Message("/start")) }, }, } @@ -63,9 +63,9 @@ class and [telebot](https://pytba.readthedocs.io/en/latest/index.html) # this variable is only for testing happy_path = ( - (Message(text="/start"), Message(text="Hi")), - (Message(text="Hi"), Message(text="Hi")), - (Message(text="Bye"), Message(text="Hi")), + (Message("/start"), Message("Hi")), + (Message("Hi"), Message("Hi")), + (Message("Bye"), Message("Hi")), ) diff --git a/tutorials/messengers/web_api_interface/2_websocket_chat.py b/tutorials/messengers/web_api_interface/2_websocket_chat.py index c1699fe1f..0cd6020a4 100644 --- a/tutorials/messengers/web_api_interface/2_websocket_chat.py +++ b/tutorials/messengers/web_api_interface/2_websocket_chat.py @@ -92,7 +92,7 @@ async def websocket_endpoint(websocket: WebSocket, client_id: int): while True: data = await websocket.receive_text() await websocket.send_text(f"User: {data}") - request = Message(text=data) + request = Message(data) context = await messenger_interface.on_request_async( request, client_id ) diff --git a/tutorials/messengers/web_api_interface/3_load_testing_with_locust.py b/tutorials/messengers/web_api_interface/3_load_testing_with_locust.py index 9473b9a83..cbe8e70b4 100644 --- a/tutorials/messengers/web_api_interface/3_load_testing_with_locust.py +++ b/tutorials/messengers/web_api_interface/3_load_testing_with_locust.py @@ -135,11 +135,11 @@ def check_first_message(msg: Message) -> str | None: self.check_happy_path( [ # a function can be used to check the return message - (Message(text="Hi"), check_first_message), + (Message("Hi"), check_first_message), # a None is used if return message should not be checked - (Message(text="i'm fine, how are you?"), None), + (Message("i'm fine, how are you?"), None), # this should fail - (Message(text="Hi"), check_first_message), + (Message("Hi"), check_first_message), ] ) diff --git a/tutorials/messengers/web_api_interface/4_streamlit_chat.py b/tutorials/messengers/web_api_interface/4_streamlit_chat.py index e7be1da78..a101b65fc 100644 --- a/tutorials/messengers/web_api_interface/4_streamlit_chat.py +++ b/tutorials/messengers/web_api_interface/4_streamlit_chat.py @@ -122,7 +122,7 @@ def send_and_receive(): st.session_state["user_requests"].append(user_request) bot_response = query( - Message(text=user_request).model_dump(), + Message(user_request).model_dump(), user_id=st.session_state["user_id"], ) bot_response.raise_for_status() diff --git a/tutorials/pipeline/1_basics.py b/tutorials/pipeline/1_basics.py index c3f09ddb0..13d8916ee 100644 --- a/tutorials/pipeline/1_basics.py +++ b/tutorials/pipeline/1_basics.py @@ -82,6 +82,6 @@ if is_interactive_mode(): ctx_id = 0 # 0 will be current dialog (context) identification. while True: - message = Message(text=input("Send request: ")) + message = Message(input("Send request: ")) ctx: Context = pipeline(message, ctx_id) print(ctx.last_response) diff --git a/tutorials/pipeline/2_pre_and_post_processors.py b/tutorials/pipeline/2_pre_and_post_processors.py index f26fafa54..bc8fe5625 100644 --- a/tutorials/pipeline/2_pre_and_post_processors.py +++ b/tutorials/pipeline/2_pre_and_post_processors.py @@ -83,7 +83,7 @@ def pong_processor(ctx: Context): if is_interactive_mode(): ctx_id = 0 # 0 will be current dialog (context) identification. while True: - message = Message(text=input("Send request: ")) + message = Message(input("Send request: ")) ctx: Context = pipeline(message, ctx_id) print(f"Response: {ctx.last_response}") ping_pong = ctx.misc.get("ping", False) and ctx.misc.get( diff --git a/tutorials/script/core/1_basics.py b/tutorials/script/core/1_basics.py index a06ffb96d..c8788d718 100644 --- a/tutorials/script/core/1_basics.py +++ b/tutorials/script/core/1_basics.py @@ -57,7 +57,7 @@ "start_node": { # This is the initial node, # it doesn't contain a `RESPONSE`. RESPONSE: Message(), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, # If "Hi" == request of the user then we make the transition. }, "node1": { @@ -66,32 +66,32 @@ ), # When the agent enters node1, # return "Hi, how are you?". TRANSITIONS: { - "node2": cnd.exact_match(Message(text="I'm fine, how are you?")) + "node2": cnd.exact_match(Message("I'm fine, how are you?")) }, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { "node3": cnd.exact_match( - Message(text="Let's talk about music.") + Message("Let's talk about music.") ) }, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about music now."), + RESPONSE: Message("Sorry, I can not talk about music now."), TRANSITIONS: { - "node4": cnd.exact_match(Message(text="Ok, goodbye.")) + "node4": cnd.exact_match(Message("Ok, goodbye.")) }, }, "node4": { - RESPONSE: Message(text="Bye"), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + RESPONSE: Message("Bye"), + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, "fallback_node": { # We get to this node if the conditions # for switching to other nodes are not performed. - RESPONSE: Message(text="Ooops"), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + RESPONSE: Message("Ooops"), + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, } } @@ -99,37 +99,37 @@ happy_path = ( ( - Message(text="Hi"), - Message(text="Hi, how are you?"), + Message("Hi"), + Message("Hi, how are you?"), ), # start_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="Bye")), # node3 -> node4 - (Message(text="Hi"), Message(text="Hi, how are you?")), # node4 -> node1 - (Message(text="stop"), Message(text="Ooops")), # node1 -> fallback_node + (Message("Ok, goodbye."), Message("Bye")), # node3 -> node4 + (Message("Hi"), Message("Hi, how are you?")), # node4 -> node1 + (Message("stop"), Message("Ooops")), # node1 -> fallback_node ( - Message(text="stop"), - Message(text="Ooops"), + Message("stop"), + Message("Ooops"), ), # fallback_node -> fallback_node ( - Message(text="Hi"), - Message(text="Hi, how are you?"), + Message("Hi"), + Message("Hi, how are you?"), ), # fallback_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="Bye")), # node3 -> node4 + (Message("Ok, goodbye."), Message("Bye")), # node3 -> node4 ) diff --git a/tutorials/script/core/2_conditions.py b/tutorials/script/core/2_conditions.py index bef1b8106..95e96c14f 100644 --- a/tutorials/script/core/2_conditions.py +++ b/tutorials/script/core/2_conditions.py @@ -107,16 +107,16 @@ def internal_condition_function(ctx: Context, _: Pipeline) -> bool: "start_node": { # This is the initial node, # it doesn't contain a `RESPONSE`. RESPONSE: Message(), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, # If "Hi" == request of user then we make the transition }, "node1": { - RESPONSE: Message(text="Hi, how are you?"), + RESPONSE: Message("Hi, how are you?"), TRANSITIONS: {"node2": cnd.regexp(r".*how are you", re.IGNORECASE)}, # pattern matching (precompiled) }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { "node3": cnd.all( [cnd.regexp(r"talk"), cnd.regexp(r"about.*music")] @@ -127,17 +127,17 @@ def internal_condition_function(ctx: Context, _: Pipeline) -> bool: # `aggregate_func` == `all`. }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about music now."), + RESPONSE: Message("Sorry, I can not talk about music now."), TRANSITIONS: {"node4": cnd.regexp(re.compile(r"Ok, goodbye."))}, # pattern matching by precompiled pattern }, "node4": { - RESPONSE: Message(text="bye"), + RESPONSE: Message("bye"), TRANSITIONS: { "node1": cnd.any( [ hi_lower_case_condition, - cnd.exact_match(Message(text="hello")), + cnd.exact_match(Message("hello")), ] ) }, @@ -147,7 +147,7 @@ def internal_condition_function(ctx: Context, _: Pipeline) -> bool: }, "fallback_node": { # We get to this node # if an error occurred while the agent was running. - RESPONSE: Message(text="Ooops"), + RESPONSE: Message("Ooops"), TRANSITIONS: { "node1": complex_user_answer_condition, # The user request can be more than just a string. @@ -170,45 +170,45 @@ def internal_condition_function(ctx: Context, _: Pipeline) -> bool: # testing happy_path = ( ( - Message(text="Hi"), - Message(text="Hi, how are you?"), + Message("Hi"), + Message("Hi, how are you?"), ), # start_node -> node1 ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="bye")), # node3 -> node4 - (Message(text="Hi"), Message(text="Hi, how are you?")), # node4 -> node1 - (Message(text="stop"), Message(text="Ooops")), # node1 -> fallback_node + (Message("Ok, goodbye."), Message("bye")), # node3 -> node4 + (Message("Hi"), Message("Hi, how are you?")), # node4 -> node1 + (Message("stop"), Message("Ooops")), # node1 -> fallback_node ( - Message(text="one"), - Message(text="Ooops"), + Message("one"), + Message("Ooops"), ), # fallback_node -> fallback_node ( - Message(text="help"), - Message(text="Ooops"), + Message("help"), + Message("Ooops"), ), # fallback_node -> fallback_node ( - Message(text="nope"), - Message(text="Ooops"), + Message("nope"), + Message("Ooops"), ), # fallback_node -> fallback_node ( Message(misc={"some_key": "some_value"}), - Message(text="Hi, how are you?"), + Message("Hi, how are you?"), ), # fallback_node -> node1 ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="bye")), # node3 -> node4 + (Message("Ok, goodbye."), Message("bye")), # node3 -> node4 ) # %% diff --git a/tutorials/script/core/3_responses.py b/tutorials/script/core/3_responses.py index 9218d1ed7..eb218eeaf 100644 --- a/tutorials/script/core/3_responses.py +++ b/tutorials/script/core/3_responses.py @@ -54,9 +54,9 @@ def cannot_talk_about_topic_response(ctx: Context, _: Pipeline) -> Message: topic = topic_pattern.findall(request.text) topic = topic and topic[0] and topic[0][-1] if topic: - return Message(text=f"Sorry, I can not talk about {topic} now.") + return Message(f"Sorry, I can not talk about {topic} now.") else: - return Message(text="Sorry, I can not talk about that now.") + return Message("Sorry, I can not talk about that now.") def upper_case_response(response: Message): @@ -84,43 +84,43 @@ def fallback_trace_response(ctx: Context, _: Pipeline) -> Message: "start_node": { # This is an initial node, # it doesn't need a `RESPONSE`. RESPONSE: Message(), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, # If "Hi" == request of user then we make the transition }, "node1": { RESPONSE: rsp.choice( [ - Message(text="Hi, what is up?"), - Message(text="Hello, how are you?"), + Message("Hi, what is up?"), + Message("Hello, how are you?"), ] ), # Random choice from candidate list. TRANSITIONS: { - "node2": cnd.exact_match(Message(text="I'm fine, how are you?")) + "node2": cnd.exact_match(Message("I'm fine, how are you?")) }, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { "node3": cnd.exact_match( - Message(text="Let's talk about music.") + Message("Let's talk about music.") ) }, }, "node3": { RESPONSE: cannot_talk_about_topic_response, TRANSITIONS: { - "node4": cnd.exact_match(Message(text="Ok, goodbye.")) + "node4": cnd.exact_match(Message("Ok, goodbye.")) }, }, "node4": { - RESPONSE: upper_case_response(Message(text="bye")), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + RESPONSE: upper_case_response(Message("bye")), + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, "fallback_node": { # We get to this node # if an error occurred while the agent was running. RESPONSE: fallback_trace_response, - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, } } @@ -128,69 +128,69 @@ def fallback_trace_response(ctx: Context, _: Pipeline) -> Message: # testing happy_path = ( ( - Message(text="Hi"), - Message(text="Hello, how are you?"), + Message("Hi"), + Message("Hello, how are you?"), ), # start_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="BYE")), # node3 -> node4 - (Message(text="Hi"), Message(text="Hi, what is up?")), # node4 -> node1 + (Message("Ok, goodbye."), Message("BYE")), # node3 -> node4 + (Message("Hi"), Message("Hi, what is up?")), # node4 -> node1 ( - Message(text="stop"), + Message("stop"), Message( misc={ "previous_node": ("greeting_flow", "node1"), - "last_request": Message(text="stop"), + "last_request": Message("stop"), } ), ), # node1 -> fallback_node ( - Message(text="one"), + Message("one"), Message( misc={ "previous_node": ("greeting_flow", "fallback_node"), - "last_request": Message(text="one"), + "last_request": Message("one"), } ), ), # f_n->f_n ( - Message(text="help"), + Message("help"), Message( misc={ "previous_node": ("greeting_flow", "fallback_node"), - "last_request": Message(text="help"), + "last_request": Message("help"), } ), ), # f_n->f_n ( - Message(text="nope"), + Message("nope"), Message( misc={ "previous_node": ("greeting_flow", "fallback_node"), - "last_request": Message(text="nope"), + "last_request": Message("nope"), } ), ), # f_n->f_n ( - Message(text="Hi"), - Message(text="Hello, how are you?"), + Message("Hi"), + Message("Hello, how are you?"), ), # fallback_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="BYE")), # node3 -> node4 + (Message("Ok, goodbye."), Message("BYE")), # node3 -> node4 ) # %% diff --git a/tutorials/script/core/4_transitions.py b/tutorials/script/core/4_transitions.py index 2617bdff9..123d226da 100644 --- a/tutorials/script/core/4_transitions.py +++ b/tutorials/script/core/4_transitions.py @@ -106,7 +106,7 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: }, "fallback_node": { # We get to this node if # an error occurred while the agent was running. - RESPONSE: Message(text="Ooops"), + RESPONSE: Message("Ooops"), TRANSITIONS: { ("music_flow", "node1"): cnd.regexp( r"talk about music" @@ -126,7 +126,7 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: }, "greeting_flow": { "node1": { - RESPONSE: Message(text="Hi, how are you?"), + RESPONSE: Message("Hi, how are you?"), # When the agent goes to node1, we return "Hi, how are you?" TRANSITIONS: { ( @@ -139,7 +139,7 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: }, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { lbl.to_fallback(0.1): cnd.true(), # third check # lbl.to_fallback(0.1) is equivalent @@ -158,11 +158,11 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: }, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about that now."), + RESPONSE: Message("Sorry, I can not talk about that now."), TRANSITIONS: {lbl.forward(): cnd.regexp(r"bye")}, }, "node4": { - RESPONSE: Message(text="Bye"), + RESPONSE: Message("Bye"), TRANSITIONS: { "node1": cnd.regexp(r"hi|hello", re.IGNORECASE), # first check lbl.to_fallback(): cnd.true(), # second check @@ -204,7 +204,7 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: }, }, "node4": { - RESPONSE: Message(text="That's all what I know."), + RESPONSE: Message("That's all what I know."), TRANSITIONS: { greeting_flow_n2_transition: cnd.regexp( r"next", re.IGNORECASE @@ -222,76 +222,76 @@ def transition(_: Context, __: Pipeline) -> NodeLabel3Type: # testing happy_path = ( - (Message(text="hi"), Message(text="Hi, how are you?")), + (Message("hi"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="talk about music."), + Message("talk about music."), Message( text="I love `System of a Down` group, " "would you like to talk about it?" ), ), ( - Message(text="yes"), + Message("yes"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="next"), + Message("next"), Message( text="The band achieved commercial success " "with the release of five studio albums." ), ), ( - Message(text="back"), + Message("back"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="repeat"), + Message("repeat"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="next"), + Message("next"), Message( text="The band achieved commercial success " "with the release of five studio albums." ), ), - (Message(text="next"), Message(text="That's all what I know.")), + (Message("next"), Message("That's all what I know.")), ( - Message(text="next"), - Message(text="Good. What do you want to talk about?"), + Message("next"), + Message("Good. What do you want to talk about?"), ), - (Message(text="previous"), Message(text="That's all what I know.")), - (Message(text="next time"), Message(text="Bye")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="previous"), Message(text="Bye")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="nope"), Message(text="Ooops")), - (Message(text="hi"), Message(text="Hi, how are you?")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="previous"), Message(text="Hi, how are you?")), + (Message("previous"), Message("That's all what I know.")), + (Message("next time"), Message("Bye")), + (Message("stop"), Message("Ooops")), + (Message("previous"), Message("Bye")), + (Message("stop"), Message("Ooops")), + (Message("nope"), Message("Ooops")), + (Message("hi"), Message("Hi, how are you?")), + (Message("stop"), Message("Ooops")), + (Message("previous"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="let's talk about something."), - Message(text="Sorry, I can not talk about that now."), + Message("let's talk about something."), + Message("Sorry, I can not talk about that now."), ), - (Message(text="Ok, goodbye."), Message(text="Bye")), + (Message("Ok, goodbye."), Message("Bye")), ) # %% diff --git a/tutorials/script/core/5_global_transitions.py b/tutorials/script/core/5_global_transitions.py index f0dc5a0fc..474bf068f 100644 --- a/tutorials/script/core/5_global_transitions.py +++ b/tutorials/script/core/5_global_transitions.py @@ -74,7 +74,7 @@ }, # This is an initial node, it doesn't need a `RESPONSE`. "fallback_node": { # We get to this node # if an error occurred while the agent was running. - RESPONSE: Message(text="Ooops"), + RESPONSE: Message("Ooops"), TRANSITIONS: {lbl.previous(): cnd.regexp(r"previous", re.I)}, # lbl.previous() is equivalent to # ("previous_flow", "previous_node", 1.0) @@ -82,12 +82,12 @@ }, "greeting_flow": { "node1": { - RESPONSE: Message(text="Hi, how are you?"), + RESPONSE: Message("Hi, how are you?"), TRANSITIONS: {"node2": cnd.regexp(r"how are you")}, # "node2" is equivalent to ("greeting_flow", "node2", 1.0) }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { lbl.forward(0.5): cnd.regexp(r"talk about"), # lbl.forward(0.5) is equivalent to @@ -96,10 +96,10 @@ }, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about that now."), + RESPONSE: Message("Sorry, I can not talk about that now."), TRANSITIONS: {lbl.forward(): cnd.regexp(r"bye")}, }, - "node4": {RESPONSE: Message(text="bye")}, + "node4": {RESPONSE: Message("bye")}, # Only the global transitions setting are used in this node. }, "music_flow": { @@ -125,7 +125,7 @@ TRANSITIONS: {lbl.backward(): cnd.regexp(r"back", re.I)}, }, "node4": { - RESPONSE: Message(text="That's all what I know."), + RESPONSE: Message("That's all what I know."), TRANSITIONS: { ("greeting_flow", "node4"): cnd.regexp(r"next time", re.I), ("greeting_flow", "node2"): cnd.regexp(r"next", re.I), @@ -136,76 +136,76 @@ # testing happy_path = ( - (Message(text="hi"), Message(text="Hi, how are you?")), + (Message("hi"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="talk about music."), + Message("talk about music."), Message( text="I love `System of a Down` group, " "would you like to talk about it?" ), ), ( - Message(text="yes"), + Message("yes"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="next"), + Message("next"), Message( text="The band achieved commercial success " "with the release of five studio albums." ), ), ( - Message(text="back"), + Message("back"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="repeat"), + Message("repeat"), Message( text="System of a Down is " "an Armenian-American heavy metal band formed in 1994." ), ), ( - Message(text="next"), + Message("next"), Message( text="The band achieved commercial success " "with the release of five studio albums." ), ), - (Message(text="next"), Message(text="That's all what I know.")), + (Message("next"), Message("That's all what I know.")), ( - Message(text="next"), - Message(text="Good. What do you want to talk about?"), + Message("next"), + Message("Good. What do you want to talk about?"), ), - (Message(text="previous"), Message(text="That's all what I know.")), - (Message(text="next time"), Message(text="bye")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="previous"), Message(text="bye")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="nope"), Message(text="Ooops")), - (Message(text="hi"), Message(text="Hi, how are you?")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="previous"), Message(text="Hi, how are you?")), + (Message("previous"), Message("That's all what I know.")), + (Message("next time"), Message("bye")), + (Message("stop"), Message("Ooops")), + (Message("previous"), Message("bye")), + (Message("stop"), Message("Ooops")), + (Message("nope"), Message("Ooops")), + (Message("hi"), Message("Hi, how are you?")), + (Message("stop"), Message("Ooops")), + (Message("previous"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="let's talk about something."), - Message(text="Sorry, I can not talk about that now."), + Message("let's talk about something."), + Message("Sorry, I can not talk about that now."), ), - (Message(text="Ok, goodbye."), Message(text="bye")), + (Message("Ok, goodbye."), Message("bye")), ) # %% diff --git a/tutorials/script/core/6_context_serialization.py b/tutorials/script/core/6_context_serialization.py index 855ab9d07..1af38c619 100644 --- a/tutorials/script/core/6_context_serialization.py +++ b/tutorials/script/core/6_context_serialization.py @@ -30,7 +30,7 @@ # %% def response_handler(ctx: Context, _: Pipeline) -> Message: - return Message(text=f"answer {len(ctx.requests)}") + return Message(f"answer {len(ctx.requests)}") # %% @@ -46,10 +46,10 @@ def response_handler(ctx: Context, _: Pipeline) -> Message: # testing happy_path = ( - (Message(text="hi"), Message(text="answer 1")), - (Message(text="how are you?"), Message(text="answer 2")), - (Message(text="ok"), Message(text="answer 3")), - (Message(text="good"), Message(text="answer 4")), + (Message("hi"), Message("answer 1")), + (Message("how are you?"), Message("answer 2")), + (Message("ok"), Message("answer 3")), + (Message("good"), Message("answer 4")), ) # %% [markdown] diff --git a/tutorials/script/core/7_pre_response_processing.py b/tutorials/script/core/7_pre_response_processing.py index fd0ec2a90..9697b8675 100644 --- a/tutorials/script/core/7_pre_response_processing.py +++ b/tutorials/script/core/7_pre_response_processing.py @@ -62,7 +62,7 @@ def add_prefix_processing(ctx: Context, _: Pipeline): RESPONSE: Message(), TRANSITIONS: {("flow", "step_0"): cnd.true()}, }, - "fallback": {RESPONSE: Message(text="the end")}, + "fallback": {RESPONSE: Message("the end")}, }, GLOBAL: { PRE_RESPONSE_PROCESSING: { @@ -78,27 +78,27 @@ def add_prefix_processing(ctx: Context, _: Pipeline): } }, "step_0": { - RESPONSE: Message(text="first"), + RESPONSE: Message("first"), TRANSITIONS: {lbl.forward(): cnd.true()}, }, "step_1": { PRE_RESPONSE_PROCESSING: {"proc_name_1": add_prefix("l1_step_1")}, - RESPONSE: Message(text="second"), + RESPONSE: Message("second"), TRANSITIONS: {lbl.forward(): cnd.true()}, }, "step_2": { PRE_RESPONSE_PROCESSING: {"proc_name_2": add_prefix("l2_step_2")}, - RESPONSE: Message(text="third"), + RESPONSE: Message("third"), TRANSITIONS: {lbl.forward(): cnd.true()}, }, "step_3": { PRE_RESPONSE_PROCESSING: {"proc_name_3": add_prefix("l3_step_3")}, - RESPONSE: Message(text="fourth"), + RESPONSE: Message("fourth"), TRANSITIONS: {lbl.forward(): cnd.true()}, }, "step_4": { PRE_RESPONSE_PROCESSING: {"proc_name_4": add_prefix("l4_step_4")}, - RESPONSE: Message(text="fifth"), + RESPONSE: Message("fifth"), TRANSITIONS: {"step_0": cnd.true()}, }, }, @@ -107,15 +107,15 @@ def add_prefix_processing(ctx: Context, _: Pipeline): # testing happy_path = ( - (Message(), Message(text="l3_local: l2_local: l1_global: first")), - (Message(), Message(text="l3_local: l2_local: l1_step_1: second")), - (Message(), Message(text="l3_local: l2_step_2: l1_global: third")), - (Message(), Message(text="l3_step_3: l2_local: l1_global: fourth")), + (Message(), Message("l3_local: l2_local: l1_global: first")), + (Message(), Message("l3_local: l2_local: l1_step_1: second")), + (Message(), Message("l3_local: l2_step_2: l1_global: third")), + (Message(), Message("l3_step_3: l2_local: l1_global: fourth")), ( Message(), - Message(text="l4_step_4: l3_local: l2_local: l1_global: fifth"), + Message("l4_step_4: l3_local: l2_local: l1_global: fifth"), ), - (Message(), Message(text="l3_local: l2_local: l1_global: first")), + (Message(), Message("l3_local: l2_local: l1_global: first")), ) diff --git a/tutorials/script/core/8_misc.py b/tutorials/script/core/8_misc.py index 55b582a2e..c0ec7310f 100644 --- a/tutorials/script/core/8_misc.py +++ b/tutorials/script/core/8_misc.py @@ -50,7 +50,7 @@ def custom_response(ctx: Context, _: Pipeline) -> Message: RESPONSE: Message(), TRANSITIONS: {("flow", "step_0"): cnd.true()}, }, - "fallback": {RESPONSE: Message(text="the end")}, + "fallback": {RESPONSE: Message("the end")}, }, GLOBAL: { MISC: { diff --git a/tutorials/script/core/9_pre_transitions_processing.py b/tutorials/script/core/9_pre_transitions_processing.py index 259b02e60..9f2eddc01 100644 --- a/tutorials/script/core/9_pre_transitions_processing.py +++ b/tutorials/script/core/9_pre_transitions_processing.py @@ -55,7 +55,7 @@ def prepend_previous_node_response(ctx: Context, _: Pipeline): RESPONSE: Message(), TRANSITIONS: {("flow", "step_0"): cnd.true()}, }, - "fallback": {RESPONSE: Message(text="the end")}, + "fallback": {RESPONSE: Message("the end")}, }, GLOBAL: { PRE_RESPONSE_PROCESSING: { @@ -67,22 +67,22 @@ def prepend_previous_node_response(ctx: Context, _: Pipeline): TRANSITIONS: {lbl.forward(0.1): cnd.true()}, }, "flow": { - "step_0": {RESPONSE: Message(text="first")}, - "step_1": {RESPONSE: Message(text="second")}, - "step_2": {RESPONSE: Message(text="third")}, - "step_3": {RESPONSE: Message(text="fourth")}, - "step_4": {RESPONSE: Message(text="fifth")}, + "step_0": {RESPONSE: Message("first")}, + "step_1": {RESPONSE: Message("second")}, + "step_2": {RESPONSE: Message("third")}, + "step_3": {RESPONSE: Message("fourth")}, + "step_4": {RESPONSE: Message("fifth")}, }, } # testing happy_path = ( - (Message(text="1"), Message(text="previous=None: current=first")), - (Message(text="2"), Message(text="previous=first: current=second")), - (Message(text="3"), Message(text="previous=second: current=third")), - (Message(text="4"), Message(text="previous=third: current=fourth")), - (Message(text="5"), Message(text="previous=fourth: current=fifth")), + (Message("1"), Message("previous=None: current=first")), + (Message("2"), Message("previous=first: current=second")), + (Message("3"), Message("previous=second: current=third")), + (Message("4"), Message("previous=third: current=fourth")), + (Message("5"), Message("previous=fourth: current=fifth")), ) diff --git a/tutorials/script/responses/1_basics.py b/tutorials/script/responses/1_basics.py index e021a4a67..2b1332d1d 100644 --- a/tutorials/script/responses/1_basics.py +++ b/tutorials/script/responses/1_basics.py @@ -28,60 +28,60 @@ toy_script = { "greeting_flow": { "start_node": { - RESPONSE: Message(text=""), - TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}, + RESPONSE: Message(""), + TRANSITIONS: {"node1": exact_match(Message("Hi"))}, }, "node1": { - RESPONSE: Message(text="Hi, how are you?"), + RESPONSE: Message("Hi, how are you?"), TRANSITIONS: { - "node2": exact_match(Message(text="i'm fine, how are you?")) + "node2": exact_match(Message("i'm fine, how are you?")) }, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { - "node3": exact_match(Message(text="Let's talk about music.")) + "node3": exact_match(Message("Let's talk about music.")) }, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about music now."), - TRANSITIONS: {"node4": exact_match(Message(text="Ok, goodbye."))}, + RESPONSE: Message("Sorry, I can not talk about music now."), + TRANSITIONS: {"node4": exact_match(Message("Ok, goodbye."))}, }, "node4": { - RESPONSE: Message(text="bye"), - TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}, + RESPONSE: Message("bye"), + TRANSITIONS: {"node1": exact_match(Message("Hi"))}, }, "fallback_node": { - RESPONSE: Message(text="Ooops"), - TRANSITIONS: {"node1": exact_match(Message(text="Hi"))}, + RESPONSE: Message("Ooops"), + TRANSITIONS: {"node1": exact_match(Message("Hi"))}, }, } } happy_path = ( - (Message(text="Hi"), Message(text="Hi, how are you?")), + (Message("Hi"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), - (Message(text="Ok, goodbye."), Message(text="bye")), - (Message(text="Hi"), Message(text="Hi, how are you?")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="stop"), Message(text="Ooops")), - (Message(text="Hi"), Message(text="Hi, how are you?")), + (Message("Ok, goodbye."), Message("bye")), + (Message("Hi"), Message("Hi, how are you?")), + (Message("stop"), Message("Ooops")), + (Message("stop"), Message("Ooops")), + (Message("Hi"), Message("Hi, how are you?")), ( - Message(text="i'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("i'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about music now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about music now."), ), - (Message(text="Ok, goodbye."), Message(text="bye")), + (Message("Ok, goodbye."), Message("bye")), ) diff --git a/tutorials/script/responses/2_buttons.py b/tutorials/script/responses/2_buttons.py index ff6373c0c..faa9f60bc 100644 --- a/tutorials/script/responses/2_buttons.py +++ b/tutorials/script/responses/2_buttons.py @@ -41,12 +41,12 @@ def payload_check_inner(ctx: Context, _: Pipeline): toy_script = { "root": { "start": { - RESPONSE: Message(text=""), + RESPONSE: Message(""), TRANSITIONS: { ("general", "question_1"): cnd.true(), }, }, - "fallback": {RESPONSE: Message(text="Finishing test")}, + "fallback": {RESPONSE: Message("Finishing test")}, }, "general": { "question_1": { @@ -110,7 +110,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): }, }, "success": { - RESPONSE: Message(text="Success!"), + RESPONSE: Message("Success!"), TRANSITIONS: {("root", "fallback"): cnd.true()}, }, }, @@ -118,7 +118,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): happy_path = ( ( - Message(text="Hi"), + Message("Hi"), Message( **{ "text": "Starting test! What's 2 + 2? " @@ -135,7 +135,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): ), ), ( - Message(text="0"), + Message("0"), Message( **{ "text": "Starting test! What's 2 + 2? " @@ -152,7 +152,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): ), ), ( - Message(text="1"), + Message("1"), Message( **{ "text": "Next question: what's 6 * 8? " @@ -169,7 +169,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): ), ), ( - Message(text="0"), + Message("0"), Message( **{ "text": "Next question: what's 6 * 8? " @@ -186,7 +186,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): ), ), ( - Message(text="1"), + Message("1"), Message( **{ "text": "What's 114 + 115? " @@ -203,7 +203,7 @@ def payload_check_inner(ctx: Context, _: Pipeline): ), ), ( - Message(text="1"), + Message("1"), Message( **{ "text": "What's 114 + 115? " @@ -219,8 +219,8 @@ def payload_check_inner(ctx: Context, _: Pipeline): } ), ), - (Message(text="0"), Message(text="Success!")), - (Message(text="ok"), Message(text="Finishing test")), + (Message("0"), Message("Success!")), + (Message("ok"), Message("Finishing test")), ) diff --git a/tutorials/script/responses/3_media.py b/tutorials/script/responses/3_media.py index e2c8f6ea2..412363c14 100644 --- a/tutorials/script/responses/3_media.py +++ b/tutorials/script/responses/3_media.py @@ -33,7 +33,7 @@ toy_script = { "root": { "start": { - RESPONSE: Message(text=""), + RESPONSE: Message(""), TRANSITIONS: {("pics", "ask_picture"): cnd.true()}, }, "fallback": { @@ -45,7 +45,7 @@ }, "pics": { "ask_picture": { - RESPONSE: Message(text="Please, send me a picture url"), + RESPONSE: Message("Please, send me a picture url"), TRANSITIONS: { ("pics", "send_one", 1.1): cnd.regexp(r"^http.+\.png$"), ("pics", "send_many", 1.0): cnd.regexp( @@ -84,33 +84,33 @@ } happy_path = ( - (Message(text="Hi"), Message(text="Please, send me a picture url")), + (Message("Hi"), Message("Please, send me a picture url")), ( - Message(text="no"), - Message(text="I cannot find the picture. Please, try again."), + Message("no"), + Message("I cannot find the picture. Please, try again."), ), ( - Message(text=img_url), + Message(img_url), Message( text="here's my picture!", attachments=Attachments(files=[Image(source=img_url)]), ), ), ( - Message(text="ok"), - Message(text="Final node reached, send any message to restart."), + Message("ok"), + Message("Final node reached, send any message to restart."), ), - (Message(text="ok"), Message(text="Please, send me a picture url")), + (Message("ok"), Message("Please, send me a picture url")), ( - Message(text=f"{img_url} repeat 10 times"), + Message(f"{img_url} repeat 10 times"), Message( text="Look at my pictures", attachments=Attachments(files=[Image(source=img_url)] * 10), ), ), ( - Message(text="ok"), - Message(text="Final node reached, send any message to restart."), + Message("ok"), + Message("Final node reached, send any message to restart."), ), ) diff --git a/tutorials/script/responses/4_multi_message.py b/tutorials/script/responses/4_multi_message.py index c3e645a16..ed0da008e 100644 --- a/tutorials/script/responses/4_multi_message.py +++ b/tutorials/script/responses/4_multi_message.py @@ -28,44 +28,44 @@ toy_script = { "greeting_flow": { "start_node": { # This is an initial node, - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, # If "Hi" == request of user then we make the transition }, "node1": { RESPONSE: MultiMessage( messages=[ - Message(text="Hi, what is up?", misc={"confidences": 0.85}), + Message("Hi, what is up?", misc={"confidences": 0.85}), Message( text="Hello, how are you?", misc={"confidences": 0.9} ), ] ), TRANSITIONS: { - "node2": cnd.exact_match(Message(text="I'm fine, how are you?")) + "node2": cnd.exact_match(Message("I'm fine, how are you?")) }, }, "node2": { - RESPONSE: Message(text="Good. What do you want to talk about?"), + RESPONSE: Message("Good. What do you want to talk about?"), TRANSITIONS: { "node3": cnd.exact_match( - Message(text="Let's talk about music.") + Message("Let's talk about music.") ) }, }, "node3": { - RESPONSE: Message(text="Sorry, I can not talk about that now."), + RESPONSE: Message("Sorry, I can not talk about that now."), TRANSITIONS: { - "node4": cnd.exact_match(Message(text="Ok, goodbye.")) + "node4": cnd.exact_match(Message("Ok, goodbye.")) }, }, "node4": { - RESPONSE: Message(text="bye"), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + RESPONSE: Message("bye"), + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, "fallback_node": { # We get to this node # if an error occurred while the agent was running. - RESPONSE: Message(text="Ooops"), - TRANSITIONS: {"node1": cnd.exact_match(Message(text="Hi"))}, + RESPONSE: Message("Ooops"), + TRANSITIONS: {"node1": cnd.exact_match(Message("Hi"))}, }, } } @@ -73,67 +73,67 @@ # testing happy_path = ( ( - Message(text="Hi"), + Message("Hi"), MultiMessage( messages=[ - Message(text="Hi, what is up?", misc={"confidences": 0.85}), - Message(text="Hello, how are you?", misc={"confidences": 0.9}), + Message("Hi, what is up?", misc={"confidences": 0.85}), + Message("Hello, how are you?", misc={"confidences": 0.9}), ] ), ), # start_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about that now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about that now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="bye")), # node3 -> node4 + (Message("Ok, goodbye."), Message("bye")), # node3 -> node4 ( - Message(text="Hi"), + Message("Hi"), MultiMessage( messages=[ - Message(text="Hi, what is up?", misc={"confidences": 0.85}), - Message(text="Hello, how are you?", misc={"confidences": 0.9}), + Message("Hi, what is up?", misc={"confidences": 0.85}), + Message("Hello, how are you?", misc={"confidences": 0.9}), ] ), ), # node4 -> node1 ( - Message(text="stop"), - Message(text="Ooops"), + Message("stop"), + Message("Ooops"), ), # node1 -> fallback_node ( - Message(text="one"), - Message(text="Ooops"), + Message("one"), + Message("Ooops"), ), # f_n->f_n ( - Message(text="help"), - Message(text="Ooops"), + Message("help"), + Message("Ooops"), ), # f_n->f_n ( - Message(text="nope"), - Message(text="Ooops"), + Message("nope"), + Message("Ooops"), ), # f_n->f_n ( - Message(text="Hi"), + Message("Hi"), MultiMessage( messages=[ - Message(text="Hi, what is up?", misc={"confidences": 0.85}), - Message(text="Hello, how are you?", misc={"confidences": 0.9}), + Message("Hi, what is up?", misc={"confidences": 0.85}), + Message("Hello, how are you?", misc={"confidences": 0.9}), ] ), ), # fallback_node -> node1 ( - Message(text="I'm fine, how are you?"), - Message(text="Good. What do you want to talk about?"), + Message("I'm fine, how are you?"), + Message("Good. What do you want to talk about?"), ), # node1 -> node2 ( - Message(text="Let's talk about music."), - Message(text="Sorry, I can not talk about that now."), + Message("Let's talk about music."), + Message("Sorry, I can not talk about that now."), ), # node2 -> node3 - (Message(text="Ok, goodbye."), Message(text="bye")), # node3 -> node4 + (Message("Ok, goodbye."), Message("bye")), # node3 -> node4 ) # %% diff --git a/tutorials/utils/1_cache.py b/tutorials/utils/1_cache.py index 676f2f9e5..871c9a939 100644 --- a/tutorials/utils/1_cache.py +++ b/tutorials/utils/1_cache.py @@ -62,9 +62,9 @@ def response(ctx: Context, _, *__, **___) -> Message: } happy_path = ( - (Message(), Message(text="1-2-1-2")), - (Message(), Message(text="3-4-3-4")), - (Message(), Message(text="5-6-5-6")), + (Message(), Message("1-2-1-2")), + (Message(), Message("3-4-3-4")), + (Message(), Message("5-6-5-6")), ) pipeline = Pipeline.from_script(toy_script, start_label=("flow", "node1")) diff --git a/tutorials/utils/2_lru_cache.py b/tutorials/utils/2_lru_cache.py index b0fa4f028..40e59715f 100644 --- a/tutorials/utils/2_lru_cache.py +++ b/tutorials/utils/2_lru_cache.py @@ -61,9 +61,9 @@ def response(ctx: Context, _, *__, **___) -> Message: } happy_path = ( - (Message(), Message(text="1-2-3-2-4")), - (Message(), Message(text="5-6-7-6-8")), - (Message(), Message(text="9-10-11-10-12")), + (Message(), Message("1-2-3-2-4")), + (Message(), Message("5-6-7-6-8")), + (Message(), Message("9-10-11-10-12")), ) pipeline = Pipeline.from_script(toy_script, start_label=("flow", "node1")) diff --git a/utils/stats/sample_data_provider.py b/utils/stats/sample_data_provider.py index d778c922a..d36d0b6a4 100644 --- a/utils/stats/sample_data_provider.py +++ b/utils/stats/sample_data_provider.py @@ -99,7 +99,7 @@ async def worker(queue: asyncio.Queue): flow, node = ["root", "start"] answers = list(MULTIFLOW_REQUEST_OPTIONS.get(flow, {}).get(node, [])) in_text = random.choice(answers) if answers else "go to fallback" - in_message = Message(text=in_text) + in_message = Message(in_text) await asyncio.sleep(random.random() * 3) ctx = await pipeline._run_pipeline(in_message, ctx.id) await asyncio.sleep(random.random() * 3)