levelapp 0.1.0__py3-none-any.whl → 0.1.1__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 levelapp might be problematic. Click here for more details.

@@ -1,121 +0,0 @@
1
- from enum import Enum
2
- from pydantic import BaseModel
3
- from dataclasses import dataclass
4
- from typing import List, Dict, Any
5
-
6
- from levelapp.config.endpoint import EndpointConfig
7
- from levelapp.core.base import BaseRepository, BaseEvaluator
8
- from levelapp.aspects import DataLoader
9
-
10
-
11
- class ExtendedEnum(Enum):
12
- @classmethod
13
- def list(cls):
14
- return [e.value for e in cls]
15
-
16
-
17
- class WorkflowType(ExtendedEnum):
18
- SIMULATOR = "SIMULATOR"
19
- COMPARATOR = "COMPARATOR"
20
- ASSESSOR = "ASSESSOR"
21
-
22
-
23
- class RepositoryType(ExtendedEnum):
24
- FIRESTORE = "FIRESTORE"
25
- FILESYSTEM = "FILESYSTEM"
26
-
27
-
28
- class EvaluatorType(ExtendedEnum):
29
- JUDGE = "JUDGE"
30
- REFERENCE = "REFERENCE"
31
- RAG = "RAG"
32
-
33
-
34
- class WorkflowConfig:
35
- """Configuration for a workflow, loaded from JSON/YAML via DataLoader."""
36
-
37
- # Class-level constant
38
- _fields_list: List[str] = [
39
- "project_name",
40
- "evaluation_params",
41
- "workflow",
42
- "repository",
43
- "evaluators",
44
- "reference_data",
45
- ]
46
-
47
- def __init__(
48
- self,
49
- workflow: WorkflowType,
50
- repository: RepositoryType,
51
- evaluators: List[EvaluatorType],
52
- endpoint_config: EndpointConfig,
53
- inputs: Dict[str, Any],
54
- ):
55
- self.workflow = workflow
56
- self.repository = repository
57
- self.evaluators = evaluators
58
- self.endpoint_config = endpoint_config
59
- self.inputs = inputs
60
-
61
- @classmethod
62
- def load(cls, path: str | None = None) -> "WorkflowConfig":
63
- """Load and validate workflow configuration from a file."""
64
- loader = DataLoader()
65
- config_dict = loader.load_raw_data(path=path)
66
- model_config: BaseModel = loader.create_dynamic_model(data=config_dict, model_name="WorkflowConfiguration")
67
-
68
- cls._check_fields(model_config)
69
- cls._check_values(model_config)
70
-
71
- workflow = WorkflowType(model_config.workflow)
72
- repository = RepositoryType(model_config.repository)
73
-
74
- if isinstance(model_config.evaluators, str):
75
- print(f"evaluators: {model_config.evaluators}")
76
- evaluators = [EvaluatorType(model_config.evaluators)]
77
- else:
78
- evaluators = [EvaluatorType(e) for e in model_config.evaluators]
79
-
80
- evaluation_params = model_config.evaluation_params.model_dump()
81
- reference_data_path = getattr(model_config.reference_data, "path", None)
82
- endpoint_config = EndpointConfig.model_validate(model_config.endpoint_configuration.model_dump())
83
-
84
- return cls(
85
- workflow=workflow,
86
- repository=repository,
87
- evaluators=evaluators,
88
- endpoint_config=endpoint_config,
89
- inputs={'reference_data_path': reference_data_path, 'evaluation_params': evaluation_params},
90
- )
91
-
92
- @classmethod
93
- def _check_fields(cls, config: BaseModel) -> None:
94
- for field_name in cls._fields_list:
95
- if field_name not in config.model_fields:
96
- raise ValueError(f"[WorkflowConfig] Field '{field_name}' missing in configuration")
97
-
98
- @staticmethod
99
- def _check_values(config: BaseModel) -> None:
100
- if config.workflow not in WorkflowType.list():
101
- raise ValueError(f"[WorkflowConfig] Unsupported workflow type '{config.workflow}'")
102
- if config.repository not in RepositoryType.list():
103
- raise ValueError(f"[WorkflowConfig] Unsupported repository type '{config.repository}'")
104
-
105
- evals = config.evaluators
106
- if isinstance(evals, str):
107
- evals = [evals]
108
-
109
- for e in evals:
110
- if e not in EvaluatorType.list():
111
- raise ValueError(f"[WorkflowConfig] Unsupported evaluator type '{config.evaluators}'")
112
-
113
-
114
- @dataclass(frozen=True)
115
- class WorkflowContext:
116
- """Immutable data holder for workflow execution context."""
117
- config: WorkflowConfig
118
- repository: BaseRepository
119
- evaluators: Dict[str, BaseEvaluator]
120
- endpoint_config: EndpointConfig
121
- inputs: Dict[str, Any]