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", "")]],
|
"documents": [[note.data.get("content", {}).get("md", "")]],
|
||||||
"metadatas": [[{"file_id": note.id, "name": note.title}]],
|
"metadatas": [[{"file_id": note.id, "name": note.title}]],
|
||||||
}
|
}
|
||||||
elif file.get("context") == "full" and file.get("type") == "file":
|
elif file.get("context") == "full":
|
||||||
# Manual Full Mode Toggle
|
if file.get("type") == "file":
|
||||||
query_result = {
|
# Manual Full Mode Toggle
|
||||||
"documents": [[file.get("file").get("data", {}).get("content")]],
|
query_result = {
|
||||||
"metadatas": [[{"file_id": file.get("id"), "name": file.get("name")}]],
|
"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 (
|
elif (
|
||||||
file.get("type") != "web_search"
|
file.get("type") != "web_search"
|
||||||
and request.app.state.config.BYPASS_EMBEDDING_AND_RETRIEVAL
|
and request.app.state.config.BYPASS_EMBEDDING_AND_RETRIEVAL
|
||||||
|
|
|
||||||
|
|
@ -1145,18 +1145,8 @@
|
||||||
loading={file.status === 'uploading'}
|
loading={file.status === 'uploading'}
|
||||||
dismissible={true}
|
dismissible={true}
|
||||||
edit={true}
|
edit={true}
|
||||||
|
modal={true}
|
||||||
on:dismiss={async () => {
|
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
|
// Remove from UI state
|
||||||
files.splice(fileIdx, 1);
|
files.splice(fileIdx, 1);
|
||||||
files = files;
|
files = files;
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@
|
||||||
export let url: string | null = null;
|
export let url: string | null = null;
|
||||||
|
|
||||||
export let dismissible = false;
|
export let dismissible = false;
|
||||||
|
export let modal = false;
|
||||||
export let loading = false;
|
export let loading = false;
|
||||||
|
|
||||||
export let item = null;
|
export let item = null;
|
||||||
|
|
@ -50,7 +51,7 @@
|
||||||
: 'rounded-2xl'} text-left"
|
: 'rounded-2xl'} text-left"
|
||||||
type="button"
|
type="button"
|
||||||
on:click={async () => {
|
on:click={async () => {
|
||||||
if (item?.file?.data?.content) {
|
if (item?.file?.data?.content || modal) {
|
||||||
showModal = !showModal;
|
showModal = !showModal;
|
||||||
} else {
|
} else {
|
||||||
if (url) {
|
if (url) {
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
import Info from '../icons/Info.svelte';
|
import Info from '../icons/Info.svelte';
|
||||||
import Switch from './Switch.svelte';
|
import Switch from './Switch.svelte';
|
||||||
import Tooltip from './Tooltip.svelte';
|
import Tooltip from './Tooltip.svelte';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
export let item;
|
export let item;
|
||||||
export let show = false;
|
export let show = false;
|
||||||
|
|
@ -77,6 +78,24 @@
|
||||||
<div>
|
<div>
|
||||||
<div class="flex flex-col items-center md:flex-row gap-1 justify-between w-full">
|
<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">
|
<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}
|
{#if item.size}
|
||||||
<div class="capitalize shrink-0">{formatFileSize(item.size)}</div>
|
<div class="capitalize shrink-0">{formatFileSize(item.size)}</div>
|
||||||
•
|
•
|
||||||
|
|
@ -127,7 +146,17 @@
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="max-h-[75vh] overflow-auto">
|
<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
|
<iframe
|
||||||
title={item?.name}
|
title={item?.name}
|
||||||
src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
|
src={`${WEBUI_API_BASE_URL}/files/${item.id}/content`}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue