levelapp 0.1.15__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.
- levelapp/__init__.py +0 -0
- levelapp/aspects/__init__.py +8 -0
- levelapp/aspects/loader.py +253 -0
- levelapp/aspects/logger.py +59 -0
- levelapp/aspects/monitor.py +617 -0
- levelapp/aspects/sanitizer.py +168 -0
- levelapp/clients/__init__.py +122 -0
- levelapp/clients/anthropic.py +112 -0
- levelapp/clients/gemini.py +130 -0
- levelapp/clients/groq.py +101 -0
- levelapp/clients/huggingface.py +162 -0
- levelapp/clients/ionos.py +126 -0
- levelapp/clients/mistral.py +106 -0
- levelapp/clients/openai.py +116 -0
- levelapp/comparator/__init__.py +5 -0
- levelapp/comparator/comparator.py +232 -0
- levelapp/comparator/extractor.py +108 -0
- levelapp/comparator/schemas.py +61 -0
- levelapp/comparator/scorer.py +269 -0
- levelapp/comparator/utils.py +136 -0
- levelapp/config/__init__.py +5 -0
- levelapp/config/endpoint.py +199 -0
- levelapp/config/prompts.py +57 -0
- levelapp/core/__init__.py +0 -0
- levelapp/core/base.py +386 -0
- levelapp/core/schemas.py +24 -0
- levelapp/core/session.py +336 -0
- levelapp/endpoint/__init__.py +0 -0
- levelapp/endpoint/client.py +188 -0
- levelapp/endpoint/client_test.py +41 -0
- levelapp/endpoint/manager.py +114 -0
- levelapp/endpoint/parsers.py +119 -0
- levelapp/endpoint/schemas.py +38 -0
- levelapp/endpoint/tester.py +52 -0
- levelapp/evaluator/__init__.py +3 -0
- levelapp/evaluator/evaluator.py +307 -0
- levelapp/metrics/__init__.py +63 -0
- levelapp/metrics/embedding.py +56 -0
- levelapp/metrics/embeddings/__init__.py +0 -0
- levelapp/metrics/embeddings/sentence_transformer.py +30 -0
- levelapp/metrics/embeddings/torch_based.py +56 -0
- levelapp/metrics/exact.py +182 -0
- levelapp/metrics/fuzzy.py +80 -0
- levelapp/metrics/token.py +103 -0
- levelapp/plugins/__init__.py +0 -0
- levelapp/repository/__init__.py +3 -0
- levelapp/repository/filesystem.py +203 -0
- levelapp/repository/firestore.py +291 -0
- levelapp/simulator/__init__.py +3 -0
- levelapp/simulator/schemas.py +116 -0
- levelapp/simulator/simulator.py +531 -0
- levelapp/simulator/utils.py +134 -0
- levelapp/visualization/__init__.py +7 -0
- levelapp/visualization/charts.py +358 -0
- levelapp/visualization/dashboard.py +240 -0
- levelapp/visualization/exporter.py +167 -0
- levelapp/visualization/templates/base.html +158 -0
- levelapp/visualization/templates/comparator_dashboard.html +57 -0
- levelapp/visualization/templates/simulator_dashboard.html +111 -0
- levelapp/workflow/__init__.py +6 -0
- levelapp/workflow/base.py +192 -0
- levelapp/workflow/config.py +96 -0
- levelapp/workflow/context.py +64 -0
- levelapp/workflow/factory.py +42 -0
- levelapp/workflow/registration.py +6 -0
- levelapp/workflow/runtime.py +19 -0
- levelapp-0.1.15.dist-info/METADATA +571 -0
- levelapp-0.1.15.dist-info/RECORD +70 -0
- levelapp-0.1.15.dist-info/WHEEL +4 -0
- levelapp-0.1.15.dist-info/licenses/LICENSE +0 -0
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""levelapp/workflow/config.py: Contains modular workflow configuration components."""
|
|
2
|
+
from typing import List, Dict, Any, Optional
|
|
3
|
+
from pydantic import BaseModel, Field
|
|
4
|
+
|
|
5
|
+
from levelapp.aspects import logger
|
|
6
|
+
from levelapp.endpoint.client import EndpointConfig
|
|
7
|
+
from levelapp.core.schemas import WorkflowType, RepositoryType, EvaluatorType
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class ProcessConfig(BaseModel):
|
|
11
|
+
project_name: str
|
|
12
|
+
workflow_type: WorkflowType
|
|
13
|
+
evaluation_params: Dict[str, Any] = Field(default_factory=dict)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class EvaluationConfig(BaseModel):
|
|
17
|
+
evaluators: List[EvaluatorType]
|
|
18
|
+
providers: List[str] = Field(default_factory=list)
|
|
19
|
+
metrics_map: Dict[str, str] | None = Field(default_factory=dict)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ReferenceDataConfig(BaseModel):
|
|
23
|
+
path: str | None
|
|
24
|
+
data: Dict[str, Any] | None = Field(default_factory=dict)
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class RepositoryConfig(BaseModel):
|
|
28
|
+
type: RepositoryType | None = None
|
|
29
|
+
project_id: str | None = None
|
|
30
|
+
database_name: str = Field(default="(default)")
|
|
31
|
+
|
|
32
|
+
class Config:
|
|
33
|
+
extra = "allow"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class WorkflowConfig(BaseModel):
|
|
37
|
+
"""
|
|
38
|
+
Static workflow configuration. Maps directly to YAML sections.
|
|
39
|
+
Supports both file-based loading and in-memory dictionary creation.
|
|
40
|
+
"""
|
|
41
|
+
process: ProcessConfig
|
|
42
|
+
endpoint: EndpointConfig
|
|
43
|
+
evaluation: EvaluationConfig
|
|
44
|
+
reference_data: ReferenceDataConfig
|
|
45
|
+
repository: RepositoryConfig
|
|
46
|
+
|
|
47
|
+
class Config:
|
|
48
|
+
extra = "allow"
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def load(cls, path: str | None = None) -> "WorkflowConfig":
|
|
52
|
+
"""
|
|
53
|
+
Load workflow configuration from a YAML/JSON file.
|
|
54
|
+
|
|
55
|
+
Args:
|
|
56
|
+
path (str): YAML/JSON configuration file path.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
WorkflowConfig: An instance of WorkflowConfig.
|
|
60
|
+
"""
|
|
61
|
+
from levelapp.aspects.loader import DataLoader
|
|
62
|
+
|
|
63
|
+
loader = DataLoader()
|
|
64
|
+
config_dict = loader.load_raw_data(path=path)
|
|
65
|
+
logger.info(f"[{cls.__name__}] Workflow configuration loaded from '{path}' file content")
|
|
66
|
+
return cls.model_validate(config_dict)
|
|
67
|
+
|
|
68
|
+
@classmethod
|
|
69
|
+
def from_dict(cls, content: Dict[str, Any]) -> "WorkflowConfig":
|
|
70
|
+
"""
|
|
71
|
+
Load workflow configuration from an in-memory dict.
|
|
72
|
+
|
|
73
|
+
Args:
|
|
74
|
+
content (dict): Workflow configuration content.
|
|
75
|
+
|
|
76
|
+
Returns:
|
|
77
|
+
WorkflowConfig: An instance of WorkflowConfig.
|
|
78
|
+
"""
|
|
79
|
+
logger.info(f"[{cls.__name__}] Workflow configuration loaded from provided content")
|
|
80
|
+
return cls.model_validate(content)
|
|
81
|
+
|
|
82
|
+
def set_reference_data(self, content: Dict[str, Any]) -> None:
|
|
83
|
+
"""
|
|
84
|
+
Load referer data from an in-memory dict.
|
|
85
|
+
|
|
86
|
+
Args:
|
|
87
|
+
content (dict): Workflow configuration content.
|
|
88
|
+
|
|
89
|
+
"""
|
|
90
|
+
self.reference_data.data = content
|
|
91
|
+
logger.info(f"[{self.__class__.__name__}] Reference data loaded from provided content")
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
if __name__ == '__main__':
|
|
95
|
+
workflow_config = WorkflowConfig.load(path="../../src/data/workflow_config.yaml")
|
|
96
|
+
print(f"Workflow Configuration:\n{workflow_config.model_dump_json(indent=2)}")
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""levelapp/workflow/context.py: Builds runtime WorkflowContext from WorkflowConfig."""
|
|
2
|
+
from typing import Dict, Callable
|
|
3
|
+
|
|
4
|
+
from levelapp.repository.filesystem import FileSystemRepository
|
|
5
|
+
from levelapp.workflow.config import WorkflowConfig
|
|
6
|
+
from levelapp.core.base import BaseRepository, BaseEvaluator
|
|
7
|
+
from levelapp.workflow.runtime import WorkflowContext
|
|
8
|
+
from levelapp.core.schemas import EvaluatorType, RepositoryType
|
|
9
|
+
|
|
10
|
+
from levelapp.repository.firestore import FirestoreRepository
|
|
11
|
+
from levelapp.evaluator.evaluator import JudgeEvaluator, MetadataEvaluator
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class WorkflowContextBuilder:
|
|
15
|
+
"""Builds a runtime WorkflowContext from a WorkflowConfig."""
|
|
16
|
+
|
|
17
|
+
def __init__(self, config: WorkflowConfig) -> None:
|
|
18
|
+
self.config = config
|
|
19
|
+
|
|
20
|
+
# Map repository type to constructor that accepts the WorkflowConfig
|
|
21
|
+
self.repository_map: Dict[RepositoryType, Callable[[WorkflowConfig], BaseRepository]] = {
|
|
22
|
+
RepositoryType.FIRESTORE: lambda cfg: FirestoreRepository(cfg),
|
|
23
|
+
RepositoryType.FILESYSTEM: lambda cfg: FileSystemRepository(cfg),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
# Map evaluator type to constructor that accepts the WorkflowConfig
|
|
27
|
+
self.evaluator_map: Dict[EvaluatorType, Callable[[WorkflowConfig], BaseEvaluator]] = {
|
|
28
|
+
EvaluatorType.JUDGE: lambda cfg: JudgeEvaluator(config=cfg),
|
|
29
|
+
EvaluatorType.REFERENCE: lambda cfg: MetadataEvaluator(config=cfg),
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def build(self) -> WorkflowContext:
|
|
33
|
+
"""
|
|
34
|
+
Build a runtime WorkflowContext from the static WorkflowConfig.
|
|
35
|
+
Supports in-memory reference data if provided.
|
|
36
|
+
"""
|
|
37
|
+
# Repository instance
|
|
38
|
+
repository_type = self.config.repository.type
|
|
39
|
+
repository = self.repository_map.get(repository_type)(self.config)
|
|
40
|
+
|
|
41
|
+
# Evaluator instances
|
|
42
|
+
evaluators: Dict[EvaluatorType, BaseEvaluator] = {
|
|
43
|
+
ev: self.evaluator_map.get(ev)(self.config) for ev in self.config.evaluation.evaluators
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
# Providers and endpoint
|
|
47
|
+
providers = self.config.evaluation.providers
|
|
48
|
+
endpoint_config = self.config.endpoint
|
|
49
|
+
|
|
50
|
+
# Inputs include reference data path or in-memory dict
|
|
51
|
+
inputs = {}
|
|
52
|
+
if self.config.reference_data.data:
|
|
53
|
+
inputs["reference_data"] = self.config.reference_data.data
|
|
54
|
+
else:
|
|
55
|
+
inputs["reference_data_path"] = self.config.reference_data.path
|
|
56
|
+
|
|
57
|
+
return WorkflowContext(
|
|
58
|
+
config=self.config,
|
|
59
|
+
repository=repository,
|
|
60
|
+
evaluators=evaluators,
|
|
61
|
+
providers=providers,
|
|
62
|
+
endpoint=endpoint_config,
|
|
63
|
+
inputs=inputs,
|
|
64
|
+
)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"""levelapp/workflow/factory.py: Creates workflows using WorkflowContext."""
|
|
2
|
+
from typing import Dict, Callable
|
|
3
|
+
|
|
4
|
+
from levelapp.core.schemas import WorkflowType
|
|
5
|
+
from levelapp.workflow.base import SimulatorWorkflow, ComparatorWorkflow, BaseWorkflow
|
|
6
|
+
from levelapp.workflow.runtime import WorkflowContext
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MainFactory:
|
|
10
|
+
"""Central factory for workflows."""
|
|
11
|
+
_workflow_map: Dict[WorkflowType, Callable[[WorkflowContext], BaseWorkflow]] = {
|
|
12
|
+
WorkflowType.SIMULATOR: lambda ctx: SimulatorWorkflow(ctx),
|
|
13
|
+
WorkflowType.COMPARATOR: lambda ctx: ComparatorWorkflow(ctx),
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@classmethod
|
|
17
|
+
def create_workflow(cls, context: WorkflowContext) -> BaseWorkflow:
|
|
18
|
+
"""
|
|
19
|
+
Create workflow using the given runtime context.
|
|
20
|
+
|
|
21
|
+
Args:
|
|
22
|
+
context (WorkflowContext): the provided workflow context.
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
BaseWorkflow: the built workflow instance from the provided context.
|
|
26
|
+
"""
|
|
27
|
+
wf_type = context.config.process.workflow_type
|
|
28
|
+
builder = cls._workflow_map.get(wf_type)
|
|
29
|
+
if not builder:
|
|
30
|
+
raise NotImplementedError(f"Workflow '{wf_type}' not implemented")
|
|
31
|
+
return builder(context)
|
|
32
|
+
|
|
33
|
+
@classmethod
|
|
34
|
+
def register_workflow(cls, wf_type: WorkflowType, builder: Callable[[WorkflowContext], BaseWorkflow]) -> None:
|
|
35
|
+
"""
|
|
36
|
+
Register a new workflow implementation.
|
|
37
|
+
|
|
38
|
+
Args:
|
|
39
|
+
wf_type (WorkflowType): the workflow type.
|
|
40
|
+
builder (Callable[[WorkflowContext], BaseWorkflow]): the workflow builder.
|
|
41
|
+
"""
|
|
42
|
+
cls._workflow_map[wf_type] = builder
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
from levelapp.core.schemas import WorkflowType
|
|
2
|
+
from levelapp.workflow.factory import MainFactory
|
|
3
|
+
from levelapp.workflow.base import SimulatorWorkflow, ComparatorWorkflow
|
|
4
|
+
|
|
5
|
+
MainFactory.register_workflow(WorkflowType.SIMULATOR, lambda ctx: SimulatorWorkflow(ctx))
|
|
6
|
+
MainFactory.register_workflow(WorkflowType.COMPARATOR, lambda ctx: ComparatorWorkflow(ctx))
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"""levelapp/workflow/runtime.py: contains the workflow runtime context component."""
|
|
2
|
+
from dataclasses import dataclass
|
|
3
|
+
from typing import Dict, List, Any
|
|
4
|
+
|
|
5
|
+
from levelapp.endpoint.client import EndpointConfig
|
|
6
|
+
from levelapp.core.base import BaseRepository, BaseEvaluator
|
|
7
|
+
from levelapp.workflow.config import WorkflowConfig
|
|
8
|
+
from levelapp.core.schemas import EvaluatorType
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True)
|
|
12
|
+
class WorkflowContext:
|
|
13
|
+
"""Immutable data holder for workflow execution context."""
|
|
14
|
+
config: WorkflowConfig
|
|
15
|
+
endpoint: EndpointConfig
|
|
16
|
+
repository: BaseRepository
|
|
17
|
+
evaluators: Dict[EvaluatorType, BaseEvaluator]
|
|
18
|
+
providers: List[str]
|
|
19
|
+
inputs: Dict[str, Any]
|