mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
enh: allow full context mode for collections
This commit is contained in:
parent
d5f9bbc7a7
commit
b3c4bc6041
4 changed files with 65 additions and 19 deletions
|
|
@ -479,12 +479,38 @@ def get_sources_from_files(
|
|||
"documents": [[note.data.get("content", {}).get("md", "")]],
|
||||
"metadatas": [[{"file_id": note.id, "name": note.title}]],
|
||||
}
|
||||
elif file.get("context") == "full" and file.get("type") == "file":
|
||||
# Manual Full Mode Toggle
|
||||
query_result = {
|
||||
"documents": [[file.get("file").get("data", {}).get("content")]],
|
||||
"metadatas": [[{"file_id": file.get("id"), "name": file.get("name")}]],
|
||||
}
|
||||
elif file.get("context") == "full":
|
||||
if file.get("type") == "file":
|
||||
# Manual Full Mode Toggle
|
||||
query_result = {
|
||||
"documents": [[file.get("file").get("data", {}).get("content")]],
|
||||
"metadatas": [
|
||||
[{"file_id": file.get("id"), "name": file.get("name")}]
|
||||
],
|
||||
}
|
||||
elif file.get("type") == "collection":
|
||||
# Manual Full Mode Toggle for Collection
|
||||
file_ids = file.get("data", {}).get("file_ids", [])
|
||||
|
||||
documents = []
|
||||
metadatas = []
|
||||
for file_id in file_ids:
|
||||
file_object = Files.get_file_by_id(file_id)
|
||||
|
||||
if file_object:
|
||||
documents.append(file_object.data.get("content", ""))
|
||||
metadatas.append(
|
||||
{
|
||||
"file_id": file_id,
|
||||
"name": file_object.filename,
|
||||
"source": file_object.filename,
|
||||
}
|
||||
)
|
||||
|
||||
query_result = {
|
||||
"documents": [documents],
|
||||
"metadatas": [metadatas],
|
||||
}
|
||||
elif (
|
||||
file.get("type") != "web_search"
|
||||
and request.app.state.config.BYPASS_EMBEDDING_AND_RETRIEVAL
|
||||
|
|
|
|||
|
|
@ -1145,18 +1145,8 @@
|
|||
loading={file.status === 'uploading'}
|
||||
dismissible={true}
|
||||
edit={true}
|
||||
modal={true}
|
||||
on:dismiss={async () => {
|
||||
try {
|
||||
if (file.type !== 'collection' && !file?.collection) {
|
||||
if (file.id) {
|
||||
// This will handle both file deletion and Chroma cleanup
|
||||
await deleteFileById(localStorage.token, file.id);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error deleting file:', error);
|
||||
}
|
||||
|
||||
// Remove from UI state
|
||||
files.splice(fileIdx, 1);
|
||||
files = files;
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@
|
|||
export let url: string | null = null;
|
||||
|
||||
export let dismissible = false;
|
||||
export let modal = false;
|
||||
export let loading = false;
|
||||
|
||||
export let item = null;
|
||||
|
|
@ -50,7 +51,7 @@
|
|||
: 'rounded-2xl'} text-left"
|
||||
type="button"
|
||||
on:click={async () => {
|
||||
if (item?.file?.data?.content) {
|
||||
if (item?.file?.data?.content || modal) {
|
||||
showModal = !showModal;
|
||||
} else {
|
||||
if (url) {
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
import Info from '../icons/Info.svelte';
|
||||
import Switch from './Switch.svelte';
|
||||
import Tooltip from './Tooltip.svelte';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
export let item;
|
||||
export let show = false;
|
||||
|
|
@ -77,6 +78,24 @@
|
|||
<div>
|
||||
<div class="flex flex-col items-center md:flex-row gap-1 justify-between w-full">
|
||||
<div class=" flex flex-wrap text-sm gap-1 text-gray-500">
|
||||
{#if item?.type === 'collection'}
|
||||
{#if item?.type}
|
||||
<div class="capitalize shrink-0">{item.type}</div>
|
||||
•
|
||||
{/if}
|
||||
|
||||
{#if item?.description}
|
||||
<div class="line-clamp-1">{item.description}</div>
|
||||
•
|
||||
{/if}
|
||||
|
||||
{#if item?.created_at}
|
||||
<div class="capitalize shrink-0">
|
||||
{dayjs(item.created_at * 1000).format('LL')}
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
|
||||
{#if item.size}
|
||||
<div class="capitalize shrink-0">{formatFileSize(item.size)}</div>
|
||||
•
|
||||
|
|
@ -127,7 +146,17 @@
|
|||
</div>
|
||||
|
||||
<div class="max-h-[75vh] overflow-auto">
|
||||
{#if isPDF}
|
||||
{#if item?.type === 'collection'}
|
||||
<div>
|
||||
{#each item?.files as file}
|
||||
<div class="flex items-center gap-2 mb-2">
|
||||
<div class="flex-shrink-0 text-xs">
|
||||
{file?.meta?.name}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
{:else if isPDF}
|
||||
<iframe
|
||||
title={item?.name}
|
||||
src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
|
||||
|
|
|
|||
Loading…
Reference in a new issue