mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac: web search link display
This commit is contained in:
parent
33f04a7714
commit
0a85dd4bca
3 changed files with 90 additions and 29 deletions
|
|
@ -1945,6 +1945,8 @@ async def process_web_search(
|
||||||
):
|
):
|
||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
|
result_items = []
|
||||||
|
|
||||||
try:
|
try:
|
||||||
logging.info(
|
logging.info(
|
||||||
f"trying to web search with {request.app.state.config.WEB_SEARCH_ENGINE, form_data.queries}"
|
f"trying to web search with {request.app.state.config.WEB_SEARCH_ENGINE, form_data.queries}"
|
||||||
|
|
@ -1966,6 +1968,7 @@ async def process_web_search(
|
||||||
if result:
|
if result:
|
||||||
for item in result:
|
for item in result:
|
||||||
if item and item.link:
|
if item and item.link:
|
||||||
|
result_items.append(item)
|
||||||
urls.append(item.link)
|
urls.append(item.link)
|
||||||
|
|
||||||
urls = list(dict.fromkeys(urls))
|
urls = list(dict.fromkeys(urls))
|
||||||
|
|
@ -2010,12 +2013,16 @@ async def process_web_search(
|
||||||
urls = [
|
urls = [
|
||||||
doc.metadata.get("source") for doc in docs if doc.metadata.get("source")
|
doc.metadata.get("source") for doc in docs if doc.metadata.get("source")
|
||||||
] # only keep the urls returned by the loader
|
] # only keep the urls returned by the loader
|
||||||
|
result_items = [
|
||||||
|
dict(item) for item in result_items if item.link in urls
|
||||||
|
] # only keep the search results that have been loaded
|
||||||
|
|
||||||
if request.app.state.config.BYPASS_WEB_SEARCH_EMBEDDING_AND_RETRIEVAL:
|
if request.app.state.config.BYPASS_WEB_SEARCH_EMBEDDING_AND_RETRIEVAL:
|
||||||
return {
|
return {
|
||||||
"status": True,
|
"status": True,
|
||||||
"collection_name": None,
|
"collection_name": None,
|
||||||
"filenames": urls,
|
"filenames": urls,
|
||||||
|
"items": result_items,
|
||||||
"docs": [
|
"docs": [
|
||||||
{
|
{
|
||||||
"content": doc.page_content,
|
"content": doc.page_content,
|
||||||
|
|
@ -2048,6 +2055,7 @@ async def process_web_search(
|
||||||
return {
|
return {
|
||||||
"status": True,
|
"status": True,
|
||||||
"collection_names": [collection_name],
|
"collection_names": [collection_name],
|
||||||
|
"items": result_items,
|
||||||
"filenames": urls,
|
"filenames": urls,
|
||||||
"loaded_count": len(docs),
|
"loaded_count": len(docs),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -487,6 +487,7 @@ async def chat_web_search_handler(
|
||||||
"action": "web_search",
|
"action": "web_search",
|
||||||
"description": "Searched {{count}} sites",
|
"description": "Searched {{count}} sites",
|
||||||
"urls": results["filenames"],
|
"urls": results["filenames"],
|
||||||
|
"items": results.get("items", []),
|
||||||
"done": True,
|
"done": True,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,14 +21,14 @@
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
class="text-sm border border-gray-50 dark:border-gray-850 rounded-xl mb-1.5 p-1"
|
class="text-sm border border-gray-50 dark:border-gray-850 rounded-xl mb-1.5 p-2"
|
||||||
slot="content"
|
slot="content"
|
||||||
>
|
>
|
||||||
{#if status?.query}
|
{#if status?.query}
|
||||||
<a
|
<a
|
||||||
href="https://www.google.com/search?q={status.query}"
|
href="https://www.google.com/search?q={status.query}"
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="flex w-full items-center p-2 px-3 group/item justify-between font-normal text-gray-800 dark:text-gray-300 no-underline"
|
class="flex w-full items-center p-1 px-3 group/item justify-between text-gray-800 dark:text-gray-300 font-normal! no-underline!"
|
||||||
>
|
>
|
||||||
<div class="flex gap-2 items-center">
|
<div class="flex gap-2 items-center">
|
||||||
<Search />
|
<Search />
|
||||||
|
|
@ -58,14 +58,25 @@
|
||||||
</a>
|
</a>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#each status.urls as url, urlIdx}
|
{#if status?.items}
|
||||||
|
{#each status.items as item, itemIdx}
|
||||||
<a
|
<a
|
||||||
href={url}
|
href={item.link}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="flex w-full items-center p-2 px-3 group/item justify-between font-normal text-gray-800 dark:text-gray-300"
|
class="flex w-full items-center p-1 px-3 group/item justify-between text-gray-800 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-850 rounded-lg font-normal! no-underline! mb-1"
|
||||||
>
|
>
|
||||||
<div class=" line-clamp-1">
|
<div class=" flex justify-center items-center gap-3">
|
||||||
{url}
|
<div class="w-fit">
|
||||||
|
<img
|
||||||
|
src="https://www.google.com/s2/favicons?sz=32&domain={item.link}"
|
||||||
|
alt="favicon"
|
||||||
|
class="size-3.5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full text-sm line-clamp-1">
|
||||||
|
{item.title ? item.title : item.link}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
@ -87,5 +98,46 @@
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
{/each}
|
{/each}
|
||||||
|
{:else if status?.urls}
|
||||||
|
{#each status.urls as url, urlIdx}
|
||||||
|
<a
|
||||||
|
href={url}
|
||||||
|
target="_blank"
|
||||||
|
class="flex w-full items-center p-1 px-3 group/item justify-between text-gray-800 dark:text-gray-300 hover:bg-gray-50 dark:hover:bg-gray-850 rounded-lg no-underline mb-1"
|
||||||
|
>
|
||||||
|
<div class=" flex justify-center items-center gap-3">
|
||||||
|
<div class="w-fit">
|
||||||
|
<img
|
||||||
|
src="https://www.google.com/s2/favicons?sz=32&domain={url}"
|
||||||
|
alt="favicon"
|
||||||
|
class="size-3.5"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="w-full text-sm line-clamp-1">
|
||||||
|
{url}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
class=" ml-1 text-white dark:text-gray-900 group-hover/item:text-gray-600 dark:group-hover/item:text-white transition"
|
||||||
|
>
|
||||||
|
<!-- -->
|
||||||
|
<svg
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
viewBox="0 0 16 16"
|
||||||
|
fill="currentColor"
|
||||||
|
class="size-4"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
fill-rule="evenodd"
|
||||||
|
d="M4.22 11.78a.75.75 0 0 1 0-1.06L9.44 5.5H5.75a.75.75 0 0 1 0-1.5h5.5a.75.75 0 0 1 .75.75v5.5a.75.75 0 0 1-1.5 0V6.56l-5.22 5.22a.75.75 0 0 1-1.06 0Z"
|
||||||
|
clip-rule="evenodd"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
</a>
|
||||||
|
{/each}
|
||||||
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</Collapsible>
|
</Collapsible>
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue