Skip to content

Commit 15016a5

Browse files
authored
Feat/augmentation (#107)
* fix: change location of prompts * feat: update evolution class * feat: update chat templates * feat: added new evolutions * feat: change test structure & add test_generator * fix: fixex ruff * fix: fixed import * fix: fixed chat_templates
1 parent a05b530 commit 15016a5

File tree

18 files changed

+318
-17
lines changed

18 files changed

+318
-17
lines changed

autointent/generation/intents/prompt_scheme.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pydantic import BaseModel, field_validator
44

5-
from autointent.generation.utterances.prompts import PROMPT_DESCRIPTION
5+
from autointent.generation.intents.prompts import PROMPT_DESCRIPTION
66

77

88
class PromptDescription(BaseModel):
File renamed without changes.
Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
from .basic import SynthesizerChatTemplate, UtteranceGenerator
2-
from .evolution import AbstractEvolution, ConcreteEvolution, EvolutionChatTemplate, ReasoningEvolution, UtteranceEvolver
2+
from .evolution import (
3+
AbstractEvolution,
4+
ConcreteEvolution,
5+
EvolutionChatTemplate,
6+
FormalEvolution,
7+
FunnyEvolution,
8+
GoofyEvolution,
9+
InformalEvolution,
10+
ReasoningEvolution,
11+
UtteranceEvolver,
12+
)
313
from .generator import Generator
414

515
__all__ = [
6-
"AbstractEvolution",
7-
"ConcreteEvolution",
8-
"EvolutionChatTemplate",
9-
"Generator",
10-
"ReasoningEvolution",
11-
"SynthesizerChatTemplate",
12-
"UtteranceEvolver",
13-
"UtteranceGenerator",
16+
"AbstractEvolution",
17+
"ConcreteEvolution",
18+
"EvolutionChatTemplate",
19+
"FormalEvolution",
20+
"FunnyEvolution",
21+
"Generator",
22+
"GoofyEvolution",
23+
"InformalEvolution",
24+
"ReasoningEvolution",
25+
"SynthesizerChatTemplate",
26+
"UtteranceEvolver",
27+
"UtteranceGenerator",
1428
]
Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1-
from .chat_templates import AbstractEvolution, ConcreteEvolution, EvolutionChatTemplate, ReasoningEvolution
1+
from .chat_templates import (
2+
AbstractEvolution,
3+
ConcreteEvolution,
4+
EvolutionChatTemplate,
5+
FormalEvolution,
6+
FunnyEvolution,
7+
GoofyEvolution,
8+
InformalEvolution,
9+
ReasoningEvolution,
10+
)
211
from .evolver import UtteranceEvolver
312

4-
__all__ = ["AbstractEvolution", "ConcreteEvolution", "EvolutionChatTemplate", "ReasoningEvolution", "UtteranceEvolver"]
13+
__all__ = [
14+
"AbstractEvolution",
15+
"ConcreteEvolution",
16+
"EvolutionChatTemplate",
17+
"FormalEvolution",
18+
"FunnyEvolution",
19+
"GoofyEvolution",
20+
"InformalEvolution",
21+
"ReasoningEvolution",
22+
"UtteranceEvolver",
23+
]
Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
from .abstract import AbstractEvolution
22
from .base import EvolutionChatTemplate
33
from .concrete import ConcreteEvolution
4+
from .formal import FormalEvolution
5+
from .funny import FunnyEvolution
6+
from .goofy import GoofyEvolution
7+
from .informal import InformalEvolution
48
from .reasoning import ReasoningEvolution
59

6-
__all__ = ["AbstractEvolution", "ConcreteEvolution", "EvolutionChatTemplate", "ReasoningEvolution"]
10+
__all__ = [
11+
"AbstractEvolution",
12+
"ConcreteEvolution",
13+
"EvolutionChatTemplate",
14+
"FormalEvolution",
15+
"FunnyEvolution",
16+
"GoofyEvolution",
17+
"InformalEvolution",
18+
"ReasoningEvolution",
19+
]

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ class AbstractEvolution(EvolutionChatTemplate):
2828
),
2929
Message(role=Role.ASSISTANT, content="Please, reserve a table for me."),
3030
Message(
31-
role=Role.ASSISTANT,
31+
role=Role.USER,
3232
content=(
33-
"Intent name: requesting technical support"
33+
"Intent name: requesting technical support\n"
3434
"Utterance: My Lenovo laptop is constantly rebooting and overheating."
3535
),
3636
),

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ class ConcreteEvolution(EvolutionChatTemplate):
2929
Message(role=Role.ASSISTANT, content="I want to reserve a table for 4 persons at 9 pm."),
3030
Message(
3131
role=Role.USER,
32-
content=("Intent name: requesting technical support\n" "Utterance: I'm having trouble with my laptop."),
32+
content=(
33+
"Intent name: requesting technical support\n"
34+
"Utterance: I'm having trouble with my laptop."
35+
),
3336
),
3437
Message(role=Role.ASSISTANT, content="My laptop is constantly rebooting and overheating."),
3538
]
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""Chat template for formal tone augmentation."""
2+
3+
from typing import ClassVar
4+
5+
from autointent.generation.utterances.schemas import Message, Role
6+
from autointent.schemas import Intent
7+
8+
from .base import EvolutionChatTemplate
9+
10+
11+
class FormalEvolution(EvolutionChatTemplate):
12+
"""Chat template for formal tone augmentation."""
13+
14+
_messages: ClassVar[list[Message]] = [
15+
Message(
16+
role=Role.USER,
17+
content=(
18+
"I want you to act as a rewriter. "
19+
"You will be provided with an utterance and the topic (name of intent class) of the utterance. "
20+
"You need to rewrite the utterance in a more formal tone using the following method:\n"
21+
"1. Rewrite the utterance in a more formal tone.\n"
22+
"2. Use polite and professional language while maintaining clarity.\n"
23+
"3. The rewritten utterance should be grammatically correct and complete.\n"
24+
"4. Keep the rewritten utterance within 15 words.\n\n"
25+
"Intent name: Reserve Restaurant"
26+
"Utterance: I want to reserve a table for 4 persons at 9 pm."
27+
),
28+
),
29+
Message(role=Role.ASSISTANT, content="I would like to make a reservation for four guests at 9 pm."),
30+
Message(
31+
role=Role.ASSISTANT,
32+
content=(
33+
"Intent name: requesting technical support\n"
34+
"Utterance: My Lenovo laptop is constantly rebooting and overheating."
35+
),
36+
),
37+
Message(
38+
role=Role.ASSISTANT,
39+
content="My Lenovo laptop frequently restarts and experiences overheating issues. Kindly assist.",
40+
),
41+
]
42+
43+
def __call__(self, utterance: str, intent_data: Intent) -> list[Message]:
44+
"""Generate chat for formal tone adaptation."""
45+
return [
46+
*self._messages,
47+
Message(role=Role.USER, content=f"Intent name: {intent_data.name or ''}\nUtterance: {utterance}"),
48+
]
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
"""Chat template for humorous tone augmentation."""
2+
3+
from typing import ClassVar
4+
5+
from autointent.generation.utterances.schemas import Message, Role
6+
from autointent.schemas import Intent
7+
8+
from .base import EvolutionChatTemplate
9+
10+
11+
class FunnyEvolution(EvolutionChatTemplate):
12+
"""Chat template for humorous tone augmentation."""
13+
14+
_messages: ClassVar[list[Message]] = [
15+
Message(
16+
role=Role.USER,
17+
content=(
18+
"I want you to act as a rewriter. "
19+
"You will be provided with an utterance and the topic (name of intent class) of the utterance. "
20+
"You need to rewrite the utterance in a humorous way while maintaining its original meaning using "
21+
"the following method:\n"
22+
"1. Rewrite the utterance in a humorous way while maintaining its original meaning.\n"
23+
"2. Use wordplay, exaggeration, or lighthearted phrasing.\n"
24+
"3. The rewritten utterance should still be understandable and relevant.\n"
25+
"4. Keep it within 15 words.\n\n"
26+
"Intent name: Reserve Restaurant"
27+
"Utterance: I want to reserve a table for 4 persons at 9 pm."
28+
),
29+
),
30+
Message(role=Role.ASSISTANT, content="Gotta feed my squad at 9 pm. Got a table for us?"),
31+
Message(
32+
role=Role.USER,
33+
content=(
34+
"Intent name: requesting technical support\n"
35+
"Utterance: My Lenovo laptop is constantly rebooting and overheating."
36+
),
37+
),
38+
Message(role=Role.ASSISTANT, content="My Lenovo thinks it's a phoenix—keeps dying and rising in flames."),
39+
]
40+
41+
def __call__(self, utterance: str, intent_data: Intent) -> list[Message]:
42+
"""Generate chat for humorous tone adaptation."""
43+
return [
44+
*self._messages,
45+
Message(role=Role.USER, content=f"Intent name: {intent_data.name or ''}\nUtterance: {utterance}"),
46+
]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
"""Chat template for goofy tone augmentation."""
2+
3+
from typing import ClassVar
4+
5+
from autointent.generation.utterances.schemas import Message, Role
6+
from autointent.schemas import Intent
7+
8+
from .base import EvolutionChatTemplate
9+
10+
11+
class GoofyEvolution(EvolutionChatTemplate):
12+
"""Chat template for goofy tone augmentation."""
13+
14+
_messages: ClassVar[list[Message]] = [
15+
Message(
16+
role=Role.USER,
17+
content=(
18+
"I want you to act as a rewriter. "
19+
"You will be provided with an utterance and the topic (name of intent class) of the utterance. "
20+
"You need to rewrite the utterance in a silly, exaggerated, or nonsensical way while keeping "
21+
"the intent clear using the following method:\n"
22+
"1. Rewrite the utterance in a silly, exaggerated, or nonsensical way while keeping the intent clear.\n"
23+
"2. Use playful words, randomness, or exaggeration.\n"
24+
"3. The rewritten utterance should still be answerable.\n"
25+
"4. Keep it under 15 words.\n\n"
26+
"Intent name: Reserve Restaurant"
27+
"Utterance: I want to reserve a table for 4 persons at 9 pm."
28+
),
29+
),
30+
Message(role=Role.ASSISTANT, content="Need a feast for my hungry goblins at 9. Got room?"),
31+
Message(
32+
role=Role.USER,
33+
content=(
34+
"Intent name: requesting technical support\n"
35+
"Utterance: My Lenovo laptop is constantly rebooting and overheating."
36+
),
37+
),
38+
Message(
39+
role=Role.ASSISTANT,
40+
content="My laptop's having an existential crisis—keeps rebooting and melting. Help!"
41+
),
42+
]
43+
44+
def __call__(self, utterance: str, intent_data: Intent) -> list[Message]:
45+
"""Generate chat for goofy tone adaptation."""
46+
return [
47+
*self._messages,
48+
Message(role=Role.USER, content=f"Intent name: {intent_data.name or ''}\nUtterance: {utterance}"),
49+
]

0 commit comments

Comments
 (0)