Skip to content

Commit 180d1b0

Browse files
committed
feat(EvalSchema): updating eval schema
Specifically updating evaluation and evaluationSet schema to adhere to agent definitions. # Conflicts: # pyproject.toml
1 parent 84ae313 commit 180d1b0

7 files changed

Lines changed: 300 additions & 17 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "uipath"
3-
version = "2.1.67"
3+
version = "2.1.68"
44
description = "Python SDK and CLI for UiPath Platform, enabling programmatic interaction with automation services, process management, and deployment tools."
55
readme = { file = "README.md", content-type = "text/markdown" }
66
requires-python = ">=3.10"

src/uipath/_cli/_evals/_models/_evaluation_set.py

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
from pydantic.alias_generators import to_camel
66

77

8+
class EvaluationSimulationTool(BaseModel):
9+
name: str = Field(..., alias="name")
10+
11+
812
class EvaluationItem(BaseModel):
913
"""Individual evaluation item within an evaluation set."""
1014

@@ -14,15 +18,19 @@ class EvaluationItem(BaseModel):
1418
name: str
1519
inputs: Dict[str, Any]
1620
expected_output: Dict[str, Any]
17-
expected_agent_behavior: str = ""
18-
simulation_instructions: str = ""
19-
simulate_input: bool = False
20-
input_generation_instructions: str = ""
21-
simulate_tools: bool = False
22-
tools_to_simulate: List[str] = Field(default_factory=list)
23-
eval_set_id: str
24-
created_at: str
25-
updated_at: str
21+
expected_agent_behavior: str = Field(default="", alias="expectedAgentBehavior")
22+
simulation_instructions: str = Field(default="", alias="simulationInstructions")
23+
simulate_input: bool = Field(default=False, alias="simulateInput")
24+
input_generation_instructions: str = Field(
25+
default="", alias="inputGenerationInstructions"
26+
)
27+
simulate_tools: bool = Field(default=False, alias="simulateTools")
28+
tools_to_simulate: List[EvaluationSimulationTool] = Field(
29+
default_factory=list, alias="toolsToSimulate"
30+
)
31+
eval_set_id: str = Field(alias="evalSetId")
32+
created_at: str = Field(alias="createdAt")
33+
updated_at: str = Field(alias="updatedAt")
2634

2735

2836
class EvaluationSet(BaseModel):
@@ -31,15 +39,17 @@ class EvaluationSet(BaseModel):
3139
model_config = ConfigDict(alias_generator=to_camel, populate_by_name=True)
3240

3341
id: str
34-
file_name: str
42+
file_name: str = Field(..., alias="fileName")
3543
evaluator_refs: List[str] = Field(default_factory=list)
3644
evaluations: List[EvaluationItem] = Field(default_factory=list)
3745
name: str
38-
batch_size: int = 10
39-
timeout_minutes: int = 20
40-
model_settings: List[Dict[str, Any]] = Field(default_factory=list)
41-
created_at: str
42-
updated_at: str
46+
batch_size: int = Field(10, alias="batch_size")
47+
timeout_minutes: int = Field(default=20, alias="timeoutMinutes")
48+
model_settings: List[Dict[str, Any]] = Field(
49+
default_factory=list, alias="modelSettings"
50+
)
51+
created_at: str = Field(alias="createdAt")
52+
updated_at: str = Field(alias="updatedAt")
4353

4454
def extract_selected_evals(self, eval_ids) -> None:
4555
selected_evals: list[EvaluationItem] = []
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
from typing import Annotated, Any, Union
2+
3+
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag
4+
5+
from uipath.eval.models.models import EvaluatorCategory, EvaluatorType
6+
7+
8+
class EvaluatorBaseParams(BaseModel):
9+
"""Parameters for initializing the base evaluator."""
10+
11+
id: str
12+
name: str
13+
description: str
14+
category: EvaluatorCategory = Field(..., alias="category")
15+
evaluator_type: EvaluatorType = Field(..., alias="type")
16+
created_at: str = Field(..., alias="createdAt")
17+
updated_at: str = Field(..., alias="updatedAt")
18+
target_output_key: str = Field(..., alias="targetOutputKey")
19+
file_name: str = Field(..., alias="fileName")
20+
21+
22+
class LLMEvaluatorParams(EvaluatorBaseParams):
23+
prompt: str = Field(..., alias="prompt")
24+
model: str = Field(..., alias="model")
25+
26+
model_config = ConfigDict(
27+
validate_by_name=True, validate_by_alias=True, extra="allow"
28+
)
29+
30+
31+
class UnknownEvaluatorParams(EvaluatorBaseParams):
32+
model_config = ConfigDict(
33+
validate_by_name=True, validate_by_alias=True, extra="allow"
34+
)
35+
36+
37+
def evaluator_discriminator(data: Any) -> str:
38+
if isinstance(data, dict):
39+
category = data.get("category")
40+
evaluator_type = data.get("type")
41+
if (
42+
category == EvaluatorCategory.LlmAsAJudge
43+
or evaluator_type == EvaluatorType.Trajectory
44+
):
45+
return "LLMEvaluatorParams"
46+
return "UnknownEvaluatorParams"
47+
48+
49+
Evaluator = Annotated[
50+
Union[
51+
Annotated[
52+
LLMEvaluatorParams,
53+
Tag("LLMEvaluatorParams"),
54+
],
55+
Annotated[
56+
UnknownEvaluatorParams,
57+
Tag("UnknownEvaluatorParams"),
58+
],
59+
],
60+
Field(discriminator=Discriminator(evaluator_discriminator)),
61+
]

