Skip to content
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

Add simulator. #2703

Merged
merged 113 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
f88b109
Adding simulator templates
nagkumar91 Apr 8, 2024
432d532
Adding synthetic simulator
nagkumar91 Apr 8, 2024
1d5697e
Add tests and dependencies
nagkumar91 Apr 8, 2024
33b6bc8
fix version of aiohttp_retry
nagkumar91 Apr 8, 2024
1db2ebd
Install before tests
nagkumar91 Apr 8, 2024
758de41
Resolve compliance check
nagkumar91 Apr 8, 2024
2ae3b2a
Syntax error on the yml
nagkumar91 Apr 8, 2024
0e9693c
Perform dev setup on unit test setup stage
nagkumar91 Apr 8, 2024
4358014
Change the setup
nagkumar91 Apr 8, 2024
f386152
revert the test file and add install of azure.keyvault
nagkumar91 Apr 8, 2024
0952488
Changing the install again
nagkumar91 Apr 8, 2024
1452643
simulator takes on ml_client as an arg
nagkumar91 Apr 10, 2024
13a0689
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 10, 2024
9ce7b38
Remove reference to ai client
nagkumar91 Apr 10, 2024
d5c6e0b
Remove unnecessary method
nagkumar91 Apr 10, 2024
e39197a
removed unused code
nagkumar91 Apr 11, 2024
8799016
Keyword args for public facing simulaor methods
nagkumar91 Apr 11, 2024
92cdb2c
removed dependency
nagkumar91 Apr 11, 2024
8db2749
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 11, 2024
3160da6
making simulator_templates private
nagkumar91 Apr 11, 2024
922accf
Move tests to right folder
nagkumar91 Apr 12, 2024
9ad30af
updated semaphore limit and load_flow
nagkumar91 Apr 12, 2024
f7288d5
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 13, 2024
89d1aec
Remove pdb
nagkumar91 Apr 15, 2024
b58e70b
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 15, 2024
62ea4c5
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 16, 2024
02334be
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 17, 2024
ab6a3cc
Add e2e test
nagkumar91 Apr 18, 2024
ea5d5f3
More e2e tests
nagkumar91 Apr 18, 2024
5205979
Integrate tests to evals folder
nagkumar91 Apr 18, 2024
da941dd
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 18, 2024
e22ceeb
ignore file in cfg and add unknown word
nagkumar91 Apr 18, 2024
fa8d1f1
Add recording for new test
nagkumar91 Apr 18, 2024
d56b607
Skip e2e test having DefaultAzureCredential
nagkumar91 Apr 18, 2024
3197fed
Fix failing test
nagkumar91 Apr 18, 2024
58c7a12
Update the recordings
nagkumar91 Apr 18, 2024
6447d57
Update recording
nagkumar91 Apr 18, 2024
c87e4d0
Marking test as skipped to mitigate 429s in recording
nagkumar91 Apr 19, 2024
afb10af
Fix cspell issues
nagkumar91 Apr 19, 2024
83c73b7
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 19, 2024
af5b3f0
Fix the formatting of docstring
nagkumar91 Apr 19, 2024
3b41ab4
Update the non-adv simulator to use a class to initialize a userbot c…
nagkumar91 Apr 22, 2024
10606f8
Merge accepting remote changes for data file
nagkumar91 Apr 23, 2024
166b546
Fixed the unittest
nagkumar91 Apr 23, 2024
ab451f5
Fixed e2e tests
nagkumar91 Apr 23, 2024
d99cb39
Skip the failing test
nagkumar91 Apr 23, 2024
746aa0a
Skip test on python 3.9 or lower
nagkumar91 Apr 23, 2024
a676092
Initial rewrite begin
nagkumar91 Apr 26, 2024
d2c2ca0
Raise error when incorrect template is being passed
nagkumar91 Apr 26, 2024
897f840
Add e2e test
nagkumar91 Apr 26, 2024
1f243e4
e2e test with and without rai_svc_url
nagkumar91 Apr 26, 2024
51beacb
State with circular import issue
nagkumar91 Apr 27, 2024
5f606b7
e2e test passing for qa
nagkumar91 Apr 27, 2024
f6ccd8f
Remove old simulator pieces
nagkumar91 Apr 27, 2024
ed24705
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 27, 2024
8675fbc
Merge branch 'main' into task/addSimulator
nagkumar91 Apr 29, 2024
1f50ba9
removed unused test
nagkumar91 Apr 29, 2024
05fbf29
Fix time taken and remove duplicate class
nagkumar91 Apr 29, 2024
4cc7c42
Added unitests for conversation bot
nagkumar91 Apr 29, 2024
7de92b6
Trying a fix for python 3.8 and 3.9
nagkumar91 Apr 29, 2024
7393ba8
Added more tests for callback conversation bot
nagkumar91 Apr 29, 2024
39d1e76
Lock in the identity manager
nagkumar91 Apr 29, 2024
b52c81a
Remove print
nagkumar91 Apr 29, 2024
3770661
Making calls to proxy completion models work better
nagkumar91 Apr 29, 2024
d5292da
remove sending 2 messages with file content
nagkumar91 Apr 29, 2024
bee5c6d
Removed all the old qa things
nagkumar91 Apr 29, 2024
710f48c
Add docstring
nagkumar91 Apr 30, 2024
340ac6d
Adding e2e test for adv_conversation
nagkumar91 Apr 30, 2024
dd58d8d
More tests and add monitoring to adversarial simulator
nagkumar91 May 1, 2024
985a7cc
Merge branch 'main' into task/addSimulator
nagkumar91 May 1, 2024
a5b8324
Update test_adv_simulator.py
nagkumar91 May 1, 2024
6eb9f72
more test changes and remove strict check for template string
nagkumar91 May 2, 2024
0472f91
Fix test and remove unused captioning code
nagkumar91 May 2, 2024
4b428e3
CHange AzureCLICredential to DefaultAzureCredential
nagkumar91 May 2, 2024
292c76c
Add readme
nagkumar91 May 3, 2024
ab40397
Bug bash instrcutions
nagkumar91 May 3, 2024
736b431
Error message for service not available
nagkumar91 May 3, 2024
7aca2ce
Adding context back to follow chat protocol
nagkumar91 May 3, 2024
52738a3
Merge branch 'main' into task/addSimulator
nagkumar91 May 3, 2024
d9854bd
fix conftest formatting
nagkumar91 May 3, 2024
e677c56
Merge branch 'main' into task/addSimulator
nagkumar91 May 6, 2024
638bb07
Remove certain keys from output and add it to tests
nagkumar91 May 6, 2024
48642f3
Remove offensive content in readme
nagkumar91 May 6, 2024
7e0a614
Merge branch 'main' into task/addSimulator
nagkumar91 May 6, 2024
69a746c
Changed the signature according to discussion
nagkumar91 May 7, 2024
71b5b68
Better variable name in readme
nagkumar91 May 7, 2024
ab799e3
Merge branch 'main' into task/addSimulator
nagkumar91 May 7, 2024
11f8de7
Change project_scope to azure_ai_project
nagkumar91 May 7, 2024
23da5a8
update instructions
nagkumar91 May 7, 2024
c59d0ec
update instructions
nagkumar91 May 7, 2024
9fb3caa
update bugbash instructions
nagkumar91 May 7, 2024
22b2524
removed redundant deps
nagkumar91 May 7, 2024
18c0977
Remove retry on 424
nagkumar91 May 7, 2024
7608f72
Removed the references to mlflow_logger as it was not being used
nagkumar91 May 7, 2024
acb660b
Using dataclass
nagkumar91 May 7, 2024
d2c09bd
Merge branch 'main' into task/addSimulator
nagkumar91 May 7, 2024
ae8ca58
use project_name instead of workspace_name
nagkumar91 May 7, 2024
70c2ba5
Update the eval part for bug bash
nagkumar91 May 7, 2024
fa96739
Fix the return type docstring and remove tracking for init
nagkumar91 May 8, 2024
a27b78a
uppercase RAI_SVC_URL
nagkumar91 May 8, 2024
5a3cf52
Merge branch 'main' into task/addSimulator
nagkumar91 May 8, 2024
8e2b5c8
Update import for content safety evaluators
nagkumar91 May 8, 2024
b22b47d
Fix for jailbreak sim
nagkumar91 May 8, 2024
2496b20
Added test to make sure jailbreak works
nagkumar91 May 8, 2024
d7c92ed
Update bugbash instrctions
nagkumar91 May 8, 2024
675bea8
Change to add the enum for adversarial scenarios
nagkumar91 May 9, 2024
ea3b9f4
Fixed e2e tests and readme
nagkumar91 May 9, 2024
35f2e61
Singular scenario
nagkumar91 May 9, 2024
1c9f167
Import fix and jupyter notebook comment
nagkumar91 May 9, 2024
667adb3
Merge branch 'main' into task/addSimulator
nagkumar91 May 9, 2024
5c25178
Skipping the e2e tests
nagkumar91 May 10, 2024
d1e7108
Skipping the e2e tests
nagkumar91 May 10, 2024
0c891c7
Merge branch 'main' into task/addSimulator
nagkumar91 May 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 93 additions & 79 deletions .cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,101 +102,115 @@
"uvicorn"
],
"ignoreWords": [
"prompty",
"AADSTS700082",
nagkumar91 marked this conversation as resolved.
Show resolved Hide resolved
"punc",
"mltable",
"tiktoken",
"Mobius",
"evals",
"nlines",
"openmpi",
"ipynb",
"xdist",
"pydash",
"tqdm",
"rtype",
"epocs",
"fout",
"funcs",
"todos",
"fstring",
"creds",
"zipp",
"gmtime",
"pyjwt",
"nbconvert",
"nbformat",
"pypandoc",
"dotenv",
"miniconda",
"datas",
"tcgetpgrp",
"Hwfoxydrg",
"thead",
"yamls",
"fmt",
"serpapi",
"runsv",
"continuumio",
"datas",
"pydash",
"genutils",
"metadatas",
"tiktoken",
"bfnrt",
"orelse",
"thead",
"werkzeug",
"fmt",
"httpx",
"pkill",
"levelno",
"nohup",
"pyjwt",
"wscript",
"sympy",
"ghactions",
"endofprompt",
"miniconda",
"getch",
"esac",
"MSRC",
"pycln",
"LANCZOS",
"cmpl",
"spawnve",
"metadatas",
"llmops",
"unlabel",
"llms",
"strictyaml",
"psutil",
"getch",
"tcgetattr",
"TCSADRAIN",
"stringio",
"jsonify",
"werkzeug",
"continuumio",
"pydantic",
"iterrows",
"uqkvl",
"nologo",
"dtype",
"fillna",
"nlines",
"gunicorn",
"Pyinstaller",
"aggr",
"pycln",
"jsonify",
"MSRC",
"metagenai",
"tcsetattr",
"pysqlite",
"AADSTS700082",
"Pyinstaller",
"runsvdir",
"runsv",
"levelno",
"LANCZOS",
"Mobius",
"ruamel",
"gunicorn",
"pkill",
"pgrep",
"Hwfoxydrg",
"llms",
"xdist",
"addrs",
"tcgetpgrp",
"setenv",
"epocs",
"vcrpy",
"uionly",
"llmops",
"Abhishek",
"restx",
"httpx",
"TCSADRAIN",
"nbconvert",
"dotenv",
"fout",
"STARTF",
"otel",
"fillna",
"tqdm",
"gmtime",
"ghactions",
"runsvdir",
"pywin",
"serpapi",
"pysqlite",
"zipp",
"tiiuae",
"nohup",
"metagenai",
"WBITS",
"laddr",
"aiohttp",
"nrows",
"Dumpable",
"XCLASS",
"otel",
"funcs",
"orelse",
"Unlabel",
"ipynb",
"OTLP",
"pgrep",
"pypandoc",
"nbformat",
"psutil",
"spawnv",
"spawnve",
"addrs",
"pywin",
"STARTF",
"mltable",
"prompty",
"Prompty",
"setenv",
"cscript",
"nologo",
"wscript",
"fstring",
"pydantic",
"raisvc",
"restx",
"WBITS",
"cscript",
"bfnrt",
"ruamel",
"Prompty",
"todos",
"uionly",
"tcgetattr",
"stringio",
"Dumpable",
"XCLASS",
"iterrows",
"laddr",
"unbatched",
"creds",
"pybase",
"tkey",
"tparam",
"ncols",
"wohdjewodhfjevwdjfywlemfhe",
nagkumar91 marked this conversation as resolved.
Show resolved Hide resolved
"dontcare",
"evals",
"dcid"
],
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/promptflow-evals-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,4 +102,4 @@ jobs:
format: markdown
hide_complexity: true
output: both
thresholds: 40 60
thresholds: 40 60
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------
import os

