デプロイされたモデル、プロンプト エージェント、またはホストされているエージェントにテスト クエリを送信し、実行時に生成された応答を評価します。
前提条件
-
クラウド評価の前提条件とクライアントのセットアップを完了します。
- 入力クエリの JSONL または CSV データセット。
- デプロイされたモデル、プロンプト エージェント、またはターゲットとして使用するホステッド エージェント。
この例では、「SDK クライアントのセットアップ」で構成された SDK クライアントを使用します。
モデル ターゲットを評価する
実行時にデプロイされたモデルにクエリを送信します。
azure_ai_target_completions データ ソースの種類とazure_ai_modelターゲットを使用して、応答を評価します。 入力データにはクエリが含まれています。 モデルによって応答が生成され、評価されます。
Note
モデル ルーターをターゲット モデルとして使用できます。 モデル ルーターは、評価ターゲットとして のみ サポートされます。 他の評価機能のモデルとして選択することはできません。
メッセージ テンプレートとターゲットを定義する
input_messages テンプレートは、クエリをモデルに送信する方法を制御します。 入力データからフィールドを参照するには、 {{item.query}} を使用します。 評価するモデルと省略可能なサンプリング パラメーターを指定します。
input_messages = {
"type": "template",
"template": [
{
"type": "message",
"role": "user",
"content": {
"type": "input_text",
"text": "{{item.query}}"
}
}
]
}
target = {
"type": "azure_ai_model",
"model": "gpt-5-mini",
"sampling_params": {
"top_p": 1.0,
"max_completion_tokens": 2048,
},
}
C# サンプルでは、「 評価と実行の作成」でメッセージ テンプレートとモデル ターゲットを定義します。
const inputMessages = {
type: "template",
template: [
{
type: "message",
role: "user",
content: { type: "input_text", text: "{{item.query}}" },
},
],
};
const target = {
type: "azure_ai_model",
model: "gpt-5-mini",
sampling_params: {
top_p: 1.0,
max_completion_tokens: 2048,
},
};
[ 評価と実行の作成] の下の [cURL] タブに表示される JSON 要求本文で、メッセージ テンプレートとターゲットを直接定義します。
エバリュエーターとデータ マッピングを設定する
data_mappingの{{item.field}}を使用して入力データを参照し、{{sample.output_text}}モデルの生成された応答を参照します。 各エバリュエーターに必要な入力を含めます。
data_source_config = DataSourceConfigCustom(
type="custom",
item_schema={
"type": "object",
"properties": {
"query": {"type": "string"},
},
"required": ["query"],
},
include_sample_schema=True,
)
testing_criteria = [
TestingCriterionAzureAIEvaluator(
type="azure_ai_evaluator",
name="coherence",
evaluator_name="builtin.coherence",
initialization_parameters={"model": model_deployment_name},
data_mapping={
"query": "{{item.query}}",
"response": "{{sample.output_text}}",
},
),
TestingCriterionAzureAIEvaluator(
type="azure_ai_evaluator",
name="violence",
evaluator_name="builtin.violence",
data_mapping={
"query": "{{item.query}}",
"response": "{{sample.output_text}}",
},
),
]
C# サンプルでは、評価と 実行の作成でデータ ソースの構成とエバリュエーターを定義します。
const dataSourceConfig = {
type: "custom",
item_schema: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"],
},
include_sample_schema: true,
};
const testingCriteria = [
{
type: "azure_ai_evaluator",
name: "coherence",
evaluator_name: "builtin.coherence",
initialization_parameters: { model: modelDeploymentName },
data_mapping: {
query: "{{item.query}}",
response: "{{sample.output_text}}",
},
},
{
type: "azure_ai_evaluator",
name: "violence",
evaluator_name: "builtin.violence",
data_mapping: {
query: "{{item.query}}",
response: "{{sample.output_text}}",
},
},
];
評価の 作成と実行の cURL タブに表示される JSON 要求本文で、エバリュエーターの構成を直接定義します。
評価を作成して実行する
eval_object = openai_client.evals.create(
name="Model Target Evaluation",
data_source_config=data_source_config,
testing_criteria=testing_criteria,
)
data_source = {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": data_id,
},
"input_messages": input_messages,
"target": target,
}
eval_run = openai_client.evals.runs.create(
eval_id=eval_object.id,
name="model-target-evaluation",
data_source=data_source,
)
object dataSourceConfig = new
{
type = "custom",
item_schema = new
{
type = "object",
properties = new { query = new { type = "string" } },
required = new[] { "query" }
},
include_sample_schema = true
};
object[] testingCriteria =
[
new
{
type = "azure_ai_evaluator",
name = "coherence",
evaluator_name = "builtin.coherence",
initialization_parameters = new { model = modelDeploymentName },
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
},
new
{
type = "azure_ai_evaluator",
name = "violence",
evaluator_name = "builtin.violence",
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
}
];
BinaryData evaluationData = BinaryData.FromObjectAsJson(new
{
name = "Model Target Evaluation",
data_source_config = dataSourceConfig,
testing_criteria = testingCriteria
});
using BinaryContent evaluationContent = BinaryContent.Create(evaluationData);
ClientResult evaluation = await evaluationClient.CreateEvaluationAsync(
evaluationContent);
string evaluationId = GetString(evaluation, "id");
object dataSource = new
{
type = "azure_ai_target_completions",
source = new { type = "file_id", id = dataId },
input_messages = new
{
type = "template",
template = new[]
{
new
{
type = "message",
role = "user",
content = new
{
type = "input_text",
text = "{{item.query}}"
}
}
}
},
target = new
{
type = "azure_ai_model",
model = modelDeploymentName,
sampling_params = new
{
top_p = 1.0f,
max_completion_tokens = 2048
}
}
};
BinaryData runData = BinaryData.FromObjectAsJson(new
{
name = "model-target-evaluation",
data_source = dataSource
});
using BinaryContent runContent = BinaryContent.Create(runData);
ClientResult evaluationRun = await evaluationClient.CreateEvaluationRunAsync(
evaluationId: evaluationId,
content: runContent);
Console.WriteLine($"Evaluation run created: {GetString(evaluationRun, "id")}");
リファレンス: EvaluationClient プロトコル メソッド
const evalObject = await openaiClient.evals.create({
name: "Model Target Evaluation",
data_source_config: dataSourceConfig,
testing_criteria: testingCriteria,
});
const dataSource = {
type: "azure_ai_target_completions",
source: {
type: "file_id",
id: dataId,
},
input_messages: inputMessages,
target: target,
};
const evalRun = await openaiClient.evals.runs.create(evalObject.id, {
name: "model-target-evaluation",
data_source: dataSource,
});
curl --request POST \
--url "https://${ACCOUNT}.services.ai.azure.com/api/projects/${PROJECT}/openai/v1/evals/${EVAL_ID}/runs" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"name": "model-target-evaluation",
"data_source": {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": "YOUR_DATASET_ID"
},
"input_messages": {
"type": "template",
"template": [
{
"type": "message",
"role": "user",
"content": {
"type": "input_text",
"text": "{{item.query}}"
}
}
]
},
"target": {
"type": "azure_ai_model",
"model": "gpt-5-mini",
"sampling_params": {
"top_p": 1.0,
"max_completion_tokens": 2048
}
}
}
}'
実行可能な完全な例については、GitHubの sample_model_evaluation.py を参照してください。 完了するまでポーリングして結果を解釈するには、クラウド評価の結果を取得するを参照してください。
完了した実行応答には、ターゲット待機時間パーセンタイルと推定モデル推論コストを含めることができます。 フィールド定義、可用性ルール、コスト見積もりの制限については、 モデルターゲットの待機時間と推定コストを確認 するを参照してください。
ヒント
別の評価実行を追加するには、同じコードを使用します。
エージェントのターゲットを評価する
実行時に Foundry エージェントにクエリを送信し、azure_ai_target_completionsターゲットでazure_ai_agentデータ ソースの種類を使用して応答を評価します。 このシナリオは、 プロンプト エージェント と ホステッド エージェントの両方で機能します。
ヒント
応答プロトコルを使用するホスト型エージェントは、次に示すのと同じコード サンプルで動作します。 呼び出しプロトコルを使用するホステッド エージェントの場合、 input_messages 形式は異なります。 詳細については、 ホストされるエージェント呼び出しプロトコル を参照してください。
メッセージ テンプレートとターゲットを定義する
input_messages テンプレートは、エージェントにクエリを送信する方法を制御します。 入力データからフィールドを参照するには、 {{item.query}} を使用します。 名前で評価するエージェントを指定します。
input_messages = {
"type": "template",
"template": [
{
"type": "message",
"role": "developer",
"content": {
"type": "input_text",
"text": "You are a helpful assistant. Answer clearly and safely."
}
},
{
"type": "message",
"role": "user",
"content": {
"type": "input_text",
"text": "{{item.query}}"
}
}
]
}
target = {
"type": "azure_ai_agent",
"name": "my-agent",
"version": "1" # Optional. Uses latest version if omitted.
}
C# サンプルでは、「 評価と実行の作成」でメッセージ テンプレートとエージェント ターゲットを定義します。
const inputMessages = {
type: "template",
template: [
{
type: "message",
role: "developer",
content: {
type: "input_text",
text: "You are a helpful assistant. Answer clearly and safely.",
},
},
{
type: "message",
role: "user",
content: { type: "input_text", text: "{{item.query}}" },
},
],
};
const target = {
type: "azure_ai_agent",
name: "my-agent",
version: "1", // Optional. Uses latest version if omitted.
};
[ 評価と実行の作成] の下の [cURL] タブに表示される JSON 要求本文で、メッセージ テンプレートとターゲットを直接定義します。
エバリュエーターとデータ マッピングを設定する
エージェントが実行時に応答を生成する場合は、{{sample.*}}data_mapping変数を使用してエージェントの出力を参照します。
| 変数 |
説明 |
用途 |
{{sample.output_text}} |
エージェントのプレーン テキスト応答。 |
文字列応答を必要とするエバリュエーター (たとえば、 coherence と violence)。 |
{{sample.output_items}} |
ツール呼び出しを含む、エージェントの構造化された JSON 出力。 |
完全な対話コンテキスト (たとえば、 task_adherence) を必要とするエバリュエーター。 |
{{item.field}} |
入力データのフィールド。 |
queryやground_truthなどの入力フィールド。 |
必要なすべてのエバリュエーター入力を明示的にマップします。 この例のほとんどのエバリュエーターは、応答に {{sample.output_text}} を使用します。 代わりに、タスクの準拠には、 {{sample.output_items}}の完全な構造化された相互作用が必要です。
ヒント
query フィールドには、システム メッセージや会話履歴など、構造化された JSON を含めることができます。
task_adherenceなどの一部のエージェント エバリュエーターは、より正確なスコア付けにこのコンテキストを使用します。 クエリの書式設定の詳細については、 エージェント エバリュエーターを参照してください。
data_source_config = DataSourceConfigCustom(
type="custom",
item_schema={
"type": "object",
"properties": {
"query": {"type": "string"},
},
"required": ["query"],
},
include_sample_schema=True,
)
testing_criteria = [
TestingCriterionAzureAIEvaluator(
type="azure_ai_evaluator",
name="coherence",
evaluator_name="builtin.coherence",
initialization_parameters={"model": model_deployment_name},
data_mapping={
"query": "{{item.query}}",
"response": "{{sample.output_text}}",
},
),
TestingCriterionAzureAIEvaluator(
type="azure_ai_evaluator",
name="violence",
evaluator_name="builtin.violence",
data_mapping={
"query": "{{item.query}}",
"response": "{{sample.output_text}}",
},
),
TestingCriterionAzureAIEvaluator(
type="azure_ai_evaluator",
name="task_adherence",
evaluator_name="builtin.task_adherence",
initialization_parameters={"model": model_deployment_name},
data_mapping={
"query": "{{item.query}}",
"response": "{{sample.output_items}}",
},
),
]
C# サンプルでは、評価と 実行の作成でデータ ソースの構成とエバリュエーターを定義します。
const dataSourceConfig = {
type: "custom",
item_schema: {
type: "object",
properties: { query: { type: "string" } },
required: ["query"],
},
include_sample_schema: true,
};
const testingCriteria = [
{
type: "azure_ai_evaluator",
name: "coherence",
evaluator_name: "builtin.coherence",
initialization_parameters: { model: modelDeploymentName },
data_mapping: {
query: "{{item.query}}",
response: "{{sample.output_text}}",
},
},
{
type: "azure_ai_evaluator",
name: "violence",
evaluator_name: "builtin.violence",
data_mapping: {
query: "{{item.query}}",
response: "{{sample.output_text}}",
},
},
{
type: "azure_ai_evaluator",
name: "task_adherence",
evaluator_name: "builtin.task_adherence",
initialization_parameters: { model: modelDeploymentName },
data_mapping: {
query: "{{item.query}}",
response: "{{sample.output_items}}",
},
},
];
評価の 作成と実行の cURL タブに表示される JSON 要求本文で、エバリュエーターの構成を直接定義します。
評価を作成して実行する
eval_object = openai_client.evals.create(
name="Agent Target Evaluation",
data_source_config=data_source_config,
testing_criteria=testing_criteria,
)
data_source = {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": data_id,
},
"input_messages": input_messages,
"target": target,
}
agent_eval_run = openai_client.evals.runs.create(
eval_id=eval_object.id,
name="agent-target-evaluation",
data_source=data_source,
)
object dataSourceConfig = new
{
type = "custom",
item_schema = new
{
type = "object",
properties = new { query = new { type = "string" } },
required = new[] { "query" }
},
include_sample_schema = true
};
object[] testingCriteria =
[
new
{
type = "azure_ai_evaluator",
name = "coherence",
evaluator_name = "builtin.coherence",
initialization_parameters = new { model = modelDeploymentName },
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
},
new
{
type = "azure_ai_evaluator",
name = "violence",
evaluator_name = "builtin.violence",
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
},
new
{
type = "azure_ai_evaluator",
name = "task_adherence",
evaluator_name = "builtin.task_adherence",
initialization_parameters = new { model = modelDeploymentName },
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_items}}"
}
}
];
BinaryData evaluationData = BinaryData.FromObjectAsJson(new
{
name = "Agent Target Evaluation",
data_source_config = dataSourceConfig,
testing_criteria = testingCriteria
});
using BinaryContent evaluationContent = BinaryContent.Create(evaluationData);
ClientResult evaluation = await evaluationClient.CreateEvaluationAsync(
evaluationContent);
string evaluationId = GetString(evaluation, "id");
object dataSource = new
{
type = "azure_ai_target_completions",
source = new { type = "file_id", id = dataId },
input_messages = new
{
type = "template",
template = new[]
{
new
{
type = "message",
role = "developer",
content = new
{
type = "input_text",
text = "You are a helpful assistant. Answer clearly and safely."
}
},
new
{
type = "message",
role = "user",
content = new
{
type = "input_text",
text = "{{item.query}}"
}
}
}
},
target = new
{
type = "azure_ai_agent",
name = "my-agent",
version = "1"
}
};
BinaryData runData = BinaryData.FromObjectAsJson(new
{
name = "agent-target-evaluation",
data_source = dataSource
});
using BinaryContent runContent = BinaryContent.Create(runData);
ClientResult evaluationRun = await evaluationClient.CreateEvaluationRunAsync(
evaluationId: evaluationId,
content: runContent);
Console.WriteLine($"Evaluation run created: {GetString(evaluationRun, "id")}");
リファレンス: EvaluationClient プロトコル メソッド
const evalObject = await openaiClient.evals.create({
name: "Agent Target Evaluation",
data_source_config: dataSourceConfig,
testing_criteria: testingCriteria,
});
const dataSource = {
type: "azure_ai_target_completions",
source: {
type: "file_id",
id: dataId,
},
input_messages: inputMessages,
target: target,
};
const agentEvalRun = await openaiClient.evals.runs.create(evalObject.id, {
name: "agent-target-evaluation",
data_source: dataSource,
});
curl --request POST \
--url "https://${ACCOUNT}.services.ai.azure.com/api/projects/${PROJECT}/openai/v1/evals/${EVAL_ID}/runs" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"name": "agent-target-evaluation",
"data_source": {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": "YOUR_DATASET_ID"
},
"input_messages": {
"type": "template",
"template": [
{
"type": "message",
"role": "developer",
"content": {
"type": "input_text",
"text": "You are a helpful assistant. Answer clearly and safely."
}
},
{
"type": "message",
"role": "user",
"content": {
"type": "input_text",
"text": "{{item.query}}"
}
}
]
},
"target": {
"type": "azure_ai_agent",
"name": "my-agent",
"version": "1"
}
}
}'
実行可能な完全な例については、GitHubのsample_agent_evaluation.pyを参照してください。 完了するまでポーリングして結果を解釈するには、クラウド評価の結果を取得するを参照してください。
ホストされるエージェント呼び出しプロトコル
呼び出しプロトコルのみをサポートするホストエージェントは、同じazure_ai_agentターゲットの種類を使用しますが、フリーフォームのinput_messages形式が必要です。 構造化されたテンプレート形式の代わりに、エージェントの /invocations 要求本文に直接マップする JSON オブジェクトを指定します。
{{item.*}}プレースホルダーを使用して、入力データのフィールドを置き換えます。
ホストされるエージェントが応答プロトコルと呼び出しプロトコルの両方をサポートしている場合、サービスは既定で応答プロトコルを使用します。 これらのエージェントについては、「メッセージ テンプレートとターゲットの定義」に示されている構造化input_messages テンプレートを使用します。
input_messages = {"message": "{{item.query}}"}
target = {
"type": "azure_ai_agent",
"name": "my-hosted-agent", # Replace with your hosted agent name
"version": "1",
}
現在の JavaScript/TypeScript SDK サンプルでは、呼び出しプロトコルによるホストエージェントの評価は示されていません。 このフローには、[Python] タブまたは [cURL] タブを使用します。
評価を作成して実行する
eval_object = openai_client.evals.create(
name="Hosted Agent Invocations Evaluation",
data_source_config=data_source_config,
testing_criteria=testing_criteria,
)
data_source = {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": data_id,
},
"input_messages": input_messages,
"target": target,
}
eval_run = openai_client.evals.runs.create(
eval_id=eval_object.id,
name="hosted-agent-invocations-evaluation",
data_source=data_source,
)
object dataSourceConfig = new
{
type = "custom",
item_schema = new
{
type = "object",
properties = new { query = new { type = "string" } },
required = new[] { "query" }
},
include_sample_schema = true
};
object[] testingCriteria =
[
new
{
type = "azure_ai_evaluator",
name = "coherence",
evaluator_name = "builtin.coherence",
initialization_parameters = new { model = modelDeploymentName },
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
},
new
{
type = "azure_ai_evaluator",
name = "violence",
evaluator_name = "builtin.violence",
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_text}}"
}
},
new
{
type = "azure_ai_evaluator",
name = "task_adherence",
evaluator_name = "builtin.task_adherence",
initialization_parameters = new { model = modelDeploymentName },
data_mapping = new
{
query = "{{item.query}}",
response = "{{sample.output_items}}"
}
}
];
BinaryData evaluationData = BinaryData.FromObjectAsJson(new
{
name = "Hosted Agent Invocations Evaluation",
data_source_config = dataSourceConfig,
testing_criteria = testingCriteria
});
using BinaryContent evaluationContent = BinaryContent.Create(evaluationData);
ClientResult evaluation = await evaluationClient.CreateEvaluationAsync(
evaluationContent);
string evaluationId = GetString(evaluation, "id");
object dataSource = new
{
type = "azure_ai_target_completions",
source = new { type = "file_id", id = dataId },
input_messages = new { message = "{{item.query}}" },
target = new
{
type = "azure_ai_agent",
name = "my-hosted-agent",
version = "1"
}
};
BinaryData runData = BinaryData.FromObjectAsJson(new
{
name = "hosted-agent-invocations-evaluation",
data_source = dataSource
});
using BinaryContent runContent = BinaryContent.Create(runData);
ClientResult evaluationRun = await evaluationClient.CreateEvaluationRunAsync(
evaluationId: evaluationId,
content: runContent);
Console.WriteLine($"Evaluation run created: {GetString(evaluationRun, "id")}");
リファレンス: EvaluationClient プロトコル メソッド
現在の JavaScript/TypeScript SDK サンプルでは、呼び出しプロトコルによるホストエージェントの評価は示されていません。 このフローには、[Python] タブまたは [cURL] タブを使用します。
curl --request POST \
--url "https://${ACCOUNT}.services.ai.azure.com/api/projects/${PROJECT}/openai/v1/evals/${EVAL_ID}/runs" \
--header "Authorization: Bearer ${TOKEN}" \
--header "Content-Type: application/json" \
--data '{
"name": "hosted-agent-invocations-evaluation",
"data_source": {
"type": "azure_ai_target_completions",
"source": {
"type": "file_id",
"id": "YOUR_DATASET_ID"
},
"input_messages": {
"message": "{{item.query}}"
},
"target": {
"type": "azure_ai_agent",
"name": "my-hosted-agent",
"version": "1"
}
}
}'
エバリュエーターのセットアップとデータ マッピングは、 プロンプト エージェントの評価の場合と同じです。 エージェントのテキスト応答には {{sample.output_text}} を使用し、ツール呼び出しを含む完全な構造化出力には {{sample.output_items}} を使用します。
関連するコンテンツ