-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat/prompt management #109
Merged
Merged
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
0f067b1
refactor templates storing
voorhs fac77e3
make base class
voorhs f949881
update evolver
voorhs de6f820
move `schemas.py`
voorhs 4a15243
update cli
voorhs 80e3644
minor bug fix
voorhs 5761719
fix typing
voorhs 21957b4
refactor chat template for basic utterance generator
voorhs 1681e77
update utterance synthesizer
voorhs de8d602
update `Dataset.from_hub` method
voorhs a3a9c76
add debug messages to cli endpoint
voorhs 218e707
update cli for evolver
voorhs 1e04f3e
fix shared classvar issue
voorhs 9072524
add tests for basic chat template
voorhs 06d1d58
configure explicit import from `generation.utterances` submodule
voorhs ac26313
add tests for augmentation
voorhs 1adc68b
commit to trigger gh actions
voorhs 24ef258
fix one doctest
voorhs db769d2
pull dev
voorhs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
autointent/generation/utterances/basic/chat_template.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
"""Chat template for evolution augmentation via abstractization.""" | ||
|
||
import random | ||
from abc import ABC, abstractmethod | ||
from typing import ClassVar | ||
|
||
from autointent import Dataset | ||
from autointent.generation.utterances.schemas import Message, Role | ||
from autointent.schemas import Intent | ||
|
||
|
||
class BaseSynthesizer(ABC): | ||
"""Base class.""" | ||
|
||
@abstractmethod | ||
def __call__(self, intent_data: Intent, n_examples: int) -> list[Message]: | ||
"""Generate examples for this intent.""" | ||
|
||
|
||
class SynthesizerChatTemplate(BaseSynthesizer): | ||
"""Chat template for generating additional examples for a given intent class.""" | ||
|
||
_messages: ClassVar[list[Message]] = [ | ||
Message( | ||
role=Role.USER, | ||
content=( | ||
"You will be provided with a set of example utterances and the name " | ||
"of the common topic (intent name) of these utterances. " | ||
"Your task is to generate more examples that fit within the same intent name.\n\n" | ||
"Note:\n" | ||
"- You can generate similar utterances with only slot values changed\n" | ||
"- You can generate completely different utterance from the same intent name\n" | ||
"- Intent name can be missed, then you should infer from example utterances only\n" | ||
"- Example utterances can be missed, then you should infer from intent name only\n" | ||
"{extra_instructions}\n\n" | ||
"Intent name: ordering_pizza\n\n" | ||
"Example Utterances:\n" | ||
"1. I want to order a large pepperoni pizza.\n" | ||
"2. Can I get a medium cheese pizza with extra olives?\n" | ||
"3. Please deliver a small veggie pizza to my address.\n\n" | ||
"Please generate 3 more examples for the provided intent name." | ||
), | ||
), | ||
Message( | ||
role=Role.ASSISTANT, | ||
content=( | ||
"1. I'd like to order a large margherita pizza.\n" | ||
"2. Can you deliver a medium Hawaiian pizza with extra pineapple?\n" | ||
"3. Please send a small BBQ chicken pizza to my home." | ||
), | ||
), | ||
Message( | ||
role=Role.USER, | ||
content=( | ||
"Intent name: booking a hotel\n\n" | ||
"Example Utterances:\n" | ||
"1. I need to book a room for two nights in New York.\n\n" | ||
"Please generate 2 more examples for the provided intent name." | ||
), | ||
), | ||
Message( | ||
role=Role.ASSISTANT, | ||
content=( | ||
"1. Can you reserve a deluxe room for my trip to Tokyo?\n" | ||
"2. I need to book a hotel room with a mountain view in Denver." | ||
), | ||
), | ||
Message( | ||
role=Role.USER, | ||
content=( | ||
"Intent name:\n\n" | ||
"Example Utterances:\n" | ||
"1. What is the weather like today?\n\n" | ||
"Please generate 2 more examples for the provided intent class." | ||
), | ||
), | ||
Message( | ||
role=Role.ASSISTANT, | ||
content=("1. Can you tell me the forecast for tomorrow?\n" "2. Is it going to rain this weekend?"), | ||
), | ||
Message( | ||
role=Role.USER, | ||
content=( | ||
"Intent name: Scheduling a Meeting\n\n" | ||
"Example Utterances:\n\n" | ||
"Please generate 3 more examples for the provided intent class." | ||
), | ||
), | ||
Message( | ||
role=Role.ASSISTANT, | ||
content=( | ||
"1. I need to schedule a meeting for next Tuesday.\n" | ||
"2. Can you set up a conference call for tomorrow afternoon?\n" | ||
"3. Please arrange a meeting with the marketing team next week." | ||
), | ||
), | ||
] | ||
|
||
def __init__( | ||
self, | ||
dataset: Dataset, | ||
split: str, | ||
extra_instructions: str | None = None, | ||
max_sample_utterances: int | None = None, | ||
) -> None: | ||
"""Initialize.""" | ||
if extra_instructions is None: | ||
extra_instructions = "" | ||
|
||
msg = self._messages[0] | ||
msg["content"] = msg["content"].format(extra_instructions=extra_instructions) | ||
|
||
self.dataset = dataset | ||
self.split = split | ||
self.max_sample_utterances = max_sample_utterances | ||
|
||
def __call__(self, intent_data: Intent, n_examples: int) -> list[Message]: | ||
"""Generate additional examples for the provided intent class.""" | ||
filtered_split = self.dataset[self.split].filter(lambda sample: sample[Dataset.label_feature] == intent_data.id) | ||
sample_utterances = filtered_split[Dataset.utterance_feature] | ||
if self.max_sample_utterances is not None: | ||
sample_utterances = random.sample(sample_utterances, k=self.max_sample_utterances) | ||
return [ | ||
*self._messages, | ||
Message( | ||
role=Role.USER, | ||
content=f"Intent name: {intent_data.name}\n\n" | ||
f"Example Utterances:\n{sample_utterances}\n\n" | ||
f"Please generate {n_examples} more examples for the provided intent class.\n", | ||
), | ||
] |
119 changes: 0 additions & 119 deletions
119
autointent/generation/utterances/basic/chat_template.yaml
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 0 additions & 14 deletions
14
autointent/generation/utterances/basic/extra_instructions.json
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Кажется тут часть темлейта
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
не, это норм, в конструкторе эта часть заполняется