removed unnecessary white space in regex that breaks qa with sources chain

This commit is contained in:
Nikhil Suresh 2023-08-29 03:44:14 +00:00
parent 8a4670e127
commit 64eb5a6082
2 changed files with 6 additions and 1 deletions

View File

@ -122,7 +122,7 @@ class BaseQAWithSourcesChain(Chain, ABC):
"""Split sources from answer.""" """Split sources from answer."""
if re.search(r"SOURCES?[:\s]", answer, re.IGNORECASE): if re.search(r"SOURCES?[:\s]", answer, re.IGNORECASE):
answer, sources = re.split( answer, sources = re.split(
r"SOURCES?[:\s]|QUESTION:\s", answer, flags=re.IGNORECASE r"SOURCES?[:]|QUESTION:\s", answer, flags=re.IGNORECASE
)[:2] )[:2]
sources = re.split(r"\n", sources)[0].strip() sources = re.split(r"\n", sources)[0].strip()
else: else:

View File

@ -27,6 +27,11 @@ from tests.unit_tests.llms.fake_llm import FakeLLM
"This Agreement is governed by English law.\n", "This Agreement is governed by English law.\n",
"28-pl", "28-pl",
), ),
(
"According to the sources, the agreement is governed by English law.\nSource: 28-pl",
"According to the sources, the agreement is governed by English law.\n",
"28-pl",
),
( (
"This Agreement is governed by English law.\n" "This Agreement is governed by English law.\n"
"SOURCES: 28-pl\n\n" "SOURCES: 28-pl\n\n"