Skip to content

Commit 27537c3

Browse files
committed
update chat template structure
1 parent da72047 commit 27537c3

File tree

10 files changed

+26
-48
lines changed

10 files changed

+26
-48
lines changed

autointent/generation/utterances/evolution/chat_templates/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@
77
from .informal import InformalEvolution
88
from .reasoning import ReasoningEvolution
99

10+
EVOLUTION_NAMES = [evolution.name for evolution in EvolutionChatTemplate.__subclasses__()]
11+
12+
EVOLUTION_MAPPING = {evolution.name: evolution for evolution in EvolutionChatTemplate.__subclasses__()}
13+
1014
__all__ = [
15+
"EVOLUTION_MAPPING",
16+
"EVOLUTION_NAMES",
1117
"AbstractEvolution",
1218
"ConcreteEvolution",
1319
"EvolutionChatTemplate",

autointent/generation/utterances/evolution/chat_templates/abstract.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class AbstractEvolution(EvolutionChatTemplate):
1211
"""Chat template for evolution augmentation via abstraction."""
1312

13+
name = "abstract"
1414
_messages: ClassVar[list[Message]] = [
1515
Message(
1616
role=Role.USER,
@@ -35,4 +35,4 @@ class AbstractEvolution(EvolutionChatTemplate):
3535
),
3636
),
3737
Message(role=Role.ASSISTANT, content="I'm having trouble with my laptop."),
38-
]
38+
]
Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Base class for chat templates for evolution augmentation."""
22

3-
from abc import ABC, abstractmethod
43
from typing import ClassVar
54

65
from autointent.generation.utterances.schemas import Message, Role
@@ -10,13 +9,13 @@
109
class EvolutionChatTemplate:
1110
"""Base class for chat templates for evolution augmentation."""
1211

13-
invoke_message: Message
1412
_messages: ClassVar[list[Message]]
13+
name: str
1514

1615
def __call__(self, utterance: str, intent_data: Intent) -> list[Message]:
1716
"""Make a chat to complete by LLM."""
1817
invoke_message = Message(
1918
role=Role.USER,
2019
content=f"Intent name: {intent_data.name or ''}\nUtterance: {utterance}",
2120
)
22-
return [*self._messages, invoke_message]
21+
return [*self._messages, invoke_message]

autointent/generation/utterances/evolution/chat_templates/concrete.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class ConcreteEvolution(EvolutionChatTemplate):
1211
"""Chat template for evolution augmentation via concretizing."""
1312

13+
name = "concrete"
14+
1415
_messages: ClassVar[list[Message]] = [
1516
Message(
1617
role=Role.USER,
@@ -33,4 +34,3 @@ class ConcreteEvolution(EvolutionChatTemplate):
3334
),
3435
Message(role=Role.ASSISTANT, content="My laptop is constantly rebooting and overheating."),
3536
]
36-

autointent/generation/utterances/evolution/chat_templates/formal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class FormalEvolution(EvolutionChatTemplate):
1211
"""Chat template for formal tone augmentation."""
1312

13+
name: str = "formal"
14+
1415
_messages: ClassVar[list[Message]] = [
1516
Message(
1617
role=Role.USER,
@@ -39,4 +40,3 @@ class FormalEvolution(EvolutionChatTemplate):
3940
content="My Lenovo laptop frequently restarts and experiences overheating issues. Kindly assist.",
4041
),
4142
]
42-

autointent/generation/utterances/evolution/chat_templates/funny.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class FunnyEvolution(EvolutionChatTemplate):
1211
"""Chat template for humorous tone augmentation."""
1312

13+
name: str = "funny"
1414
_messages: ClassVar[list[Message]] = [
1515
Message(
1616
role=Role.USER,

autointent/generation/utterances/evolution/chat_templates/goofy.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class GoofyEvolution(EvolutionChatTemplate):
1211
"""Chat template for goofy tone augmentation."""
1312

13+
name: str = "goofy"
1414
_messages: ClassVar[list[Message]] = [
1515
Message(
1616
role=Role.USER,

autointent/generation/utterances/evolution/chat_templates/informal.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class InformalEvolution(EvolutionChatTemplate):
1211
"""Chat template for informal tone augmentation."""
1312

13+
name: str = "informal"
1414
_messages: ClassVar[list[Message]] = [
1515
Message(
1616
role=Role.USER,
@@ -35,4 +35,4 @@ class InformalEvolution(EvolutionChatTemplate):
3535
),
3636
),
3737
Message(role=Role.ASSISTANT, content="My Lenovo keeps crashing and getting super hot. Any ideas?"),
38-
]
38+
]

autointent/generation/utterances/evolution/chat_templates/reasoning.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
from typing import ClassVar
44

55
from autointent.generation.utterances.schemas import Message, Role
6-
from autointent.schemas import Intent
76

87
from .base import EvolutionChatTemplate
98

109

1110
class ReasoningEvolution(EvolutionChatTemplate):
1211
"""Chat template for evolution augmentation via reasoning."""
1312

13+
name = "reasoning"
14+
1415
_messages: ClassVar[list[Message]] = [
1516
Message(
1617
role=Role.USER,

autointent/generation/utterances/evolution/cli.py

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@
88
from autointent.generation.utterances.generator import Generator
99

1010
from .chat_templates import (
11-
AbstractEvolution,
12-
ConcreteEvolution,
13-
FormalEvolution,
14-
FunnyEvolution,
15-
GoofyEvolution,
16-
InformalEvolution,
17-
ReasoningEvolution,
11+
EVOLUTION_MAPPING,
12+
EVOLUTION_NAMES,
1813
)
1914

2015
logging.basicConfig(level="INFO")
@@ -44,14 +39,8 @@ def _parse_args() -> Namespace:
4439
)
4540
parser.add_argument("--private", action="store_true", help="Publish privately if --output-repo option is used")
4641
parser.add_argument("--n-evolutions", type=int, default=1, help="Number of utterances to generate for each intent")
47-
parser.add_argument("--decide-for-me", action="store_true")
48-
parser.add_argument("--reasoning", action="store_true", help="Whether to use `Reasoning` evolution")
49-
parser.add_argument("--concretizing", action="store_true", help="Whether to use `Concretizing` evolution")
50-
parser.add_argument("--abstract", action="store_true", help="Whether to use `Abstract` evolution")
51-
parser.add_argument("--formal", action="store_true", help="Whether to use `Formal` evolution")
52-
parser.add_argument("--funny", action="store_true", help="Whether to use `Funny` evolution")
53-
parser.add_argument("--goofy", action="store_true", help="Whether to use `Goofy` evolution")
54-
parser.add_argument("--informal", action="store_true", help="Whether to use `Informal` evolution")
42+
parser.add_argument("--decide-for-me", action="store_true", help="Enable incremental evolution")
43+
parser.add_argument("--template", type=str, choices=EVOLUTION_NAMES, help="Template to use", nargs="+")
5544
parser.add_argument("--async-mode", action="store_true", help="Enable asynchronous generation")
5645
parser.add_argument("--seed", type=int, default=0)
5746
parser.add_argument("--batch-size", type=int, default=4)
@@ -62,25 +51,8 @@ def _parse_args() -> Namespace:
6251

6352
def main() -> None:
6453
"""CLI endpoint."""
65-
mapping = {
66-
"reasoning": ReasoningEvolution,
67-
"concretizing": ConcreteEvolution,
68-
"abstract": AbstractEvolution,
69-
"formal": FormalEvolution,
70-
"funny": FunnyEvolution,
71-
"goofy": GoofyEvolution,
72-
"informal": InformalEvolution,
73-
}
7454
args = _parse_args()
75-
evolutions = []
76-
77-
for arg_name, evolution_cls in mapping.items():
78-
if getattr(args, arg_name):
79-
evolutions.append(evolution_cls()) # type: ignore[abstract]
80-
81-
if not evolutions:
82-
logger.warning("No evolutions selected. Exiting.")
83-
return
55+
evolutions = [EVOLUTION_MAPPING[template_name] for template_name in args.template]
8456

8557
utterance_evolver: UtteranceEvolver
8658
if args.decide_for_me:
@@ -103,7 +75,7 @@ def main() -> None:
10375
dataset.to_json(args.output_path)
10476

10577
if args.output_repo is not None:
106-
dataset.push_to_hub(args.output_repo)
78+
dataset.push_to_hub(args.output_repo, args.private)
10779

10880

10981
if __name__ == "__main__":

0 commit comments

Comments
 (0)