mirror of
https://github.com/open-webui/open-webui
synced 2025-05-28 09:11:36 +00:00
fix: correct document citation
This commit is contained in:
parent
9cb1104f09
commit
d8a7e9c660
@ -897,12 +897,14 @@ 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"]):
|
||||
context_string += (
|
||||
f'<source id="{source_idx + 1}">{doc_context}</source>\n'
|
||||
)
|
||||
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><source_id>{citated_file_idx[file_id]}</source_id><source_context>{doc_context}</source_context></source>\n"
|
||||
|
||||
context_string = context_string.strip()
|
||||
prompt = get_last_user_message(form_data["messages"])
|
||||
|
Loading…
Reference in New Issue
Block a user