Skip to content

Commit 8bd1c68

Browse files
nagkumar91Nagkumar ArkalgudNagkumar ArkalgudNagkumar Arkalgud
authored andcommitted
Eval qr json lines now has context from both turns and category if it exists (Azure#38199)
* Update task_query_response.prompty remove required keys * Update task_simulate.prompty * Update task_query_response.prompty * Update task_simulate.prompty * Fix the api_key needed * Update for release * Black fix for file * Add original text in global context * Update test * Update the indirect attack simulator * Black suggested fixes * Update simulator prompty * Update adversarial scenario enum to exclude XPIA * Update changelog * Black fixes * Remove duplicate import * Fix the mypy error * Mypy please be happy * Updates to non adv simulator * accept context from assistant messages, exclude them when using them for conversation * update changelog * pylint fixes * pylint fixes * remove redundant quotes * Fix typo * pylint fix * Update broken tests * Include the grounding json in the manifest * Fix typo * Come on package * Release 1.0.0b5 * Notice from Chang * Remove adv_conv template parameters from the outputs * Update chanagelog * Experimental tags on adv scenarios * Readme fix onbreaking change * Add the category and both user and assistant context to the response of qr_json_lines * Update changelog --------- Co-authored-by: Nagkumar Arkalgud <[email protected]> Co-authored-by: Nagkumar Arkalgud <[email protected]> Co-authored-by: Nagkumar Arkalgud <[email protected]>
1 parent 37bf5c8 commit 8bd1c68

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

sdk/evaluation/azure-ai-evaluation/CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Breaking Changes
88

99
### Bugs Fixed
10+
- Output of adversarial simulators are of type `JsonLineList` and the helper function `to_eval_qr_json_lines` now outputs context from both user and assistant turns along with `category` if it exists in the conversation
1011

1112
### Other Changes
1213
- Refined error messages for serviced-based evaluators and simulators.

sdk/evaluation/azure-ai-evaluation/azure/ai/evaluation/simulator/_utils.py

+25-7
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,41 @@ def to_eval_qr_json_lines(self):
4444
for item in self:
4545
user_message = None
4646
assistant_message = None
47-
context = None
47+
user_context = None
48+
assistant_context = None
49+
template_parameters = item.get("template_parameters", {})
50+
category = template_parameters.get("category", None)
4851
for message in item["messages"]:
4952
if message["role"] == "user":
5053
user_message = message["content"]
54+
user_context = message.get("context", "")
5155
elif message["role"] == "assistant":
5256
assistant_message = message["content"]
53-
if "context" in message:
54-
context = message.get("context", None)
57+
assistant_context = message.get("context", "")
5558
if user_message and assistant_message:
56-
if context:
59+
if user_context or assistant_context:
5760
json_lines += (
58-
json.dumps({"query": user_message, "response": assistant_message, "context": context})
61+
json.dumps(
62+
{
63+
"query": user_message,
64+
"response": assistant_message,
65+
"context": str(
66+
{
67+
"user_context": user_context,
68+
"assistant_context": assistant_context,
69+
}
70+
),
71+
"category": category,
72+
}
73+
)
5974
+ "\n"
6075
)
61-
user_message = assistant_message = context = None
76+
user_message = assistant_message = None
6277
else:
63-
json_lines += json.dumps({"query": user_message, "response": assistant_message}) + "\n"
78+
json_lines += (
79+
json.dumps({"query": user_message, "response": assistant_message, "category": category})
80+
+ "\n"
81+
)
6482
user_message = assistant_message = None
6583

6684
return json_lines

0 commit comments

Comments
 (0)