Skip to content

Commit

Permalink
Remove MultiMessage (#330)
Browse files Browse the repository at this point in the history
* replace multimessage with misc messages

* format
  • Loading branch information
RLKRo authored Feb 29, 2024
1 parent ac34686 commit b8c4bc6
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 41 deletions.
2 changes: 1 addition & 1 deletion dff/script/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@
ModuleName,
ActorStage,
)
from .core.message import Message, MultiMessage
from .core.message import Message
6 changes: 0 additions & 6 deletions dff/script/core/message.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,3 @@ def __eq__(self, other):

def __repr__(self) -> str:
return " ".join([f"{key}='{value}'" for key, value in self.model_dump(exclude_none=True).items()])


class MultiMessage(Message):
"""This class represents a message that contains multiple sub-messages."""

messages: Optional[List[Message]] = None
78 changes: 44 additions & 34 deletions tutorials/script/responses/4_multi_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,18 @@
"""
# Responses: 4. Multi Message
This tutorial shows Multi Message usage.
This tutorial shows how to store several messages inside a single one.
This might be useful if you want DFF Pipeline to send `response` candidates
to the messenger interface instead of a final response.
The %mddoclink(api,script.core.message,MultiMessage)
represents a combination of several messages.
Let's do all the necessary imports from DFF.
However, this approach is not recommended due to history incompleteness.
"""

# %pip install dff

# %%

from dff.script import TRANSITIONS, RESPONSE, Message, MultiMessage
from dff.script import TRANSITIONS, RESPONSE, Message
import dff.script.conditions as cnd

from dff.pipeline import Pipeline
Expand All @@ -32,13 +31,16 @@
# If "Hi" == request of user then we make the transition
},
"node1": {
RESPONSE: MultiMessage(
messages=[
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message(
text="Hello, how are you?", misc={"confidences": 0.9}
),
]
RESPONSE: Message(
misc={
"messages": [
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("I'm fine, how are you?"))
Expand All @@ -47,16 +49,12 @@
"node2": {
RESPONSE: Message("Good. What do you want to talk about?"),
TRANSITIONS: {
"node3": cnd.exact_match(
Message("Let's talk about music.")
)
"node3": cnd.exact_match(Message("Let's talk about music."))
},
},
"node3": {
RESPONSE: Message("Sorry, I can not talk about that now."),
TRANSITIONS: {
"node4": cnd.exact_match(Message("Ok, goodbye."))
},
TRANSITIONS: {"node4": cnd.exact_match(Message("Ok, goodbye."))},
},
"node4": {
RESPONSE: Message("bye"),
Expand All @@ -74,11 +72,15 @@
happy_path = (
(
Message("Hi"),
MultiMessage(
messages=[
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message("Hello, how are you?", misc={"confidences": 0.9}),
]
Message(
misc={
"messages": [
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message(
text="Hello, how are you?", misc={"confidences": 0.9}
),
]
}
),
), # start_node -> node1
(
Expand All @@ -92,11 +94,15 @@
(Message("Ok, goodbye."), Message("bye")), # node3 -> node4
(
Message("Hi"),
MultiMessage(
messages=[
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message("Hello, how are you?", misc={"confidences": 0.9}),
]
Message(
misc={
"messages": [
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message(
text="Hello, how are you?", misc={"confidences": 0.9}
),
]
}
),
), # node4 -> node1
(
Expand All @@ -118,11 +124,15 @@
), # f_n->f_n
(
Message("Hi"),
MultiMessage(
messages=[
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message("Hello, how are you?", misc={"confidences": 0.9}),
]
Message(
misc={
"messages": [
Message("Hi, what is up?", misc={"confidences": 0.85}),
Message(
text="Hello, how are you?", misc={"confidences": 0.9}
),
]
}
),
), # fallback_node -> node1
(
Expand Down

0 comments on commit b8c4bc6

Please sign in to comment.