Skip to content

Commit 6eedf8f

Browse files
Copilotslister1001
andcommitted
Implement ability for caller to update red team user agent
Co-authored-by: slister1001 <[email protected]>
1 parent 53ac499 commit 6eedf8f

File tree

3 files changed

+817
-233
lines changed

3 files changed

+817
-233
lines changed

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

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,35 @@ def add_useragent_product(cls, *product: str) -> Iterator[None]:
3838

3939
@classmethod
4040
@contextmanager
41-
def redteam_context(cls) -> Iterator[None]:
41+
def redteam_context(cls, *, subtype: str = "RedTeam", **kwargs) -> Iterator[None]:
4242
"""Context manager to use red team user agent for RAI service calls
4343
4444
This context manager temporarily sets the user agent to include red team context
4545
for all calls within the context.
46+
47+
:param subtype: The subtype to use in the red team user agent. Defaults to "RedTeam"
48+
:type subtype: str
49+
:param kwargs: Additional keyword arguments for future extensibility
50+
"""
51+
with cls.add_useragent_product(f"(type=redteam; subtype={subtype})"):
52+
yield
53+
54+
@classmethod
55+
@contextmanager
56+
def redteam_context_with_product(cls, *products: str) -> Iterator[None]:
57+
"""Context manager to use custom red team user agent for RAI service calls
58+
59+
This context manager temporarily sets the user agent to include custom red team
60+
products for all calls within the context.
61+
62+
:param products: User Agent products to append for red team context
63+
:type products: str
64+
65+
..see-also::
66+
67+
`User-Agent section of RFC 9110, <https://www.rfc-editor.org/rfc/rfc9110#name-user-agent>`
4668
"""
47-
with cls.add_useragent_product("(type=redteam; subtype=RedTeam)"):
69+
default_redteam_product = "(type=redteam; subtype=RedTeam)"
70+
all_products = [default_redteam_product] + list(products)
71+
with cls.add_useragent_product(*all_products):
4872
yield

0 commit comments

Comments
 (0)