File size: 2,340 Bytes
88c61d3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
from typing import Any

from .artifact import fetch_artifact
from .llm_as_judge_constants import Criteria, CriteriaOption, CriteriaWithOptions
from .operators import FieldOperator


class LoadCriteriaWithOptions(FieldOperator):
    def process_value(self, text: Any) -> CriteriaWithOptions:
        return fetch_artifact(text)[0]


class CreateCriteriaWithOptionsFromDict(FieldOperator):
    def process_value(self, criteria_dict: dict) -> Any:
        return CriteriaWithOptions.from_obj(criteria_dict)


class CreateCriteriaWithOptionsFromJson(FieldOperator):
    def process_value(self, text: str) -> Any:
        return CriteriaWithOptions.from_jsons(text)


class CreateYesNoCriteriaFromString(FieldOperator):
    def process_value(self, text: Any) -> Any:
        return CriteriaWithOptions(
            name=f"Unknown ({text[:20]}...)",
            description=text,
            options=[
                CriteriaOption(name="Yes", description=""),
                CriteriaOption(name="No", description=""),
            ],
            option_map={
                "Yes": 1.0,
                "No": 0.0,
            },
        )


class CreateYesNoPartiallyCriteriaFromString(FieldOperator):
    def process_value(self, text: str) -> Any:
        return CriteriaWithOptions(
            name=f"Unknown ({text[:20]}...)",
            description=text,
            options=[
                CriteriaOption(name="Yes", description=""),
                CriteriaOption(name="Partially", description=""),
                CriteriaOption(name="No", description=""),
            ],
            option_map={
                "Yes": 1.0,
                "Partially": 0.5,
                "No": 0.0,
            },
        )


class LoadCriteria(FieldOperator):
    def process_value(self, text: Any) -> Criteria:
        return fetch_artifact(text)[0]


class CreateCriteriaFromDict(FieldOperator):
    def process_value(self, criteria_dict: dict) -> Any:
        return Criteria.from_obj(criteria_dict)


class CreateCriteriaFromJson(FieldOperator):
    def process_value(self, text: str) -> Any:
        return Criteria.from_jsons(text)


class CreateCriteriaFromString(FieldOperator):
    def process_value(self, text: str) -> Any:
        return Criteria(
            name=f"Unknown ({text[:20]}...)",
            description=text,
        )