forked from elementsinteractive/lightman-ai
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluator.py
More file actions
50 lines (42 loc) · 1.3 KB
/
evaluator.py
File metadata and controls
50 lines (42 loc) · 1.3 KB
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
import logging
from typing import TYPE_CHECKING
from lightman_ai.ai.utils import get_agent_class_from_agent_name
from eval.classifier import Classifier
from eval.templates import ResultsFileBuilder
from eval.utils import ResultsMetrics
if TYPE_CHECKING:
from lightman_ai.article.models import Article
logger = logging.getLogger("eval")
def eval(
*,
prompt: str,
score_threshold: int,
relevant_articles: set[Article],
non_relevant_articles: set[Article],
samples: int,
tag: str | None,
agent: str,
model: str | None,
parallel_workers: int = 1,
) -> None:
agent_class = get_agent_class_from_agent_name(agent)
classified_articles = Classifier(
agent=agent_class(prompt, model=model),
score=score_threshold,
relevant_articles=relevant_articles,
non_relevant_articles=non_relevant_articles,
samples=samples,
workers=parallel_workers,
).run()
results_metrics = ResultsMetrics(raw_results=classified_articles)
results_template = ResultsFileBuilder(
results_metrics=results_metrics,
tag=tag,
agent=agent,
samples=samples,
prompt=prompt,
score=score_threshold,
logger=logger,
model=model or agent_class._default_model_name,
)
results_template.save()