From c0711ba0c9153b7d5f316bbfaf11f481a9dab075 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Wed, 2 Apr 2025 20:07:09 -0700 Subject: [PATCH] refac --- backend/open_webui/config.py | 11 +++++------ backend/open_webui/utils/middleware.py | 4 +++- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/backend/open_webui/config.py b/backend/open_webui/config.py index 981ba1b7e..0a33c68b1 100644 --- a/backend/open_webui/config.py +++ b/backend/open_webui/config.py @@ -1889,7 +1889,7 @@ CHUNK_OVERLAP = PersistentConfig( ) DEFAULT_RAG_TEMPLATE = """### Task: -Respond to the user query using the provided context, incorporating inline citations in the format [source_id] **only when the tag is explicitly provided** in the context. +Respond to the user query using the provided context, incorporating inline citations in the format [source_id] **only when the tag includes an explicit id attribute** (e.g., ). ### Guidelines: - If you don't know the answer, clearly state that. @@ -1897,15 +1897,14 @@ Respond to the user query using the provided context, incorporating inline citat - Respond in the same language as the user's query. - If the context is unreadable or of poor quality, inform the user and provide the best possible answer. - If the answer isn't present in the context but you possess the knowledge, explain this to the user and provide the answer using your own understanding. -- **Only include inline citations using [source_id] (e.g., [1], [2]) when a `` tag is explicitly provided in the context.** -- Do not cite if the tag is not provided in the context. +- **Only include inline citations using [source_id] (e.g., [1], [2]) when the tag includes an id attribute.** +- Do not cite if the tag does not contain an id attribute. - Do not use XML tags in your response. - Ensure citations are concise and directly related to the information provided. ### Example of Citation: -If the user asks about a specific topic and the information is found in "whitepaper.pdf" with a provided , the response should include the citation like so: -* "According to the study, the proposed method increases efficiency by 20% [whitepaper.pdf]." -If no is present, the response should omit the citation. +If the user asks about a specific topic and the information is found in a source with a provided id attribute, the response should include the citation like so: +* "According to the study, the proposed method increases efficiency by 20% [1]." ### Output: Provide a clear and direct response to the user's query, including inline citations in the format [source_id] only when the tag is present in the context. diff --git a/backend/open_webui/utils/middleware.py b/backend/open_webui/utils/middleware.py index f96c7f836..35ff61231 100644 --- a/backend/open_webui/utils/middleware.py +++ b/backend/open_webui/utils/middleware.py @@ -866,7 +866,9 @@ async def process_chat_payload(request, form_data, user, metadata, model): for source_idx, source in enumerate(sources): if "document" in source: for doc_idx, doc_context in enumerate(source["document"]): - context_string += f"{source_idx + 1}{doc_context}\n" + context_string += ( + f'{doc_context}\n' + ) context_string = context_string.strip() prompt = get_last_user_message(form_data["messages"])