瀏覽代碼

refac: citations

Timothy Jaeryang Baek 2 月之前
父節點
當前提交
bbda717b69
共有 2 個文件被更改,包括 17 次插入2 次删除
  1. 1 1
      backend/open_webui/utils/middleware.py
  2. 16 1
      src/lib/components/chat/Messages/Markdown/Source.svelte

+ 1 - 1
backend/open_webui/utils/middleware.py

@@ -772,7 +772,7 @@ async def process_chat_payload(request, form_data, metadata, user, model):
 
             if "document" in source:
                 for doc_idx, doc_context in enumerate(source["document"]):
-                    context_string += f"<source><source_id>{doc_idx}</source_id><source_context>{doc_context}</source_context></source>\n"
+                    context_string += f"<source><source_id>{source_idx}</source_id><source_context>{doc_context}</source_context></source>\n"
 
         context_string = context_string.strip()
         prompt = get_last_user_message(form_data["messages"])

+ 16 - 1
src/lib/components/chat/Messages/Markdown/Source.svelte

@@ -17,6 +17,21 @@
 		return attrs;
 	}
 
+	// Helper function to return only the domain from a URL
+	function getDomain(url: string): string {
+		const domain = url.replace('http://', '').replace('https://', '').split(/[/?#]/)[0];
+		return domain;
+	}
+
+	// Helper function to check if text is a URL and return the domain
+	function formattedTitle(title: string): string {
+		if (title.startsWith('http')) {
+			return getDomain(title);
+		}
+
+		return title;
+	}
+
 	$: attributes = extractAttributes(token.text);
 </script>
 
@@ -27,6 +42,6 @@
 	}}
 >
 	<span class="line-clamp-1">
-		{attributes.title}
+		{formattedTitle(attributes.title)}
 	</span>
 </button>