Skip to content

Commit

Permalink
Update display_agent_utterance to consider agent and recipient ID (#…
Browse files Browse the repository at this point in the history
…265)

* Update `display_agent_utterance` to consider agent and recipient ID

Fixes #252

* Fix pre-commit

* Update pre-commit requirements

* Address review comments
  • Loading branch information
NoB0 authored Nov 7, 2024
1 parent 9cc5e22 commit f90d7a3
Show file tree
Hide file tree
Showing 17 changed files with 54 additions and 43 deletions.
5 changes: 4 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ repos:
name: docformatter
description: "Formats docstrings to follow PEP 257."
entry: docformatter
args: [--in-place]
args:
- --in-place
- --wrap-summaries=80
- --wrap-descriptions=80
language: python
types: [python]

Expand Down
7 changes: 4 additions & 3 deletions dialoguekit/connector/dialogue_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
the User, the DialogueConnector sends it to the other party by calling their
`receive_{agent/user}_utterance()` method.
"""

from __future__ import annotations

import json
Expand Down Expand Up @@ -107,7 +108,7 @@ def register_agent_utterance(
"""
self._dialogue_history.add_utterance(annotated_utterance)
self._platform.display_agent_utterance(
self._user.id, annotated_utterance
annotated_utterance, self._agent.id, self._user.id
)
if self._agent.stop_intent in annotated_utterance.get_intents():
self.close()
Expand Down Expand Up @@ -137,8 +138,8 @@ def start(self) -> None:
def close(self) -> None:
"""Closes the conversation.
If '_save_dialogue_history' is set to True it will export the
dialogue history.
If '_save_dialogue_history' is set to True it will export the dialogue
history.
"""
if self._save_dialogue_history:
self._dump_dialogue_history()
Expand Down
6 changes: 3 additions & 3 deletions dialoguekit/core/annotated_utterance.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
class AnnotatedUtterance(Utterance):
"""Represents an utterance, with annotations.
The AnnotatedUtterance is a Utterance with additional information.
In some cases we want to send an utterance with dialogue acts and/or
Annotations. Dialogue acts are a specific type of annotation.
The AnnotatedUtterance is a Utterance with additional information. In some
cases we want to send an utterance with dialogue acts and/or Annotations.
Dialogue acts are a specific type of annotation.
"""

