mirror of
https://github.com/hwchase17/langchain
synced 2024-10-29 17:07:25 +00:00
e31705b5ab
when the LLMs output 'yes|no',BooleanOutputParser can parse it to 'True|False', fix the ValueError in parse(). <!-- when use the BooleanOutputParser in the chain_filter.py, the LLMs output 'yes|no',the function 'parse' will throw ValueError。 --> Fixes # (issue) #5396 https://github.com/hwchase17/langchain/issues/5396 --------- Co-authored-by: gaofeng27692 <gaofeng27692@hundsun.com>
29 lines
639 B
Python
29 lines
639 B
Python
from langchain.output_parsers.boolean import BooleanOutputParser
|
|
|
|
|
|
def test_boolean_output_parser_parse() -> None:
|
|
parser = BooleanOutputParser()
|
|
|
|
# Test valid input
|
|
result = parser.parse("YES")
|
|
assert result is True
|
|
|
|
# Test valid input
|
|
result = parser.parse("NO")
|
|
assert result is False
|
|
|
|
# Test valid input
|
|
result = parser.parse("yes")
|
|
assert result is True
|
|
|
|
# Test valid input
|
|
result = parser.parse("no")
|
|
assert result is False
|
|
|
|
# Test invalid input
|
|
try:
|
|
parser.parse("INVALID")
|
|
assert False, "Should have raised ValueError"
|
|
except ValueError:
|
|
pass
|