Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Fuzzy citation bugfix #925

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion llama_hub/llama_packs/fuzzy_citation/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,16 @@ def get_relevant_sentences(
# concat nearby sentences
top_chunks = defaultdict(list)
prev_idx = -1
prev_response_sent_idx = -1
for response_sent_idx, node_sent_idx in sorted(top_sentences.keys()):
if prev_idx == -1:
top_chunks[response_sent_idx].append(
top_sentences[(response_sent_idx, node_sent_idx)]
)
elif node_sent_idx - prev_idx == 1:
elif (
prev_response_sent_idx == response_sent_idx
and node_sent_idx - prev_idx == 1
):
top_chunks[response_sent_idx][-1] += top_sentences[
(response_sent_idx, node_sent_idx)
]
Expand All @@ -73,6 +77,7 @@ def get_relevant_sentences(
top_sentences[(response_sent_idx, node_sent_idx)]
)
prev_idx = node_sent_idx
prev_response_sent_idx = response_sent_idx

# associate chunks with their nodes
for response_sent_idx, chunks in top_chunks.items():
Expand Down
Loading