dialogue_acts: List[DialogueAct] = field(
Expand Down
6 changes: 3 additions & 3 deletions dialoguekit/core/feedback.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Interface representing user's feedback.
Currently only binary feedback is supported on the utterance level.
Later, it might be extended to graded feedback as well as with
conversation-level feedback.
Currently only binary feedback is supported on the utterance level. Later, it
might be extended to graded feedback as well as with conversation-level
feedback.
"""
from dataclasses import dataclass, field
from enum import Enum
Expand Down
4 changes: 2 additions & 2 deletions dialoguekit/nlu/disjoint_dialogue_act_extractor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Dialogue act extractor with disjoint intent classification and slot filling.
It is assumed that the intent classifier assigns a single intent to the
utterance that corresponds to the slot-value pairs extracted by the
slot-value annotators.
utterance that corresponds to the slot-value pairs extracted by the slot-value
annotators.
"""

from __future__ import annotations
Expand Down
6 changes: 3 additions & 3 deletions dialoguekit/nlu/intent_classifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""Abstract interface for intent classification.
This interface assumes a single intent per utterance, i.e., approaches
the task as a single-label classification problem. The generalization to
multi-label classification is left to future work.
This interface assumes a single intent per utterance, i.e., approaches the task
as a single-label classification problem. The generalization to multi-label
classification is left to future work.
"""

from abc import ABC, abstractmethod
Expand Down
3 changes: 1 addition & 2 deletions dialoguekit/participant/user.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Abstract representation of core user-related data and functionality.
For communicating with an agent, the specific user instance needs to be
connected with a DialogueConnector by invoking
`register_dialogue_connector()`.
connected with a DialogueConnector by invoking `register_dialogue_connector()`.
"""
from __future__ import annotations

Expand Down
4 changes: 2 additions & 2 deletions dialoguekit/participant/user_preferences.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""General representation of user preferences.
Preferences are given to key-value pairs in terms of real values in the
range [-1,1].
Preferences are given to key-value pairs in terms of real values in the range
[-1,1].
"""

from collections import defaultdict
Expand Down
9 changes: 5 additions & 4 deletions dialoguekit/platforms/flask_socket_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def from_utterance(self, utterance: Utterance) -> Message:

@dataclass
class Response:
recipient: str
sender: str
message: Message


Expand All @@ -84,17 +84,18 @@ def start(self, host: str = "127.0.0.1", port: str = "5000") -> None:
self.socketio.run(self.app, host=host, port=port)

def display_agent_utterance(
self, user_id: str, utterance: Utterance
self, utterance: Utterance, agent_id: str, user_id: str
) -> None:
"""Emits agent utterance to the client.
Args:
user_id: User ID.
utterance: An instance of Utterance.
agent_id: Agent ID.
user_id: User ID of the recipient.
"""
message = Message.from_utterance(utterance)
self.socketio.send(
asdict(Response(user_id, message)),
asdict(Response(agent_id, message)),
room=user_id,
)

Expand Down
9 changes: 7 additions & 2 deletions dialoguekit/platforms/platform.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The Platform facilitates displaying of the conversation."""

from abc import ABC, abstractmethod
from typing import Dict, Type

Expand Down Expand Up @@ -30,13 +31,17 @@ def start(self) -> None:

@abstractmethod
def display_agent_utterance(
self, user_id: str, utterance: Utterance
self, utterance: Utterance, agent_id: str, user_id: str
) -> None:
"""Displays an agent utterance.
Considering that an agent can interact with multiple users, the
user_id is provided to identify the recipient.
Args:
user_id: User ID.
utterance: An instance of Utterance.
agent_id: Agent ID.
user_id: User ID of the recipient.
Raises:
NotImplementedError: If the method is not implemented.
Expand Down
10 changes: 6 additions & 4 deletions dialoguekit/platforms/terminal_platform.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
"""Terminal platform.
This platform is used for getting user input and displaying agent
responses in the terminal.
This platform is used for getting user input and displaying agent responses in
the terminal.
"""

from typing import Type

from dialoguekit.core import Utterance
Expand Down Expand Up @@ -36,13 +37,14 @@ def start(self) -> None:
self.disconnect(self._user_id)

def display_agent_utterance(
self, user_id: str, utterance: Utterance
self, utterance: Utterance, agent_id: str, user_id: str = None
) -> None:
"""Displays an agent utterance.
Args:
user_id: User ID.
utterance: An instance of Utterance.
agent_id: Agent ID.
user_id: User ID of the recipient. Defaults to None.
"""
print(f"AGENT: {utterance.text}")

Expand Down
4 changes: 2 additions & 2 deletions dialoguekit/utils/annotation_converter.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Annotation converter interface.
As the different modules used for NLU use different formats for
training, file converters are needed.
As the different modules used for NLU use different formats for training, file
converters are needed.
"""

from abc import ABC, abstractmethod
Expand Down
2 changes: 1 addition & 1 deletion requirements/pre_commit.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pre-commit
pre-commit==3.8.0
black==21.7b0 #Tensorflow 2.6.1 requires typing-extensions~=3.7.4 requires black<=21.7b0
click>=8.0.2 # Fixes black error https://github.com/psf/black/issues/2964
flake8==5.0.4
Expand Down
4 changes: 2 additions & 2 deletions sample_agents/rasa_parrot_agent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Simplest possible agent that parrots back everything the user says.
This agent depends on Rasa parrot project to parrot back. See
'docs/rasa-parrot.md' for more information
This agent depends on Rasa parrot project to parrot back. See 'docs/rasa-
parrot.md' for more information
"""

import requests
Expand Down
5 changes: 2 additions & 3 deletions sample_agents/woz_agent.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
"""Wizard-of-Oz (WoZ) agent.
A WoZ agent is one that is controlled by a human operator. It can be
especially useful for human-human data collection or for testing
simulated users.
A WoZ agent is one that is controlled by a human operator. It can be especially
useful for human-human data collection or for testing simulated users.
"""
from typing import List, Optional

Expand Down
3 changes: 1 addition & 2 deletions tests/nlg/test_conditional_nlg.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
def nlg_class() -> ConditionalNLG:
"""Tests class init.
This method is also a testing fixture used for the rest of the
tests.
This method is also a testing fixture used for the rest of the tests.
"""
template = extract_utterance_template(
annotated_dialogue_file=ANNOTATED_DIALOGUE_FILE,
Expand Down
10 changes: 6 additions & 4 deletions tests/platforms/test_flask_socketio_platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,11 @@ def test_display_agent_utterance(send, platform):
text = "Hello, I'm an agent!"
utterance = Utterance(text, DialogueParticipant.AGENT)

platform.display_agent_utterance(user_id, utterance)
agent_id = "test_agent_id"
platform.display_agent_utterance(utterance, agent_id, user_id)
send.assert_called_once_with(
{
"recipient": user_id,
"sender": agent_id,
"message": {"text": text, "dialogue_acts": None},
},
room=user_id,
Expand All @@ -150,10 +151,11 @@ def test_display_agent_annotated_utterance(send, platform):
],
)

platform.display_agent_utterance(user_id, utterance)
agent_id = "test_agent_id"
platform.display_agent_utterance(utterance, agent_id, user_id)
send.assert_called_once_with(
{
"recipient": user_id,
"sender": agent_id,
"message": {
"text": text,
"dialogue_acts": [
Expand Down

0 comments on commit f90d7a3

Please sign in to comment.