src/uipath/_cli/cli_pull.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ async def download_folder_files(
112112
if local_hash != remote_hash:
113113
styled_path = click.style(str(file_path), fg="cyan")
114114
console.warning(f"File {styled_path}" + " differs from remote version.")
115-
response = click.prompt("Do you want to override it? (y/n)", type=str)
115+
response = click.prompt("Do you want to overwrite it? (y/n)", type=str)
116116
if response.lower() == "y":
117117
with open(local_path, "w", encoding="utf-8", newline="\n") as f:
118118
f.write(remote_content)

src/uipath/agent/_utils.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,52 @@ async def load_agent_definition(project_id: str):
3131
await get_file(project_structure, PurePath("agent.json"), studio_client)
3232
).json()
3333

34+
evaluators = []
35+
try:
36+
evaluators_path = resolve_path(
37+
project_structure, PurePath("evals", "evaluators")
38+
)
39+
if isinstance(evaluators_path, ProjectFolder):
40+
for file in evaluators_path.files:
41+
evaluators.append(
42+
(
43+
await get_file(
44+
evaluators_path, PurePath(file.name), studio_client
45+
)
46+
).json()
47+
)
48+
else:
49+
logger.warning(
50+
"Unable to read evaluators from project. Defaulting to empty evaluators."
51+
)
52+
except Exception:
53+
logger.warning(
54+
"Unable to read evaluators from project. Defaulting to empty evaluators."
55+
)
56+
57+
evaluation_sets = []
58+
try:
59+
evaluation_sets_path = resolve_path(
60+
project_structure, PurePath("evals", "eval-sets")
61+
)
62+
if isinstance(evaluation_sets_path, ProjectFolder):
63+
for file in evaluation_sets_path.files:
64+
evaluation_sets.append(
65+
(
66+
await get_file(
67+
evaluation_sets_path, PurePath(file.name), studio_client
68+
)
69+
).json()
70+
)
71+
else:
72+
logger.warning(
73+
"Unable to read eval-sets from project. Defaulting to empty eval-sets."
74+
)
75+
except Exception:
76+
logger.warning(
77+
"Unable to read eval-sets from project. Defaulting to empty eval-sets."
78+
)
79+
3480
resolved_path = resolve_path(project_structure, PurePath("resources"))
3581
if isinstance(resolved_path, ProjectFolder):
3682
resource_folders = resolved_path.folders
@@ -50,6 +96,8 @@ async def load_agent_definition(project_id: str):
5096
"id": project_id,
5197
"name": project_structure.name,
5298
"resources": resources,
99+
"evaluators": evaluators,
100+
"evaluationSets": evaluation_sets,
53101
**agent,
54102
}
55103
return TypeAdapter(AgentDefinition).validate_python(agent_definition)

src/uipath/agent/models/agent.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
from pydantic import BaseModel, ConfigDict, Discriminator, Field, Tag
77

8+
from uipath._cli._evals._models._evaluation_set import EvaluationSet
9+
from uipath._cli._evals._models._evaluator import Evaluator
810
from uipath.models import Connection
911

1012

@@ -307,6 +309,12 @@ class BaseAgentDefinition(BaseModel):
307309
resources: List[AgentResourceConfig] = Field(
308310
..., description="List of tools, context, and escalation resources"
309311
)
312+
evaluation_sets: List[EvaluationSet] = Field(
313+
...,
314+
alias="evaluationSets",
315+
description="List of agent evaluation sets",
316+
)
317+
evaluators: List[Evaluator] = Field(..., description="List of agent evaluators")
310318

311319
model_config = ConfigDict(
312320
validate_by_name=True, validate_by_alias=True, extra="allow"

0 commit comments

Comments
 (0)