azure-ai-evaluation 1.0.1__py3-none-any.whl → 1.13.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of azure-ai-evaluation might be problematic. Click here for more details.
- azure/ai/evaluation/__init__.py +83 -14
- azure/ai/evaluation/_aoai/__init__.py +10 -0
- azure/ai/evaluation/_aoai/aoai_grader.py +140 -0
- azure/ai/evaluation/_aoai/label_grader.py +68 -0
- azure/ai/evaluation/_aoai/python_grader.py +86 -0
- azure/ai/evaluation/_aoai/score_model_grader.py +94 -0
- azure/ai/evaluation/_aoai/string_check_grader.py +66 -0
- azure/ai/evaluation/_aoai/text_similarity_grader.py +80 -0
- azure/ai/evaluation/_azure/__init__.py +3 -0
- azure/ai/evaluation/_azure/_clients.py +204 -0
- azure/ai/evaluation/_azure/_envs.py +207 -0
- azure/ai/evaluation/_azure/_models.py +227 -0
- azure/ai/evaluation/_azure/_token_manager.py +129 -0
- azure/ai/evaluation/_common/__init__.py +9 -1
- azure/ai/evaluation/_common/constants.py +124 -2
- azure/ai/evaluation/_common/evaluation_onedp_client.py +169 -0
- azure/ai/evaluation/_common/onedp/__init__.py +32 -0
- azure/ai/evaluation/_common/onedp/_client.py +166 -0
- azure/ai/evaluation/_common/onedp/_configuration.py +72 -0
- azure/ai/evaluation/_common/onedp/_model_base.py +1232 -0
- azure/ai/evaluation/_common/onedp/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/_serialization.py +2032 -0
- azure/ai/evaluation/_common/onedp/_types.py +21 -0
- azure/ai/evaluation/_common/onedp/_utils/__init__.py +6 -0
- azure/ai/evaluation/_common/onedp/_utils/model_base.py +1232 -0
- azure/ai/evaluation/_common/onedp/_utils/serialization.py +2032 -0
- azure/ai/evaluation/_common/onedp/_validation.py +66 -0
- azure/ai/evaluation/_common/onedp/_vendor.py +50 -0
- azure/ai/evaluation/_common/onedp/_version.py +9 -0
- azure/ai/evaluation/_common/onedp/aio/__init__.py +29 -0
- azure/ai/evaluation/_common/onedp/aio/_client.py +168 -0
- azure/ai/evaluation/_common/onedp/aio/_configuration.py +72 -0
- azure/ai/evaluation/_common/onedp/aio/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/aio/operations/__init__.py +49 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_operations.py +7143 -0
- azure/ai/evaluation/_common/onedp/aio/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/models/__init__.py +358 -0
- azure/ai/evaluation/_common/onedp/models/_enums.py +447 -0
- azure/ai/evaluation/_common/onedp/models/_models.py +5963 -0
- azure/ai/evaluation/_common/onedp/models/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/operations/__init__.py +49 -0
- azure/ai/evaluation/_common/onedp/operations/_operations.py +8951 -0
- azure/ai/evaluation/_common/onedp/operations/_patch.py +21 -0
- azure/ai/evaluation/_common/onedp/py.typed +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/__init__.py +1 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/__init__.py +22 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_operations.py +29 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/buildingblocks/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_operations.py +34 -0
- azure/ai/evaluation/_common/onedp/servicepatterns/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/rai_service.py +578 -69
- azure/ai/evaluation/_common/raiclient/__init__.py +34 -0
- azure/ai/evaluation/_common/raiclient/_client.py +128 -0
- azure/ai/evaluation/_common/raiclient/_configuration.py +87 -0
- azure/ai/evaluation/_common/raiclient/_model_base.py +1235 -0
- azure/ai/evaluation/_common/raiclient/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/_serialization.py +2050 -0
- azure/ai/evaluation/_common/raiclient/_version.py +9 -0
- azure/ai/evaluation/_common/raiclient/aio/__init__.py +29 -0
- azure/ai/evaluation/_common/raiclient/aio/_client.py +130 -0
- azure/ai/evaluation/_common/raiclient/aio/_configuration.py +87 -0
- azure/ai/evaluation/_common/raiclient/aio/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/_operations.py +981 -0
- azure/ai/evaluation/_common/raiclient/aio/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/models/__init__.py +60 -0
- azure/ai/evaluation/_common/raiclient/models/_enums.py +18 -0
- azure/ai/evaluation/_common/raiclient/models/_models.py +651 -0
- azure/ai/evaluation/_common/raiclient/models/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/operations/__init__.py +25 -0
- azure/ai/evaluation/_common/raiclient/operations/_operations.py +1238 -0
- azure/ai/evaluation/_common/raiclient/operations/_patch.py +20 -0
- azure/ai/evaluation/_common/raiclient/py.typed +1 -0
- azure/ai/evaluation/_common/utils.py +505 -27
- azure/ai/evaluation/_constants.py +148 -0
- azure/ai/evaluation/_converters/__init__.py +3 -0
- azure/ai/evaluation/_converters/_ai_services.py +899 -0
- azure/ai/evaluation/_converters/_models.py +467 -0
- azure/ai/evaluation/_converters/_sk_services.py +495 -0
- azure/ai/evaluation/_eval_mapping.py +83 -0
- azure/ai/evaluation/_evaluate/_batch_run/__init__.py +10 -2
- azure/ai/evaluation/_evaluate/_batch_run/_run_submitter_client.py +176 -0
- azure/ai/evaluation/_evaluate/_batch_run/batch_clients.py +82 -0
- azure/ai/evaluation/_evaluate/_batch_run/code_client.py +18 -12
- azure/ai/evaluation/_evaluate/_batch_run/eval_run_context.py +19 -6
- azure/ai/evaluation/_evaluate/_batch_run/proxy_client.py +47 -22
- azure/ai/evaluation/_evaluate/_batch_run/target_run_context.py +18 -2
- azure/ai/evaluation/_evaluate/_eval_run.py +32 -46
- azure/ai/evaluation/_evaluate/_evaluate.py +1809 -142
- azure/ai/evaluation/_evaluate/_evaluate_aoai.py +992 -0
- azure/ai/evaluation/_evaluate/_telemetry/__init__.py +5 -90
- azure/ai/evaluation/_evaluate/_utils.py +237 -42
- azure/ai/evaluation/_evaluator_definition.py +76 -0
- azure/ai/evaluation/_evaluators/_bleu/_bleu.py +80 -28
- azure/ai/evaluation/_evaluators/_code_vulnerability/__init__.py +5 -0
- azure/ai/evaluation/_evaluators/_code_vulnerability/_code_vulnerability.py +119 -0
- azure/ai/evaluation/_evaluators/_coherence/_coherence.py +40 -4
- azure/ai/evaluation/_evaluators/_common/__init__.py +2 -0
- azure/ai/evaluation/_evaluators/_common/_base_eval.py +427 -29
- azure/ai/evaluation/_evaluators/_common/_base_multi_eval.py +63 -0
- azure/ai/evaluation/_evaluators/_common/_base_prompty_eval.py +269 -12
- azure/ai/evaluation/_evaluators/_common/_base_rai_svc_eval.py +74 -9
- azure/ai/evaluation/_evaluators/_common/_conversation_aggregators.py +49 -0
- azure/ai/evaluation/_evaluators/_content_safety/_content_safety.py +73 -53
- azure/ai/evaluation/_evaluators/_content_safety/_hate_unfairness.py +35 -5
- azure/ai/evaluation/_evaluators/_content_safety/_self_harm.py +26 -5
- azure/ai/evaluation/_evaluators/_content_safety/_sexual.py +35 -5
- azure/ai/evaluation/_evaluators/_content_safety/_violence.py +34 -4
- azure/ai/evaluation/_evaluators/_document_retrieval/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_document_retrieval/_document_retrieval.py +442 -0
- azure/ai/evaluation/_evaluators/_eci/_eci.py +6 -3
- azure/ai/evaluation/_evaluators/_f1_score/_f1_score.py +97 -70
- azure/ai/evaluation/_evaluators/_fluency/_fluency.py +39 -3
- azure/ai/evaluation/_evaluators/_gleu/_gleu.py +80 -25
- azure/ai/evaluation/_evaluators/_groundedness/_groundedness.py +230 -20
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_with_query.prompty +30 -29
- azure/ai/evaluation/_evaluators/_groundedness/groundedness_without_query.prompty +19 -14
- azure/ai/evaluation/_evaluators/_intent_resolution/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_intent_resolution/_intent_resolution.py +196 -0
- azure/ai/evaluation/_evaluators/_intent_resolution/intent_resolution.prompty +275 -0
- azure/ai/evaluation/_evaluators/_meteor/_meteor.py +89 -36
- azure/ai/evaluation/_evaluators/_protected_material/_protected_material.py +22 -4
- azure/ai/evaluation/_evaluators/_qa/_qa.py +94 -35
- azure/ai/evaluation/_evaluators/_relevance/_relevance.py +100 -4
- azure/ai/evaluation/_evaluators/_relevance/relevance.prompty +154 -56
- azure/ai/evaluation/_evaluators/_response_completeness/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_response_completeness/_response_completeness.py +202 -0
- azure/ai/evaluation/_evaluators/_response_completeness/response_completeness.prompty +84 -0
- azure/ai/evaluation/_evaluators/_retrieval/_retrieval.py +39 -3
- azure/ai/evaluation/_evaluators/_rouge/_rouge.py +166 -26
- azure/ai/evaluation/_evaluators/_service_groundedness/_service_groundedness.py +38 -7
- azure/ai/evaluation/_evaluators/_similarity/_similarity.py +81 -85
- azure/ai/evaluation/_evaluators/_task_adherence/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_adherence/_task_adherence.py +226 -0
- azure/ai/evaluation/_evaluators/_task_adherence/task_adherence.prompty +101 -0
- azure/ai/evaluation/_evaluators/_task_completion/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_completion/_task_completion.py +177 -0
- azure/ai/evaluation/_evaluators/_task_completion/task_completion.prompty +220 -0
- azure/ai/evaluation/_evaluators/_task_navigation_efficiency/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_task_navigation_efficiency/_task_navigation_efficiency.py +384 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/_tool_call_accuracy.py +298 -0
- azure/ai/evaluation/_evaluators/_tool_call_accuracy/tool_call_accuracy.prompty +166 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/_tool_input_accuracy.py +263 -0
- azure/ai/evaluation/_evaluators/_tool_input_accuracy/tool_input_accuracy.prompty +76 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/_tool_output_utilization.py +225 -0
- azure/ai/evaluation/_evaluators/_tool_output_utilization/tool_output_utilization.prompty +221 -0
- azure/ai/evaluation/_evaluators/_tool_selection/__init__.py +9 -0
- azure/ai/evaluation/_evaluators/_tool_selection/_tool_selection.py +266 -0
- azure/ai/evaluation/_evaluators/_tool_selection/tool_selection.prompty +104 -0
- azure/ai/evaluation/_evaluators/_tool_success/__init__.py +7 -0
- azure/ai/evaluation/_evaluators/_tool_success/_tool_success.py +301 -0
- azure/ai/evaluation/_evaluators/_tool_success/tool_success.prompty +321 -0
- azure/ai/evaluation/_evaluators/_ungrounded_attributes/__init__.py +5 -0
- azure/ai/evaluation/_evaluators/_ungrounded_attributes/_ungrounded_attributes.py +102 -0
- azure/ai/evaluation/_evaluators/_xpia/xpia.py +20 -4
- azure/ai/evaluation/_exceptions.py +24 -1
- azure/ai/evaluation/_http_utils.py +7 -5
- azure/ai/evaluation/_legacy/__init__.py +3 -0
- azure/ai/evaluation/_legacy/_adapters/__init__.py +7 -0
- azure/ai/evaluation/_legacy/_adapters/_check.py +17 -0
- azure/ai/evaluation/_legacy/_adapters/_configuration.py +45 -0
- azure/ai/evaluation/_legacy/_adapters/_constants.py +10 -0
- azure/ai/evaluation/_legacy/_adapters/_errors.py +29 -0
- azure/ai/evaluation/_legacy/_adapters/_flows.py +28 -0
- azure/ai/evaluation/_legacy/_adapters/_service.py +16 -0
- azure/ai/evaluation/_legacy/_adapters/client.py +51 -0
- azure/ai/evaluation/_legacy/_adapters/entities.py +26 -0
- azure/ai/evaluation/_legacy/_adapters/tracing.py +28 -0
- azure/ai/evaluation/_legacy/_adapters/types.py +15 -0
- azure/ai/evaluation/_legacy/_adapters/utils.py +31 -0
- azure/ai/evaluation/_legacy/_batch_engine/__init__.py +9 -0
- azure/ai/evaluation/_legacy/_batch_engine/_config.py +48 -0
- azure/ai/evaluation/_legacy/_batch_engine/_engine.py +477 -0
- azure/ai/evaluation/_legacy/_batch_engine/_exceptions.py +88 -0
- azure/ai/evaluation/_legacy/_batch_engine/_openai_injector.py +132 -0
- azure/ai/evaluation/_legacy/_batch_engine/_result.py +107 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run.py +127 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run_storage.py +128 -0
- azure/ai/evaluation/_legacy/_batch_engine/_run_submitter.py +262 -0
- azure/ai/evaluation/_legacy/_batch_engine/_status.py +25 -0
- azure/ai/evaluation/_legacy/_batch_engine/_trace.py +97 -0
- azure/ai/evaluation/_legacy/_batch_engine/_utils.py +97 -0
- azure/ai/evaluation/_legacy/_batch_engine/_utils_deprecated.py +131 -0
- azure/ai/evaluation/_legacy/_common/__init__.py +3 -0
- azure/ai/evaluation/_legacy/_common/_async_token_provider.py +117 -0
- azure/ai/evaluation/_legacy/_common/_logging.py +292 -0
- azure/ai/evaluation/_legacy/_common/_thread_pool_executor_with_context.py +17 -0
- azure/ai/evaluation/_legacy/prompty/__init__.py +36 -0
- azure/ai/evaluation/_legacy/prompty/_connection.py +119 -0
- azure/ai/evaluation/_legacy/prompty/_exceptions.py +139 -0
- azure/ai/evaluation/_legacy/prompty/_prompty.py +430 -0
- azure/ai/evaluation/_legacy/prompty/_utils.py +663 -0
- azure/ai/evaluation/_legacy/prompty/_yaml_utils.py +99 -0
- azure/ai/evaluation/_model_configurations.py +26 -0
- azure/ai/evaluation/_safety_evaluation/__init__.py +3 -0
- azure/ai/evaluation/_safety_evaluation/_generated_rai_client.py +0 -0
- azure/ai/evaluation/_safety_evaluation/_safety_evaluation.py +917 -0
- azure/ai/evaluation/_user_agent.py +32 -1
- azure/ai/evaluation/_vendor/rouge_score/rouge_scorer.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/scoring.py +0 -4
- azure/ai/evaluation/_vendor/rouge_score/tokenize.py +0 -4
- azure/ai/evaluation/_version.py +2 -1
- azure/ai/evaluation/red_team/__init__.py +22 -0
- azure/ai/evaluation/red_team/_agent/__init__.py +3 -0
- azure/ai/evaluation/red_team/_agent/_agent_functions.py +261 -0
- azure/ai/evaluation/red_team/_agent/_agent_tools.py +461 -0
- azure/ai/evaluation/red_team/_agent/_agent_utils.py +89 -0
- azure/ai/evaluation/red_team/_agent/_semantic_kernel_plugin.py +228 -0
- azure/ai/evaluation/red_team/_attack_objective_generator.py +268 -0
- azure/ai/evaluation/red_team/_attack_strategy.py +49 -0
- azure/ai/evaluation/red_team/_callback_chat_target.py +115 -0
- azure/ai/evaluation/red_team/_default_converter.py +21 -0
- azure/ai/evaluation/red_team/_evaluation_processor.py +505 -0
- azure/ai/evaluation/red_team/_mlflow_integration.py +430 -0
- azure/ai/evaluation/red_team/_orchestrator_manager.py +803 -0
- azure/ai/evaluation/red_team/_red_team.py +1717 -0
- azure/ai/evaluation/red_team/_red_team_result.py +661 -0
- azure/ai/evaluation/red_team/_result_processor.py +1708 -0
- azure/ai/evaluation/red_team/_utils/__init__.py +37 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_eval_chat_target.py +128 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_target.py +601 -0
- azure/ai/evaluation/red_team/_utils/_rai_service_true_false_scorer.py +114 -0
- azure/ai/evaluation/red_team/_utils/constants.py +72 -0
- azure/ai/evaluation/red_team/_utils/exception_utils.py +345 -0
- azure/ai/evaluation/red_team/_utils/file_utils.py +266 -0
- azure/ai/evaluation/red_team/_utils/formatting_utils.py +365 -0
- azure/ai/evaluation/red_team/_utils/logging_utils.py +139 -0
- azure/ai/evaluation/red_team/_utils/metric_mapping.py +73 -0
- azure/ai/evaluation/red_team/_utils/objective_utils.py +46 -0
- azure/ai/evaluation/red_team/_utils/progress_utils.py +252 -0
- azure/ai/evaluation/red_team/_utils/retry_utils.py +218 -0
- azure/ai/evaluation/red_team/_utils/strategy_utils.py +218 -0
- azure/ai/evaluation/simulator/_adversarial_scenario.py +6 -0
- azure/ai/evaluation/simulator/_adversarial_simulator.py +187 -80
- azure/ai/evaluation/simulator/_constants.py +1 -0
- azure/ai/evaluation/simulator/_conversation/__init__.py +138 -11
- azure/ai/evaluation/simulator/_conversation/_conversation.py +6 -2
- azure/ai/evaluation/simulator/_conversation/constants.py +1 -1
- azure/ai/evaluation/simulator/_direct_attack_simulator.py +37 -24
- azure/ai/evaluation/simulator/_helpers/_language_suffix_mapping.py +1 -0
- azure/ai/evaluation/simulator/_indirect_attack_simulator.py +56 -28
- azure/ai/evaluation/simulator/_model_tools/__init__.py +2 -1
- azure/ai/evaluation/simulator/_model_tools/_generated_rai_client.py +225 -0
- azure/ai/evaluation/simulator/_model_tools/_identity_manager.py +12 -10
- azure/ai/evaluation/simulator/_model_tools/_proxy_completion_model.py +100 -45
- azure/ai/evaluation/simulator/_model_tools/_rai_client.py +101 -3
- azure/ai/evaluation/simulator/_model_tools/_template_handler.py +31 -11
- azure/ai/evaluation/simulator/_model_tools/models.py +20 -17
- azure/ai/evaluation/simulator/_simulator.py +43 -19
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.3.dist-info}/METADATA +366 -27
- azure_ai_evaluation-1.13.3.dist-info/RECORD +305 -0
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.3.dist-info}/WHEEL +1 -1
- azure/ai/evaluation/_evaluators/_multimodal/__init__.py +0 -20
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal.py +0 -132
- azure/ai/evaluation/_evaluators/_multimodal/_content_safety_multimodal_base.py +0 -55
- azure/ai/evaluation/_evaluators/_multimodal/_hate_unfairness.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_protected_material.py +0 -124
- azure/ai/evaluation/_evaluators/_multimodal/_self_harm.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_sexual.py +0 -100
- azure/ai/evaluation/_evaluators/_multimodal/_violence.py +0 -100
- azure/ai/evaluation/simulator/_tracing.py +0 -89
- azure_ai_evaluation-1.0.1.dist-info/RECORD +0 -119
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.3.dist-info/licenses}/NOTICE.txt +0 -0
- {azure_ai_evaluation-1.0.1.dist-info → azure_ai_evaluation-1.13.3.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,495 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from datetime import datetime, timezone
|
|
3
|
+
from typing import Any, Dict, List, Tuple, Optional
|
|
4
|
+
|
|
5
|
+
from azure.ai.evaluation._common._experimental import experimental
|
|
6
|
+
|
|
7
|
+
from semantic_kernel.contents import (
|
|
8
|
+
AuthorRole,
|
|
9
|
+
TextContent,
|
|
10
|
+
FunctionCallContent,
|
|
11
|
+
FunctionResultContent,
|
|
12
|
+
)
|
|
13
|
+
from semantic_kernel.contents.chat_message_content import ChatMessageContent
|
|
14
|
+
|
|
15
|
+
from semantic_kernel.agents import (
|
|
16
|
+
ChatCompletionAgent,
|
|
17
|
+
ChatHistoryAgentThread,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
from ._models import (
|
|
21
|
+
Message,
|
|
22
|
+
SystemMessage,
|
|
23
|
+
UserMessage,
|
|
24
|
+
SKToolMessage,
|
|
25
|
+
SKAssistantMessage,
|
|
26
|
+
ToolDefinition,
|
|
27
|
+
ToolCall,
|
|
28
|
+
EvaluatorData,
|
|
29
|
+
SKDeveloperMessage,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@experimental
|
|
34
|
+
class SKAgentConverter:
|
|
35
|
+
"""
|
|
36
|
+
A converter for SK agent data.
|
|
37
|
+
"""
|
|
38
|
+
|
|
39
|
+
def __init__(self):
|
|
40
|
+
try:
|
|
41
|
+
import semantic_kernel as sk
|
|
42
|
+
except ImportError as e:
|
|
43
|
+
raise ImportError(
|
|
44
|
+
"semantic_kernel package is not installed. Please install it to use SKAgentConverter."
|
|
45
|
+
) from e
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
def _transform_tool_definitions(
|
|
49
|
+
tool_list: List[Dict[str, Any]],
|
|
50
|
+
) -> List[ToolDefinition]:
|
|
51
|
+
"""
|
|
52
|
+
Convert verbose tool definition dicts into the `ToolDefinition`s
|
|
53
|
+
:param tool_list: List of tool definitions to transform.
|
|
54
|
+
:type tool_list: List[Dict[str, Any]]
|
|
55
|
+
:return: Transformed list of tool definitions.
|
|
56
|
+
:rtype: List[Dict[str, Any]]
|
|
57
|
+
"""
|
|
58
|
+
# TODO: Add required and default values when also supported by Foundry's converter
|
|
59
|
+
|
|
60
|
+
final_tools: List[ToolDefinition] = []
|
|
61
|
+
|
|
62
|
+
for tool in tool_list:
|
|
63
|
+
filtered_tool = {
|
|
64
|
+
"name": tool["fully_qualified_name"],
|
|
65
|
+
"description": tool.get("description") or "No description",
|
|
66
|
+
"type": "function", # TODO: hardcoded for now.
|
|
67
|
+
"parameters": {
|
|
68
|
+
"type": "object", # Is this always the case?
|
|
69
|
+
"properties": {}, # Will be filled in below
|
|
70
|
+
},
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
for param in tool.get("parameters", []):
|
|
74
|
+
param_name = param.get("name")
|
|
75
|
+
filtered_tool["parameters"]["properties"][param_name] = {
|
|
76
|
+
"type": param["type_"],
|
|
77
|
+
"description": param.get("description") or "No description",
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
final_tools.append(ToolDefinition(**filtered_tool))
|
|
81
|
+
|
|
82
|
+
return final_tools
|
|
83
|
+
|
|
84
|
+
@staticmethod
|
|
85
|
+
def _get_tool_definitions(agent: ChatCompletionAgent) -> list:
|
|
86
|
+
"""
|
|
87
|
+
Get tool definitions from the agent's plugins.
|
|
88
|
+
:param agent: The ChatCompletionAgent from which to retrieve tool definitions.
|
|
89
|
+
:type agent: ChatCompletionAgent
|
|
90
|
+
:return: A list of tool definitions.
|
|
91
|
+
:rtype: list
|
|
92
|
+
"""
|
|
93
|
+
functions = []
|
|
94
|
+
for plugin in agent.kernel.plugins:
|
|
95
|
+
functions_metadata = agent.kernel.plugins[plugin].get_functions_metadata()
|
|
96
|
+
for function in functions_metadata:
|
|
97
|
+
# Serialize metadata to a dictionary
|
|
98
|
+
function_dict = function.model_dump()
|
|
99
|
+
function_dict["fully_qualified_name"] = function.fully_qualified_name
|
|
100
|
+
# function_dict["type"] = "tool_call"
|
|
101
|
+
functions.append(function_dict)
|
|
102
|
+
|
|
103
|
+
return functions
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def _extract_function_tool_definitions(
|
|
107
|
+
agent: ChatCompletionAgent,
|
|
108
|
+
) -> List[ToolDefinition]:
|
|
109
|
+
"""Get and transform tool definitions from the agent."""
|
|
110
|
+
tool_definitions = SKAgentConverter._get_tool_definitions(agent)
|
|
111
|
+
return SKAgentConverter._transform_tool_definitions(tool_definitions)
|
|
112
|
+
|
|
113
|
+
@staticmethod
|
|
114
|
+
def _is_output_role(role):
|
|
115
|
+
return role in (AuthorRole.ASSISTANT, AuthorRole.TOOL)
|
|
116
|
+
|
|
117
|
+
@staticmethod
|
|
118
|
+
async def _get_messages_from_thread(
|
|
119
|
+
thread: ChatHistoryAgentThread,
|
|
120
|
+
) -> List[ChatMessageContent]:
|
|
121
|
+
"""
|
|
122
|
+
Get messages from a thread.
|
|
123
|
+
:param thread: The ChatHistoryAgentThread to get messages from.
|
|
124
|
+
:type thread: ChatHistoryAgentThread
|
|
125
|
+
:return: A list of ChatMessageContent objects.
|
|
126
|
+
:rtype: List[ChatMessageContent]
|
|
127
|
+
"""
|
|
128
|
+
return [msg async for msg in thread.get_messages()]
|
|
129
|
+
|
|
130
|
+
@staticmethod
|
|
131
|
+
async def _get_messages_from_thread_with_agent(
|
|
132
|
+
thread: ChatHistoryAgentThread,
|
|
133
|
+
agent: ChatCompletionAgent = None,
|
|
134
|
+
) -> List[ChatMessageContent]:
|
|
135
|
+
"""
|
|
136
|
+
Get messages from a thread with agent instructions included as a system message if available.
|
|
137
|
+
:param thread: The ChatHistoryAgentThread to get messages from.
|
|
138
|
+
:type thread: ChatHistoryAgentThread
|
|
139
|
+
:param agent: The ChatCompletionAgent to use.
|
|
140
|
+
:type agent: ChatCompletionAgent
|
|
141
|
+
:return: A list of ChatMessageContent objects.
|
|
142
|
+
:rtype: List[ChatMessageContent]
|
|
143
|
+
"""
|
|
144
|
+
messages: List[ChatMessageContent] = []
|
|
145
|
+
|
|
146
|
+
# If agent is provided, with instructions, add it as a system message
|
|
147
|
+
if agent and agent.instructions:
|
|
148
|
+
messages.append(
|
|
149
|
+
ChatMessageContent(
|
|
150
|
+
role=AuthorRole.SYSTEM,
|
|
151
|
+
items=[TextContent(text=agent.instructions)],
|
|
152
|
+
)
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
thread_messages = await SKAgentConverter._get_messages_from_thread(thread)
|
|
156
|
+
messages.extend(thread_messages)
|
|
157
|
+
|
|
158
|
+
return messages
|
|
159
|
+
|
|
160
|
+
@staticmethod
|
|
161
|
+
async def _convert_thread_to_eval_schema(
|
|
162
|
+
thread: ChatHistoryAgentThread,
|
|
163
|
+
turn_index: int,
|
|
164
|
+
agent: ChatCompletionAgent = None,
|
|
165
|
+
):
|
|
166
|
+
"""
|
|
167
|
+
Convert a thread to the evaluation schema.
|
|
168
|
+
:param thread: The ChatHistoryAgentThread containing the conversation history.
|
|
169
|
+
:type thread: ChatHistoryAgentThread
|
|
170
|
+
:param turn_index: The index of the turn in the conversation.
|
|
171
|
+
:type turn_index: int
|
|
172
|
+
:param agent: The ChatCompletionAgent being evaluated.
|
|
173
|
+
:type agent: ChatCompletionAgent
|
|
174
|
+
:return: A dictionary containing the converted data.
|
|
175
|
+
:rtype: dict
|
|
176
|
+
"""
|
|
177
|
+
|
|
178
|
+
messages: List[ChatMessageContent] = await SKAgentConverter._get_messages_from_thread_with_agent(
|
|
179
|
+
thread=thread,
|
|
180
|
+
agent=agent,
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
turns = SKAgentConverter._extract_turns_from_messages(messages, turn_index_to_stop=turn_index)
|
|
184
|
+
|
|
185
|
+
if turn_index >= len(turns):
|
|
186
|
+
raise ValueError(f"Turn {turn_index} not found. Only {len(turns)} turns exist.")
|
|
187
|
+
|
|
188
|
+
return turns[turn_index]
|
|
189
|
+
|
|
190
|
+
@staticmethod
|
|
191
|
+
def _extract_turns_from_messages(
|
|
192
|
+
messages: List[ChatMessageContent],
|
|
193
|
+
turn_index_to_stop: Optional[int] = None,
|
|
194
|
+
) -> List[Tuple[List[Message], List[Message]]]:
|
|
195
|
+
turns = []
|
|
196
|
+
query: List[Message] = []
|
|
197
|
+
response: List[Message] = []
|
|
198
|
+
|
|
199
|
+
queued_items = []
|
|
200
|
+
is_queued_output = None
|
|
201
|
+
|
|
202
|
+
for msg in messages:
|
|
203
|
+
curr_items = SKAgentConverter._process_message_items(msg)
|
|
204
|
+
curr_is_output = SKAgentConverter._is_output_role(msg.role)
|
|
205
|
+
|
|
206
|
+
# Handle the first message to initialize the output/input mode
|
|
207
|
+
if is_queued_output is None:
|
|
208
|
+
queued_items.extend(curr_items)
|
|
209
|
+
is_queued_output = curr_is_output
|
|
210
|
+
continue # This means if chat starts with an assistant/tool message, it's a separate turn
|
|
211
|
+
|
|
212
|
+
# Same group: still within the same input/output block
|
|
213
|
+
if is_queued_output == curr_is_output:
|
|
214
|
+
queued_items.extend(curr_items)
|
|
215
|
+
continue
|
|
216
|
+
|
|
217
|
+
# Transition from input → output
|
|
218
|
+
if not is_queued_output and curr_is_output:
|
|
219
|
+
if queued_items:
|
|
220
|
+
query.extend(queued_items)
|
|
221
|
+
queued_items = curr_items
|
|
222
|
+
is_queued_output = True
|
|
223
|
+
continue
|
|
224
|
+
|
|
225
|
+
# Transition from output → input = End of a turn
|
|
226
|
+
if is_queued_output and not curr_is_output:
|
|
227
|
+
# Transition from output to input: end of turn
|
|
228
|
+
response = list(queued_items)
|
|
229
|
+
turns.append((query, response))
|
|
230
|
+
# New turn's query would be the whole previous
|
|
231
|
+
query = list(query) + response
|
|
232
|
+
if turn_index_to_stop is not None and len(turns) > turn_index_to_stop:
|
|
233
|
+
break
|
|
234
|
+
queued_items = curr_items
|
|
235
|
+
is_queued_output = False
|
|
236
|
+
|
|
237
|
+
# Handle if final message(s) are assistant/tool messages
|
|
238
|
+
if queued_items and is_queued_output:
|
|
239
|
+
response = list(queued_items)
|
|
240
|
+
turns.append((query, response))
|
|
241
|
+
|
|
242
|
+
return turns
|
|
243
|
+
|
|
244
|
+
@staticmethod
|
|
245
|
+
def _convert_messages_to_schema_new(
|
|
246
|
+
messages: List[ChatMessageContent], turn_index: int
|
|
247
|
+
) -> Tuple[List[Message], List[Message]]:
|
|
248
|
+
"""
|
|
249
|
+
Converts messages to schema for a specific turn.
|
|
250
|
+
"""
|
|
251
|
+
turns = SKAgentConverter._extract_turns_from_messages(messages, turn_index_to_stop=turn_index)
|
|
252
|
+
if turn_index >= len(turns):
|
|
253
|
+
raise ValueError(f"Turn {turn_index} not found. Only {len(turns)} turns exist.")
|
|
254
|
+
return turns[turn_index]
|
|
255
|
+
|
|
256
|
+
@staticmethod
|
|
257
|
+
def _safe_json_loads(value: Any) -> Any:
|
|
258
|
+
"""Safely parse a JSON string into a Python object, return original if parsing fails."""
|
|
259
|
+
if isinstance(value, str):
|
|
260
|
+
try:
|
|
261
|
+
return json.loads(value)
|
|
262
|
+
except json.JSONDecodeError:
|
|
263
|
+
return value
|
|
264
|
+
return value
|
|
265
|
+
|
|
266
|
+
@staticmethod
|
|
267
|
+
def _process_message_items(message: ChatMessageContent) -> List[Message]:
|
|
268
|
+
"""
|
|
269
|
+
Processes the items in a message and converts them to the specified schema.
|
|
270
|
+
Args:
|
|
271
|
+
message (Any): The message object to process.
|
|
272
|
+
Returns:
|
|
273
|
+
List[Dict[str, Any]]: A list of dictionaries representing the message items in the specified schema.
|
|
274
|
+
"""
|
|
275
|
+
converted_messages = []
|
|
276
|
+
for item in message.items:
|
|
277
|
+
message_dict = {
|
|
278
|
+
"role": message.role.value,
|
|
279
|
+
"content": [], # will be filled in later
|
|
280
|
+
}
|
|
281
|
+
if "created" in message.metadata:
|
|
282
|
+
message_dict["createdAt"] = SKAgentConverter._convert_timestamp_to_iso(message.metadata["created"])
|
|
283
|
+
if isinstance(item, TextContent):
|
|
284
|
+
item_text = item.to_dict()["text"]
|
|
285
|
+
if message.role == AuthorRole.SYSTEM: # to match other converters
|
|
286
|
+
message_dict["content"] = item_text
|
|
287
|
+
else:
|
|
288
|
+
message_dict["content"] = [{"type": "text", "text": item_text}]
|
|
289
|
+
|
|
290
|
+
elif isinstance(item, FunctionCallContent):
|
|
291
|
+
item_dict = item.to_dict()
|
|
292
|
+
item_func = item_dict["function"]
|
|
293
|
+
arguments = SKAgentConverter._safe_json_loads(item_func["arguments"])
|
|
294
|
+
|
|
295
|
+
message_dict["content"].append(
|
|
296
|
+
{
|
|
297
|
+
"type": "tool_call",
|
|
298
|
+
"tool_call_id": item_dict.get("id", None),
|
|
299
|
+
"name": item_func["name"],
|
|
300
|
+
"arguments": arguments,
|
|
301
|
+
}
|
|
302
|
+
)
|
|
303
|
+
elif isinstance(item, FunctionResultContent):
|
|
304
|
+
item_dict = item.to_dict()
|
|
305
|
+
message_dict["tool_call_id"] = item_dict.get("tool_call_id", None)
|
|
306
|
+
|
|
307
|
+
item_content = SKAgentConverter._safe_json_loads(item_dict["content"])
|
|
308
|
+
|
|
309
|
+
message_dict["content"].append(
|
|
310
|
+
{
|
|
311
|
+
"type": "tool_result",
|
|
312
|
+
"tool_result": item_content,
|
|
313
|
+
}
|
|
314
|
+
)
|
|
315
|
+
else:
|
|
316
|
+
raise Exception(f"Unexpected item type: {type(item)} in message: {message}")
|
|
317
|
+
|
|
318
|
+
if message.role == AuthorRole.SYSTEM:
|
|
319
|
+
convert_message = SystemMessage(**message_dict)
|
|
320
|
+
elif message.role == AuthorRole.USER:
|
|
321
|
+
convert_message = UserMessage(**message_dict)
|
|
322
|
+
elif message.role == AuthorRole.DEVELOPER:
|
|
323
|
+
convert_message = SKDeveloperMessage(**message_dict)
|
|
324
|
+
elif message.role == AuthorRole.ASSISTANT:
|
|
325
|
+
convert_message = SKAssistantMessage(**message_dict)
|
|
326
|
+
elif message.role == AuthorRole.TOOL:
|
|
327
|
+
convert_message = SKToolMessage(**message_dict)
|
|
328
|
+
else:
|
|
329
|
+
raise ValueError(f"Unknown role: {message.role}")
|
|
330
|
+
|
|
331
|
+
converted_messages.append(convert_message)
|
|
332
|
+
return converted_messages
|
|
333
|
+
|
|
334
|
+
@staticmethod
|
|
335
|
+
def is_turn_complete(message: ChatMessageContent) -> bool:
|
|
336
|
+
"""
|
|
337
|
+
Determines if a message completes a turn (assistant provides a response).
|
|
338
|
+
:param message: The message object to check.
|
|
339
|
+
:type message: ChatMessageContent
|
|
340
|
+
:return: True if the message completes a turn, False otherwise.
|
|
341
|
+
:rtype: bool
|
|
342
|
+
"""
|
|
343
|
+
return any(isinstance(item, TextContent) for item in message.items)
|
|
344
|
+
|
|
345
|
+
@staticmethod
|
|
346
|
+
def _convert_timestamp_to_iso(timestamp: float) -> str:
|
|
347
|
+
"""
|
|
348
|
+
Converts a timestamp to ISO format.
|
|
349
|
+
:param timestamp: The timestamp to convert.
|
|
350
|
+
:type timestamp: float
|
|
351
|
+
:return: The timestamp in ISO format.
|
|
352
|
+
:rtype: str
|
|
353
|
+
"""
|
|
354
|
+
created_dt = datetime.fromtimestamp(timestamp, tz=timezone.utc)
|
|
355
|
+
return created_dt.isoformat().replace("+00:00", "Z")
|
|
356
|
+
|
|
357
|
+
async def convert(
|
|
358
|
+
self,
|
|
359
|
+
thread: ChatHistoryAgentThread,
|
|
360
|
+
agent: ChatCompletionAgent,
|
|
361
|
+
turn_index: int,
|
|
362
|
+
) -> dict:
|
|
363
|
+
"""Convert the sdk chat completion agent run to a format suitable for evaluation.
|
|
364
|
+
|
|
365
|
+
:param thread: The ChatHistoryAgentThread containing the conversation history.
|
|
366
|
+
:type thread: ChatHistoryAgentThread
|
|
367
|
+
:param agent: The ChatCompletionAgent being evaluated.
|
|
368
|
+
:type agent: ChatCompletionAgent
|
|
369
|
+
:param turn_index: The index of the turn in the conversation.
|
|
370
|
+
:type turn_index: int
|
|
371
|
+
:return: The converted data in dictionary format.
|
|
372
|
+
:rtype: dict
|
|
373
|
+
"""
|
|
374
|
+
|
|
375
|
+
tool_definitions: List[ToolDefinition] = SKAgentConverter._extract_function_tool_definitions(agent)
|
|
376
|
+
|
|
377
|
+
if not thread:
|
|
378
|
+
raise ValueError("Thread cannot be None")
|
|
379
|
+
|
|
380
|
+
query, response = await SKAgentConverter._convert_thread_to_eval_schema(
|
|
381
|
+
thread=thread,
|
|
382
|
+
turn_index=turn_index,
|
|
383
|
+
agent=agent,
|
|
384
|
+
)
|
|
385
|
+
|
|
386
|
+
result = EvaluatorData(
|
|
387
|
+
query=query,
|
|
388
|
+
response=response,
|
|
389
|
+
tool_definitions=tool_definitions,
|
|
390
|
+
)
|
|
391
|
+
|
|
392
|
+
return json.loads(result.to_json())
|
|
393
|
+
|
|
394
|
+
async def prepare_evaluation_data(
|
|
395
|
+
self,
|
|
396
|
+
threads: List[ChatHistoryAgentThread],
|
|
397
|
+
agent: ChatCompletionAgent,
|
|
398
|
+
filename: Optional[str] = None,
|
|
399
|
+
) -> List[dict]:
|
|
400
|
+
"""
|
|
401
|
+
Prepares evaluation data for a list of threads and optionally writes it to a file.
|
|
402
|
+
|
|
403
|
+
:param threads: List of ChatHistoryAgentThread objects.
|
|
404
|
+
:type threads: List[ChatHistoryAgentThread]
|
|
405
|
+
:param agent: The ChatCompletionAgent being evaluated.
|
|
406
|
+
:type agent: ChatCompletionAgent
|
|
407
|
+
:param filename: Optional file path to save evaluation data as JSONL.
|
|
408
|
+
:type filename: Optional[str]
|
|
409
|
+
:return: List of evaluation data dictionaries.
|
|
410
|
+
:rtype: List[dict]
|
|
411
|
+
"""
|
|
412
|
+
|
|
413
|
+
if isinstance(threads, ChatHistoryAgentThread):
|
|
414
|
+
threads = [threads]
|
|
415
|
+
|
|
416
|
+
all_eval_data: List[dict] = []
|
|
417
|
+
|
|
418
|
+
for thread in threads:
|
|
419
|
+
thread_data = await self._prepare_single_thread_evaluation_data(thread, agent)
|
|
420
|
+
all_eval_data.extend(thread_data)
|
|
421
|
+
|
|
422
|
+
if filename:
|
|
423
|
+
with open(filename, "w", encoding="utf-8") as f:
|
|
424
|
+
for item in all_eval_data:
|
|
425
|
+
f.write(json.dumps(item) + "\n")
|
|
426
|
+
|
|
427
|
+
return all_eval_data
|
|
428
|
+
|
|
429
|
+
async def _prepare_single_thread_evaluation_data(
|
|
430
|
+
self,
|
|
431
|
+
thread: ChatHistoryAgentThread,
|
|
432
|
+
agent: ChatCompletionAgent,
|
|
433
|
+
) -> List[dict]:
|
|
434
|
+
"""
|
|
435
|
+
Prepares evaluation data for a single thread.
|
|
436
|
+
|
|
437
|
+
:param thread: A ChatHistoryAgentThread object.
|
|
438
|
+
:type thread: ChatHistoryAgentThread
|
|
439
|
+
:param agent: The ChatCompletionAgent being evaluated.
|
|
440
|
+
:type agent: ChatCompletionAgent
|
|
441
|
+
:return: A list of evaluation data dictionaries for the thread.
|
|
442
|
+
:rtype: List[dict]
|
|
443
|
+
"""
|
|
444
|
+
thread_eval_data: List[dict] = []
|
|
445
|
+
|
|
446
|
+
tool_definitions: List[ToolDefinition] = self._extract_function_tool_definitions(agent)
|
|
447
|
+
|
|
448
|
+
if not thread:
|
|
449
|
+
raise ValueError("Thread cannot be None")
|
|
450
|
+
|
|
451
|
+
messages: List[ChatMessageContent] = await SKAgentConverter._get_messages_from_thread_with_agent(
|
|
452
|
+
thread=thread,
|
|
453
|
+
agent=agent,
|
|
454
|
+
)
|
|
455
|
+
|
|
456
|
+
turns = SKAgentConverter._extract_turns_from_messages(messages)
|
|
457
|
+
|
|
458
|
+
for query, response in turns:
|
|
459
|
+
turn_eval_data = EvaluatorData(
|
|
460
|
+
query=query,
|
|
461
|
+
response=response,
|
|
462
|
+
tool_definitions=tool_definitions,
|
|
463
|
+
)
|
|
464
|
+
|
|
465
|
+
thread_eval_data.append(json.loads(turn_eval_data.to_json()))
|
|
466
|
+
|
|
467
|
+
return thread_eval_data
|
|
468
|
+
|
|
469
|
+
@staticmethod
|
|
470
|
+
async def _get_thread_turn_indices(thread: ChatHistoryAgentThread) -> List[int]:
|
|
471
|
+
"""
|
|
472
|
+
Determines all complete turn indices in a thread.
|
|
473
|
+
|
|
474
|
+
:param thread: The ChatHistoryAgentThread to analyze.
|
|
475
|
+
:type thread: ChatHistoryAgentThread
|
|
476
|
+
:return: A list of valid turn indices (0-based).
|
|
477
|
+
:rtype: List[int]
|
|
478
|
+
"""
|
|
479
|
+
|
|
480
|
+
messages: List[ChatMessageContent] = await SKAgentConverter._get_messages_from_thread(thread)
|
|
481
|
+
if not messages:
|
|
482
|
+
return []
|
|
483
|
+
|
|
484
|
+
# Extract turns from the messages
|
|
485
|
+
turns = SKAgentConverter._extract_turns_from_messages(messages)
|
|
486
|
+
|
|
487
|
+
# Return indices of valid turns
|
|
488
|
+
return SKAgentConverter._get_turn_indices(messages) if turns else []
|
|
489
|
+
|
|
490
|
+
@staticmethod
|
|
491
|
+
def _get_turn_indices(messages: List[ChatMessageContent]) -> List[int]:
|
|
492
|
+
"""
|
|
493
|
+
Returns a list of valid turn indices.
|
|
494
|
+
"""
|
|
495
|
+
return list(range(len(SKAgentConverter._extract_turns_from_messages(messages))))
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# ---------------------------------------------------------
|
|
2
|
+
# Copyright (c) Microsoft Corporation. All rights reserved.
|
|
3
|
+
# ---------------------------------------------------------
|
|
4
|
+
|
|
5
|
+
# Note: This was removed from the normal constants file due to circular import issues.
|
|
6
|
+
|
|
7
|
+
# In the future, it would be nice to instead rely on the id value
|
|
8
|
+
# of each eval class, but I wouldn't like to rely on those before
|
|
9
|
+
# we simplify them into version-less, static values, instead of the
|
|
10
|
+
# problematic registry references they currently are.
|
|
11
|
+
|
|
12
|
+
# Import all evals
|
|
13
|
+
from azure.ai.evaluation._evaluators._eci._eci import ECIEvaluator
|
|
14
|
+
from azure.ai.evaluation._evaluators._task_completion import _TaskCompletionEvaluator
|
|
15
|
+
from azure.ai.evaluation._evaluators._tool_input_accuracy import _ToolInputAccuracyEvaluator
|
|
16
|
+
from azure.ai.evaluation._evaluators._tool_selection import _ToolSelectionEvaluator
|
|
17
|
+
from azure.ai.evaluation._evaluators._tool_success import _ToolSuccessEvaluator
|
|
18
|
+
from azure.ai.evaluation._evaluators._task_navigation_efficiency import _TaskNavigationEfficiencyEvaluator
|
|
19
|
+
from azure.ai.evaluation import (
|
|
20
|
+
BleuScoreEvaluator,
|
|
21
|
+
CodeVulnerabilityEvaluator,
|
|
22
|
+
CoherenceEvaluator,
|
|
23
|
+
ContentSafetyEvaluator,
|
|
24
|
+
DocumentRetrievalEvaluator,
|
|
25
|
+
F1ScoreEvaluator,
|
|
26
|
+
FluencyEvaluator,
|
|
27
|
+
GleuScoreEvaluator,
|
|
28
|
+
GroundednessEvaluator,
|
|
29
|
+
GroundednessProEvaluator,
|
|
30
|
+
HateUnfairnessEvaluator,
|
|
31
|
+
IndirectAttackEvaluator,
|
|
32
|
+
IntentResolutionEvaluator,
|
|
33
|
+
MeteorScoreEvaluator,
|
|
34
|
+
ProtectedMaterialEvaluator,
|
|
35
|
+
QAEvaluator,
|
|
36
|
+
RelevanceEvaluator,
|
|
37
|
+
ResponseCompletenessEvaluator,
|
|
38
|
+
RetrievalEvaluator,
|
|
39
|
+
RougeScoreEvaluator,
|
|
40
|
+
SelfHarmEvaluator,
|
|
41
|
+
SexualEvaluator,
|
|
42
|
+
SimilarityEvaluator,
|
|
43
|
+
TaskAdherenceEvaluator,
|
|
44
|
+
ToolCallAccuracyEvaluator,
|
|
45
|
+
UngroundedAttributesEvaluator,
|
|
46
|
+
ViolenceEvaluator,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
EVAL_CLASS_MAP = {
|
|
50
|
+
BleuScoreEvaluator: "bleu_score",
|
|
51
|
+
CodeVulnerabilityEvaluator: "code_vulnerability",
|
|
52
|
+
CoherenceEvaluator: "coherence",
|
|
53
|
+
ContentSafetyEvaluator: "content_safety",
|
|
54
|
+
DocumentRetrievalEvaluator: "document_retrieval",
|
|
55
|
+
ECIEvaluator: "eci",
|
|
56
|
+
F1ScoreEvaluator: "f1_score",
|
|
57
|
+
FluencyEvaluator: "fluency",
|
|
58
|
+
GleuScoreEvaluator: "gleu_score",
|
|
59
|
+
GroundednessEvaluator: "groundedness",
|
|
60
|
+
GroundednessProEvaluator: "groundedness_pro",
|
|
61
|
+
HateUnfairnessEvaluator: "hate_unfairness",
|
|
62
|
+
IndirectAttackEvaluator: "indirect_attack",
|
|
63
|
+
IntentResolutionEvaluator: "intent_resolution",
|
|
64
|
+
MeteorScoreEvaluator: "meteor_score",
|
|
65
|
+
ProtectedMaterialEvaluator: "protected_material",
|
|
66
|
+
QAEvaluator: "qa",
|
|
67
|
+
RelevanceEvaluator: "relevance",
|
|
68
|
+
ResponseCompletenessEvaluator: "response_completeness",
|
|
69
|
+
RetrievalEvaluator: "retrieval",
|
|
70
|
+
RougeScoreEvaluator: "rouge_score",
|
|
71
|
+
SelfHarmEvaluator: "self_harm",
|
|
72
|
+
SexualEvaluator: "sexual",
|
|
73
|
+
SimilarityEvaluator: "similarity",
|
|
74
|
+
TaskAdherenceEvaluator: "task_adherence",
|
|
75
|
+
_TaskCompletionEvaluator: "task_completion",
|
|
76
|
+
_TaskNavigationEfficiencyEvaluator: "task_navigation_efficiency",
|
|
77
|
+
ToolCallAccuracyEvaluator: "tool_call_accuracy",
|
|
78
|
+
_ToolInputAccuracyEvaluator: "tool_input_accuracy",
|
|
79
|
+
_ToolSelectionEvaluator: "tool_selection",
|
|
80
|
+
_ToolSuccessEvaluator: "tool_success",
|
|
81
|
+
UngroundedAttributesEvaluator: "ungrounded_attributes",
|
|
82
|
+
ViolenceEvaluator: "violence",
|
|
83
|
+
}
|
|
@@ -3,7 +3,15 @@
|
|
|
3
3
|
# ---------------------------------------------------------
|
|
4
4
|
from .eval_run_context import EvalRunContext
|
|
5
5
|
from .code_client import CodeClient
|
|
6
|
-
from .proxy_client import ProxyClient
|
|
6
|
+
from .proxy_client import ProxyClient, ProxyRun
|
|
7
|
+
from ._run_submitter_client import RunSubmitterClient
|
|
7
8
|
from .target_run_context import TargetRunContext
|
|
8
9
|
|
|
9
|
-
__all__ = [
|
|
10
|
+
__all__ = [
|
|
11
|
+
"CodeClient",
|
|
12
|
+
"ProxyClient",
|
|
13
|
+
"EvalRunContext",
|
|
14
|
+
"TargetRunContext",
|
|
15
|
+
"ProxyRun",
|
|
16
|
+
"RunSubmitterClient",
|
|
17
|
+
]
|