mirror of
https://github.com/open-webui/open-webui
synced 2025-06-16 19:31:52 +00:00
Merge pull request #12971 from tth37/fix_source_indexing
fix: Align backend <source> tag indexing with frontend citation grouping
This commit is contained in:
commit
840dd9c89a
@ -888,16 +888,20 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
|||||||
# If context is not empty, insert it into the messages
|
# If context is not empty, insert it into the messages
|
||||||
if len(sources) > 0:
|
if len(sources) > 0:
|
||||||
context_string = ""
|
context_string = ""
|
||||||
citated_file_idx = {}
|
citation_idx = {}
|
||||||
for _, source in enumerate(sources, 1):
|
for source in sources:
|
||||||
if "document" in source:
|
if "document" in source:
|
||||||
for doc_context, doc_meta in zip(
|
for doc_context, doc_meta in zip(
|
||||||
source["document"], source["metadata"]
|
source["document"], source["metadata"]
|
||||||
):
|
):
|
||||||
file_id = doc_meta.get("file_id")
|
citation_id = (
|
||||||
if file_id not in citated_file_idx:
|
doc_meta.get("source", None)
|
||||||
citated_file_idx[file_id] = len(citated_file_idx) + 1
|
or source.get("source", {}).get("id", None)
|
||||||
context_string += f'<source id="{citated_file_idx[file_id]}">{doc_context}</source>\n'
|
or "N/A"
|
||||||
|
)
|
||||||
|
if citation_id not in citation_idx:
|
||||||
|
citation_idx[citation_id] = len(citation_idx) + 1
|
||||||
|
context_string += f'<source id="{citation_idx[citation_id]}">{doc_context}</source>\n'
|
||||||
|
|
||||||
context_string = context_string.strip()
|
context_string = context_string.strip()
|
||||||
prompt = get_last_user_message(form_data["messages"])
|
prompt = get_last_user_message(form_data["messages"])
|
||||||
|
@ -83,6 +83,7 @@
|
|||||||
});
|
});
|
||||||
return acc;
|
return acc;
|
||||||
}, []);
|
}, []);
|
||||||
|
console.log('citations', citations);
|
||||||
|
|
||||||
showRelevance = calculateShowRelevance(citations);
|
showRelevance = calculateShowRelevance(citations);
|
||||||
showPercentage = shouldShowPercentage(citations);
|
showPercentage = shouldShowPercentage(citations);
|
||||||
|
Loading…
Reference in New Issue
Block a user