From 35d75e733d30ef004ea74f0a421a541a0f17f55a Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Fri, 22 Nov 2024 10:35:59 -0800 Subject: [PATCH] refac: file handling --- backend/open_webui/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/backend/open_webui/main.py b/backend/open_webui/main.py index 797c9622a..3aa3c5559 100644 --- a/backend/open_webui/main.py +++ b/backend/open_webui/main.py @@ -698,12 +698,13 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware): if "document" in source: for doc_idx, doc_context in enumerate(source["document"]): metadata = source.get("metadata") + doc_source_id = None if metadata: doc_source_id = metadata[doc_idx].get("source", source_id) if source_id: - context_string += f"{doc_source_id}{doc_context}\n" + context_string += f"{doc_source_id if doc_source_id is not None else source_id}{doc_context}\n" else: # If there is no source_id, then do not include the source_id tag context_string += f"{doc_context}\n"