mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
d3ec00b566
Co-authored-by: Nuno Campos <nuno@boringbits.io> Co-authored-by: Davis Chase <130488702+dev2049@users.noreply.github.com> Co-authored-by: Zander Chase <130414180+vowelparrot@users.noreply.github.com> Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
44 lines
1.8 KiB
Python
44 lines
1.8 KiB
Python
# flake8: noqa E501
|
|
|
|
"""Test LLMCheckerChain functionality."""
|
|
|
|
import pytest
|
|
|
|
from langchain.chains.llm_checker.base import LLMCheckerChain
|
|
from langchain.chains.llm_checker.prompt import (
|
|
_CHECK_ASSERTIONS_TEMPLATE,
|
|
_CREATE_DRAFT_ANSWER_TEMPLATE,
|
|
_LIST_ASSERTIONS_TEMPLATE,
|
|
_REVISED_ANSWER_TEMPLATE,
|
|
)
|
|
from tests.unit_tests.llms.fake_llm import FakeLLM
|
|
|
|
|
|
@pytest.fixture
|
|
def fake_llm_checker_chain() -> LLMCheckerChain:
|
|
"""Fake LLMCheckerChain for testing."""
|
|
queries = {
|
|
_CREATE_DRAFT_ANSWER_TEMPLATE.format(
|
|
question="Which mammal lays the biggest eggs?"
|
|
): "I don't know which mammal layers the biggest eggs.",
|
|
_LIST_ASSERTIONS_TEMPLATE.format(
|
|
statement="I don't know which mammal layers the biggest eggs.",
|
|
): "1) I know that mammals lay eggs.\n2) I know that birds lay eggs.\n3) I know that birds are mammals.",
|
|
_CHECK_ASSERTIONS_TEMPLATE.format(
|
|
assertions="1) I know that mammals lay eggs.\n2) I know that birds lay eggs.\n3) I know that birds are mammals.",
|
|
): "1) I know that mammals lay eggs. TRUE\n2) I know that birds lay eggs. TRUE\n3) I know that birds are mammals. TRUE",
|
|
_REVISED_ANSWER_TEMPLATE.format(
|
|
checked_assertions="1) I know that mammals lay eggs. TRUE\n2) I know that birds lay eggs. TRUE\n3) I know that birds are mammals. TRUE",
|
|
question="Which mammal lays the biggest eggs?",
|
|
): "I still don't know.",
|
|
}
|
|
fake_llm = FakeLLM(queries=queries)
|
|
return LLMCheckerChain.from_llm(fake_llm, input_key="q", output_key="a")
|
|
|
|
|
|
def test_simple_question(fake_llm_checker_chain: LLMCheckerChain) -> None:
|
|
"""Test simple question that should not need python."""
|
|
question = "Which mammal lays the biggest eggs?"
|
|
output = fake_llm_checker_chain.run(question)
|
|
assert output == "I still don't know."
|