Skip to content

Commit

Permalink
Update langchain version to 0.1.5 and fix _split_sources() method in …
Browse files Browse the repository at this point in the history
…BaseQAWithSourcesChain
  • Loading branch information
arunraja1 committed Jan 4, 2024
1 parent 02efd94 commit 8a3f835
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
22 changes: 16 additions & 6 deletions libs/langchain/langchain/chains/qa_with_sources/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,17 +119,27 @@ def validate_naming(cls, values: Dict) -> Dict:
values["combine_documents_chain"] = values.pop("combine_document_chain")
return values

def _split_sources(self, answer: str) -> Tuple[str, str]:
def _split_sources(self, raw_answer: str) -> Tuple[str, str]:
"""Split sources from answer."""
if re.search(r"SOURCES?:", answer, re.IGNORECASE):
answer, sources = re.split(
r"SOURCES?:|QUESTION:\s", answer, flags=re.IGNORECASE
)[:2]
sources = re.split(r"\n", sources)[0].strip()
if re.search(r"SOURCES?:", raw_answer, re.IGNORECASE):
try:
answer, raw_sources = re.split(
r"SOURCES?:|QUESTION:\s", raw_answer, flags=re.IGNORECASE
)[:2]
sources = re.split(r"\n", raw_sources)[0].strip()
if sources == "":
regex = r"- \s*(.+\.pdf)"
sources_list = re.findall(regex, raw_sources)
sources = ', '.join(sources_list)
except Exception as e:
print(f"An Exception has occured for answer : {raw_answer}",e)
sources = ""
else:
sources = ""

return answer, sources


@abstractmethod
def _get_docs(
self,
Expand Down
2 changes: 1 addition & 1 deletion libs/langchain/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "langchain"
version = "0.1.3"
version = "0.1.5"
description = "Building applications with LLMs through composability"
authors = []
license = "MIT"
Expand Down

0 comments on commit 8a3f835

Please sign in to comment.