Skip to content

Commit fa2d637

Browse files
Copilotslister1001
andcommitted
Implement red team user agent for RAI service calls
Co-authored-by: slister1001 <[email protected]>
1 parent 8b4e111 commit fa2d637

File tree

2 files changed

+420
-400
lines changed

2 files changed

+420
-400
lines changed

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/_user_agent.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
class UserAgentSingleton:
1111
__BASE_USER_AGENT: str = "{}/{}".format("azure-ai-evaluation", VERSION)
12+
__REDTEAM_USER_AGENT: str = "{}-redteam/{}".format("azure-ai-evaluation", VERSION)
13+
__is_redteam_context: bool = False
1214

1315
@property
1416
def value(self):
1517
"""Get the user-agent"""
16-
return self.__BASE_USER_AGENT
18+
return self.__REDTEAM_USER_AGENT if self.__is_redteam_context else self.__BASE_USER_AGENT
1719

1820
def __str__(self) -> str:
1921
return self.value
@@ -35,3 +37,18 @@ def add_useragent_product(cls, *product: str) -> Iterator[None]:
3537
yield
3638

3739
cls.__BASE_USER_AGENT = old_useragent
40+
41+
@classmethod
42+
@contextmanager
43+
def redteam_context(cls) -> Iterator[None]:
44+
"""Context manager to use red team user agent for RAI service calls
45+
46+
This context manager temporarily sets the user agent to "azure-ai-evaluation-redteam"
47+
for all calls within the context.
48+
"""
49+
old_context = cls.__is_redteam_context
50+
cls.__is_redteam_context = True
51+
52+
yield
53+
54+
cls.__is_redteam_context = old_context

0 commit comments

Comments
 (0)