langchain/tests/unit_tests/chains/test_constitutional_ai.py
CG80499 af8f5c1a49
Added constitutional chain. (#1147)
- Added self-critique constitutional chain based on this
[paper](https://www.anthropic.com/constitutional.pdf).
2023-02-18 19:31:51 -08:00

27 lines
651 B
Python

"""Unit tests for the Constitutional AI chain."""
from langchain.chains.constitutional_ai.base import ConstitutionalChain
TEXT_ONE = """ This text is bad.
Revision request: Make it better.
Revision:"""
TEXT_TWO = """ This text is bad.\n\n"""
TEXT_THREE = """ This text is bad.
Revision request: Make it better.
Revision: Better text"""
def test_critique_parsing() -> None:
"""Test parsing of critique text."""
for text in [TEXT_ONE, TEXT_TWO, TEXT_THREE]:
critique = ConstitutionalChain._parse_critique(text)
assert (
critique.strip() == "This text is bad."
), f"Failed on {text} with {critique}"