mirror of
https://github.com/hwchase17/langchain
synced 2024-11-08 07:10:35 +00:00
ec66d5188c
+ change to ABC - this lets us add things like the evaluation name for loading
52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""Test the criteria eval chain."""
|
|
|
|
|
|
import pytest
|
|
|
|
from langchain.evaluation.criteria.eval_chain import (
|
|
_SUPPORTED_CRITERIA,
|
|
CriteriaEvalChain,
|
|
)
|
|
from langchain.evaluation.schema import StringEvaluator
|
|
from tests.unit_tests.llms.fake_llm import FakeLLM
|
|
|
|
|
|
def test_resolve_criteria() -> None:
|
|
assert CriteriaEvalChain.resolve_criteria("helpfulness") == {
|
|
"helpfulness": _SUPPORTED_CRITERIA["helpfulness"]
|
|
}
|
|
assert CriteriaEvalChain.resolve_criteria(["correctness"]) == {
|
|
"correctness": _SUPPORTED_CRITERIA["correctness"]
|
|
}
|
|
|
|
|
|
def test_criteria_eval_chain() -> None:
|
|
chain = CriteriaEvalChain.from_llm(
|
|
llm=FakeLLM(
|
|
queries={"text": "The meaning of life\nY"}, sequential_responses=True
|
|
),
|
|
criteria={"my criterion": "my criterion description"},
|
|
)
|
|
with pytest.warns(UserWarning, match=chain._skip_reference_warning):
|
|
result = chain.evaluate_strings(
|
|
prediction="my prediction", reference="my reference", input="my input"
|
|
)
|
|
assert result["reasoning"] == "The meaning of life"
|
|
|
|
|
|
def test_criteria_eval_chain_missing_reference() -> None:
|
|
chain = CriteriaEvalChain.from_llm(
|
|
llm=FakeLLM(
|
|
queries={"text": "The meaning of life\nY"},
|
|
sequential_responses=True,
|
|
),
|
|
requires_reference=True,
|
|
criteria={"my criterion": "my criterion description"},
|
|
)
|
|
with pytest.raises(ValueError):
|
|
chain.evaluate_strings(prediction="my prediction", input="my input")
|
|
|
|
|
|
def test_implements_string_protocol() -> None:
|
|
assert issubclass(CriteriaEvalChain, StringEvaluator)
|