Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
Azure AI Foundry project.
"""

import os
import os, time

from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
Expand All @@ -31,30 +31,59 @@
EvaluatorIds,
EvaluatorConfiguration,
AgentEvaluationSamplingConfiguration,
AgentEvaluationRedactionConfiguration
)
from dotenv import load_dotenv

load_dotenv()

endpoint = os.environ["PROJECT_ENDPOINT"]
model_deployment_name = os.environ["MODEL_DEPLOYMENT_NAME"]


with DefaultAzureCredential(exclude_interactive_browser_credential=False) as credential:

with AIProjectClient(endpoint=endpoint, credential=credential) as project_client:

# [START evaluations_agent_sample]
agent = project_client.agents.create_agent(
model=model_deployment_name,
name="my-agent",
instructions="You are helpful agent",
)
print(f"Created agent, agent ID: {agent.id}")

thread = project_client.agents.create_thread()
print(f"Created thread, thread ID: {thread.id}")

message = project_client.agents.create_message(thread_id=thread.id, role="user", content="Hello, tell me a joke")
print(f"Created message, message ID: {message.id}")

run = project_client.agents.create_run(thread_id=thread.id, agent_id=agent.id)

# Poll the run as long as run status is queued or in progress
while run.status in ["queued", "in_progress", "requires_action"]:
# Wait for a second
time.sleep(1)
run = project_client.agents.get_run(thread_id=thread.id, run_id=run.id)
print(f"Run status: {run.status}")


agent_evaluation_request = AgentEvaluationRequest(
run_id="run-id",
thread_id="thread-id",
run_id=run.id,
thread_id=thread.id,
evaluators={
"violence": EvaluatorConfiguration(
id=EvaluatorIds.VIOLENCE,
)
},
sampling_configuration=AgentEvaluationSamplingConfiguration(
name="test",
sampling_percent=0.5,
sampling_percent=100,
max_request_rate=100,
),
redaction_configuration=AgentEvaluationRedactionConfiguration(
redact_score_properties=False,
),
app_insights_connection_string=project_client.telemetry.get_connection_string(),
)
Expand Down
Loading