mirror of
https://github.com/open-webui/open-webui
synced 2025-05-22 22:04:27 +00:00
Merge pull request #12562 from almajo/fix/agrimm/correct_knowledge_base_citations
fix: Correct Citations for knowledge base models
This commit is contained in:
commit
ef14d0b46d
@ -897,11 +897,15 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
# If context is not empty, insert it into the messages
|
||||
if len(sources) > 0:
|
||||
context_string = ""
|
||||
for source_idx, source in enumerate(sources):
|
||||
citated_file_idx = {}
|
||||
for _, source in enumerate(sources, 1):
|
||||
if "document" in source:
|
||||
for doc_idx, doc_context in enumerate(source["document"]):
|
||||
for doc_context, doc_meta in zip(source["document"], source['metadata']):
|
||||
file_id = doc_meta.get('file_id')
|
||||
if file_id not in citated_file_idx:
|
||||
citated_file_idx[file_id] = len(citated_file_idx) + 1
|
||||
context_string += (
|
||||
f'<source id="{source_idx + 1}">{doc_context}</source>\n'
|
||||
f'<source id="{citated_file_idx[file_id]}">{doc_context}</source>\n'
|
||||
)
|
||||
|
||||
context_string = context_string.strip()
|
||||
|
Loading…
Reference in New Issue
Block a user