-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding the non adversarial simulator (#37350)
* Adding the non adversarial simulator * Remove promptflow.evals * Fixed the import bug * Fixed the parse response error * Fixed the output to be in json format * Fix progress bar * remove pdb * sphinx please be happy with this * Move application calling logic to a separate function * Synthetic to simulator * Removed old init * Add unittests * Docstring and warning message * First turn through the simulator * Fixes to test and user flow * More checks and changes to messages * Fix the progress bar --------- Co-authored-by: Nagkumar Arkalgud <nagkumar@naarkalg-work-mac.local> Co-authored-by: Nagkumar Arkalgud <nagkumar@naarkalgworkmac.lan> Co-authored-by: Nagkumar Arkalgud <nagkumar@Mac.lan>
- Loading branch information
1 parent
b9824f7
commit a9233f4
Showing
11 changed files
with
1,185 additions
and
34 deletions.
There are no files selected for viewing
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
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
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
3 changes: 2 additions & 1 deletion
3
sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_helpers/__init__.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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
from ._simulator_data_classes import ConversationHistory, Turn | ||
from ._language_suffix_mapping import SUPPORTED_LANGUAGES_MAPPING | ||
|
||
__all__ = ["SUPPORTED_LANGUAGES_MAPPING"] | ||
__all__ = ["ConversationHistory", "Turn", "SUPPORTED_LANGUAGES_MAPPING"] |
93 changes: 93 additions & 0 deletions
93
...ion/azure-ai-evaluation/azure/ai/evaluation/simulator/_helpers/_simulator_data_classes.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,93 @@ | ||
# --------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# --------------------------------------------------------- | ||
# pylint: disable=C0103,C0114,C0116 | ||
from dataclasses import dataclass | ||
from typing import Union | ||
|
||
from azure.ai.evaluation.simulator._conversation.constants import ConversationRole | ||
|
||
|
||
@dataclass | ||
class Turn: | ||
""" | ||
Represents a conversation turn, | ||
keeping track of the role, content, | ||
and context of a turn in a conversation. | ||
""" | ||
|
||
role: Union[str, ConversationRole] | ||
content: str | ||
context: str = None | ||
|
||
def to_dict(self): | ||
""" | ||
Convert the conversation turn to a dictionary. | ||
Returns: | ||
dict: A dictionary representation of the conversation turn. | ||
""" | ||
return { | ||
"role": self.role.value if isinstance(self.role, ConversationRole) else self.role, | ||
"content": self.content, | ||
"context": self.context, | ||
} | ||
|
||
def __repr__(self): | ||
""" | ||
Return the string representation of the conversation turn. | ||
Returns: | ||
str: A string representation of the conversation turn. | ||
""" | ||
return f"Turn(role={self.role}, content={self.content})" | ||
|
||
|
||
class ConversationHistory: | ||
""" | ||
Conversation history class to keep track of the conversation turns in a conversation. | ||
""" | ||
|
||
def __init__(self): | ||
""" | ||
Initializes the conversation history with an empty list of turns. | ||
""" | ||
self.history = [] | ||
|
||
def add_to_history(self, turn: Turn): | ||
""" | ||
Adds a turn to the conversation history. | ||
Args: | ||
turn (Turn): The conversation turn to add. | ||
""" | ||
self.history.append(turn) | ||
|
||
def to_list(self): | ||
""" | ||
Converts the conversation history to a list of dictionaries. | ||
Returns: | ||
list: A list of dictionaries representing the conversation turns. | ||
""" | ||
return [turn.to_dict() for turn in self.history] | ||
|
||
def get_length(self): | ||
""" | ||
Returns the length of the conversation. | ||
Returns: | ||
int: The number of turns in the conversation history. | ||
""" | ||
return len(self.history) | ||
|
||
def __repr__(self): | ||
""" | ||
Returns the string representation of the conversation history. | ||
Returns: | ||
str: A string representation of the conversation history. | ||
""" | ||
for turn in self.history: | ||
print(turn) | ||
return "" |
Oops, something went wrong.