Skip to content

Commit 3ef88ba

Browse files
committed
Improve evaluators API readability
Moves the `getattr` to the end of the function to make the code more readable.
1 parent 883e0bd commit 3ef88ba

File tree

1 file changed

+42
-42
lines changed

1 file changed

+42
-42
lines changed

src/root/skills.py

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,48 +1389,6 @@ def __init__(self, client_context: ClientContextCallable):
13891389
self.client_context = client_context
13901390
self.versions = Versions(client_context)
13911391

1392-
EvaluatorName = Literal[
1393-
"Faithfulness",
1394-
"Relevance",
1395-
"Clarity",
1396-
"Non_toxicity",
1397-
"Helpfulness",
1398-
"Politeness",
1399-
"Formality",
1400-
"Harmlessness",
1401-
"Confidentiality",
1402-
"Persuasiveness",
1403-
"JSON_Empty_Values_Ratio",
1404-
"JSON_Property_Name_Accuracy",
1405-
"JSON_Property_Type_Accuracy",
1406-
"JSON_Property_Completeness",
1407-
"JSON_Content_Accuracy",
1408-
"Context_Recall",
1409-
"Answer_Correctness",
1410-
"Answer_Semantic_Similarity",
1411-
"Sentiment_recognition",
1412-
"Safety_for_Children",
1413-
"Precision",
1414-
"Originality",
1415-
"Engagingness",
1416-
"Conciseness",
1417-
"Coherence",
1418-
"Quality_of_Writing_Professional",
1419-
"Quality_of_Writing_Creative",
1420-
"Truthfulness",
1421-
"Context_Precision",
1422-
"Answer_Relevance",
1423-
]
1424-
1425-
def __getattr__(self, name: Union[EvaluatorName, str]) -> Union["PresetEvaluatorRunner", "APresetEvaluatorRunner"]:
1426-
if name in self.Eval.__members__:
1427-
context = self.client_context()
1428-
if isinstance(context, AbstractContextManager):
1429-
return PresetEvaluatorRunner(self.client_context, self.Eval.__members__[name].value, name)
1430-
else:
1431-
return APresetEvaluatorRunner(self.client_context, self.Eval.__members__[name].value, name)
1432-
raise AttributeError(f"{name} is not a valid attribute")
1433-
14341392
@with_sync_client
14351393
def run(
14361394
self,
@@ -2402,3 +2360,45 @@ async def arun_by_name(
24022360
evaluator_execution_request=evaluator_execution_request,
24032361
_request_timeout=_request_timeout,
24042362
)
2363+
2364+
EvaluatorName = Literal[
2365+
"Faithfulness",
2366+
"Relevance",
2367+
"Clarity",
2368+
"Non_toxicity",
2369+
"Helpfulness",
2370+
"Politeness",
2371+
"Formality",
2372+
"Harmlessness",
2373+
"Confidentiality",
2374+
"Persuasiveness",
2375+
"JSON_Empty_Values_Ratio",
2376+
"JSON_Property_Name_Accuracy",
2377+
"JSON_Property_Type_Accuracy",
2378+
"JSON_Property_Completeness",
2379+
"JSON_Content_Accuracy",
2380+
"Context_Recall",
2381+
"Answer_Correctness",
2382+
"Answer_Semantic_Similarity",
2383+
"Sentiment_recognition",
2384+
"Safety_for_Children",
2385+
"Precision",
2386+
"Originality",
2387+
"Engagingness",
2388+
"Conciseness",
2389+
"Coherence",
2390+
"Quality_of_Writing_Professional",
2391+
"Quality_of_Writing_Creative",
2392+
"Truthfulness",
2393+
"Context_Precision",
2394+
"Answer_Relevance",
2395+
]
2396+
2397+
def __getattr__(self, name: Union[EvaluatorName, str]) -> Union["PresetEvaluatorRunner", "APresetEvaluatorRunner"]:
2398+
if name in self.Eval.__members__:
2399+
context = self.client_context()
2400+
if isinstance(context, AbstractContextManager):
2401+
return PresetEvaluatorRunner(self.client_context, self.Eval.__members__[name].value, name)
2402+
else:
2403+
return APresetEvaluatorRunner(self.client_context, self.Eval.__members__[name].value, name)
2404+
raise AttributeError(f"{name} is not a valid attribute")

0 commit comments

Comments
 (0)