Skip to content

The agent engineering platform.

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

Nikhil Suresh64eb5a6082d5
diff --git a/libs/langchain/langchain/chains/qa_with_sources/base.py b/libs/langchain/langchain/chains/qa_with_sources/base.py
index d0408059a8..e6a07c3763 100644
--- a/libs/langchain/langchain/chains/qa_with_sources/base.py
+++ b/libs/langchain/langchain/chains/qa_with_sources/base.py
@@ -122,7 +122,7 @@ class BaseQAWithSourcesChain(Chain, ABC):
"""Split sources from answer."""
if re.search(r"SOURCES?[:\s]", answer, re.IGNORECASE):
answer, sources = re.split(
- r"SOURCES?[:\s]|QUESTION:\s", answer, flags=re.IGNORECASE
+ r"SOURCES?[:]|QUESTION:\s", answer, flags=re.IGNORECASE
)[:2]
sources = re.split(r"\n", sources)[0].strip()
else:
diff --git a/libs/langchain/tests/unit_tests/chains/test_qa_with_sources.py b/libs/langchain/tests/unit_tests/chains/test_qa_with_sources.py
index 56daf00685..c93d202bae 100644
--- a/libs/langchain/tests/unit_tests/chains/test_qa_with_sources.py
+++ b/libs/langchain/tests/unit_tests/chains/test_qa_with_sources.py
@@ -27,6 +27,11 @@ from tests.unit_tests.llms.fake_llm import FakeLLM
"This Agreement is governed by English law.\n",
"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"
"SOURCES: 28-pl\n\n"