_template_dir = os.path.join(os.path.dirname(__file__), "templates")

# from .simulator.simulator import Simulator # pylint: disable=wrong-import-position


# __all__ = ["Simulator"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

# pylint: disable=unused-import
from .al_conversation_bot import AugLoopConversationBot

# pylint: disable=unused-import
from .augloop_client import AugLoopParams

# pylint: disable=unused-import
from .constants import ConversationRole

# pylint: disable=unused-import
from .conversation import debug_conversation, play_conversation, simulate_conversation

# pylint: disable=unused-import
from .conversation_bot import ConversationBot

# pylint: disable=unused-import
from .conversation_request import ConversationRequest

# pylint: disable=unused-import
from .conversation_turn import ConversationTurn

# pylint: disable=unused-import
from .conversation_writer import ConversationWriter

# pylint: disable=unused-import
from .dummy_conversation_bot import DummyConversationBot

__all__ = [
"AugLoopConversationBot",
"AugLoopParams",
"ConversationRole",
"debug_conversation",
"play_conversation",
"simulate_conversation",
"ConversationBot",
"ConversationRequest",
"ConversationTurn",
"ConversationWriter",
"DummyConversationBot",
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# ---------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# ---------------------------------------------------------

import logging
import time
from typing import Dict, List, Tuple

from promptflow.evals.synthetic.simulator._model_tools import RetryClient

from .augloop_client import AugLoopClient, AugLoopParams
from .constants import ConversationRole
from .conversation_bot import ConversationBot
from .conversation_turn import ConversationTurn


class AugLoopConversationBot(ConversationBot):
def __init__( # pylint: disable=super-init-not-called
self,
role: ConversationRole,
augLoopParams: AugLoopParams,
instantiation_parameters: Dict[str, str],
):
"""
Create an AugLoop ConversationBot with specific name,
persona and a sentence that can be used as a conversation starter.

Parameters
----------
role: The role of the bot in the conversation, either USER or ASSISTANT
augLoopParams: The augloop params to use for connecting to augloop
conversation_template: A jinja2 template that describes the conversation,
this is used to generate the prompt for the LLM
instantiation_parameters: A dictionary of parameters that are used to instantiate the conversation template
"""
if role == ConversationRole.USER:
raise Exception("AugLoop conversation Bot is not enabled for USER role")

self.role = role
self.augLoopParams = augLoopParams

self.persona_template_args = instantiation_parameters
self.name = (
self.persona_template_args.get("chatbot_name", role.value) or f"Augloop_{augLoopParams.workflowName}"
)

self.logger = logging.getLogger(repr(self))

self.augLoopClient = AugLoopClient(augLoopParams)

async def generate_response(
self,
session: RetryClient,
conversation_history: List[ConversationTurn],
max_history: int,
turn_number: int = 0,
) -> Tuple[dict, dict, int, dict]:
"""
Prompt the ConversationBot for a response.

:param session: The aiohttp session to use for the request.
:type session: RetryClient
:param conversation_history: The turns in the conversation so far.
:type conversation_history: List[ConversationTurn]
:param max_history: Parameters used to query GPT-4 model.
:type max_history: int
:param turn_number: Parameters used to query GPT-4 model.
:type turn_number: int
:return: The response from the ConversationBot.
:rtype: Tuple[dict, dict, int, dict]
"""

messageToSend = conversation_history[-1].message

time_start = time.time()

# send message
response_data = self.augLoopClient.send_signal_and_wait_for_annotation(messageToSend)

time_taken = time.time() - time_start

if not response_data["success"]:
raise Exception("Unexpected result from Augloop")

parsed_response = {
"samples": response_data["messages"],
"id": response_data["id"],
}

messages = [{"role": "system", "content": messageToSend}]
request = {"messages": messages}

return parsed_response, request, int(time_taken), response_data["full_message"]

def __repr__(self):
return f"Bot(name={self.name}, role={self.role.name}, model=Augloop)"
Loading
Loading