mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-06-24 23:11:01 +02:00
fix for citation update
This commit is contained in:
parent
7ac6d3ed50
commit
3ce8923086
@ -346,7 +346,10 @@ def retrieve_search_docs(
|
|||||||
|
|
||||||
|
|
||||||
def get_answer_citation_ids(answer_str: str) -> list[int]:
|
def get_answer_citation_ids(answer_str: str) -> list[int]:
|
||||||
citation_ids = re.findall(r"\[\[D(\d+)\]\]", answer_str)
|
"""
|
||||||
|
Extract citation numbers of format [D<number>] from the answer string.
|
||||||
|
"""
|
||||||
|
citation_ids = re.findall(r"\[D(\d+)\]", answer_str)
|
||||||
return list(set([(int(id) - 1) for id in citation_ids]))
|
return list(set([(int(id) - 1) for id in citation_ids]))
|
||||||
|
|
||||||
|
|
||||||
@ -422,10 +425,9 @@ def remove_document_citations(text: str) -> str:
|
|||||||
Text with citations removed
|
Text with citations removed
|
||||||
"""
|
"""
|
||||||
# Pattern explanation:
|
# Pattern explanation:
|
||||||
# \[\[D\d+\]\]\(\) matches:
|
# \[(?:D|Q)?\d+\] matches:
|
||||||
# \[\[ - literal [[ characters
|
# \[ - literal [ character
|
||||||
# D - literal D character
|
# (?:D|Q)? - optional D or Q character
|
||||||
# \d+ - one or more digits
|
# \d+ - one or more digits
|
||||||
# \]\] - literal ]] characters
|
# \] - literal ] character
|
||||||
# \(\) - literal () characters
|
return re.sub(r"\[(?:D|Q)?\d+\]", "", text)
|
||||||
return re.sub(r"\[\[(?:D|Q)?\d+\]\](?:\([^)]*\))?", "", text)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user