forked from open-webui/open-webui
		
	feat: query all documents
This commit is contained in:
		
							parent
							
								
									3858485675
								
							
						
					
					
						commit
						eb2b1ab77b
					
				
					 4 changed files with 27 additions and 18 deletions
				
			
		| 
						 | 
				
			
			@ -468,7 +468,7 @@
 | 
			
		|||
 | 
			
		||||
											<div class="flex flex-col justify-center -space-y-0.5">
 | 
			
		||||
												<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
 | 
			
		||||
													#{file.name}
 | 
			
		||||
													{file?.title ?? `#${file.name}`}
 | 
			
		||||
												</div>
 | 
			
		||||
 | 
			
		||||
												<div class=" text-gray-500 text-sm">Collection</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,34 +13,43 @@
 | 
			
		|||
 | 
			
		||||
	let filteredItems = [];
 | 
			
		||||
	let filteredDocs = [];
 | 
			
		||||
	let filteredTags = [];
 | 
			
		||||
 | 
			
		||||
	let collections = [];
 | 
			
		||||
 | 
			
		||||
	$: collections = $documents
 | 
			
		||||
		.reduce((a, e, i, arr) => {
 | 
			
		||||
			return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])];
 | 
			
		||||
		}, [])
 | 
			
		||||
		.map((tag) => ({
 | 
			
		||||
			name: tag,
 | 
			
		||||
	$: collections = [
 | 
			
		||||
		{
 | 
			
		||||
			name: 'All Documents',
 | 
			
		||||
			type: 'collection',
 | 
			
		||||
			collection_names: $documents
 | 
			
		||||
				.filter((doc) => (doc?.content?.tags ?? []).map((tag) => tag.name).includes(tag))
 | 
			
		||||
				.map((doc) => doc.collection_name)
 | 
			
		||||
		}));
 | 
			
		||||
			title: 'All Documents',
 | 
			
		||||
			collection_names: $documents.map((doc) => doc.collection_name)
 | 
			
		||||
		},
 | 
			
		||||
		...$documents
 | 
			
		||||
			.reduce((a, e, i, arr) => {
 | 
			
		||||
				return [...new Set([...a, ...(e?.content?.tags ?? []).map((tag) => tag.name)])];
 | 
			
		||||
			}, [])
 | 
			
		||||
			.map((tag) => ({
 | 
			
		||||
				name: tag,
 | 
			
		||||
				type: 'collection',
 | 
			
		||||
				collection_names: $documents
 | 
			
		||||
					.filter((doc) => (doc?.content?.tags ?? []).map((tag) => tag.name).includes(tag))
 | 
			
		||||
					.map((doc) => doc.collection_name)
 | 
			
		||||
			}))
 | 
			
		||||
	];
 | 
			
		||||
 | 
			
		||||
	$: filteredCollections = collections
 | 
			
		||||
		.filter((tag) => tag.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
 | 
			
		||||
		.filter((collection) => collection.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
 | 
			
		||||
		.sort((a, b) => a.name.localeCompare(b.name));
 | 
			
		||||
 | 
			
		||||
	$: filteredDocs = $documents
 | 
			
		||||
		.filter((p) => p.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
 | 
			
		||||
		.filter((doc) => doc.name.includes(prompt.split(' ')?.at(0)?.substring(1) ?? ''))
 | 
			
		||||
		.sort((a, b) => a.title.localeCompare(b.title));
 | 
			
		||||
 | 
			
		||||
	$: filteredItems = [...filteredCollections, ...filteredDocs];
 | 
			
		||||
 | 
			
		||||
	$: if (prompt) {
 | 
			
		||||
		selectedIdx = 0;
 | 
			
		||||
 | 
			
		||||
		console.log(filteredCollections);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	export const selectUp = () => {
 | 
			
		||||
| 
						 | 
				
			
			@ -74,7 +83,7 @@
 | 
			
		|||
	};
 | 
			
		||||
</script>
 | 
			
		||||
 | 
			
		||||
{#if filteredDocs.length > 0 || prompt.split(' ')?.at(0)?.substring(1).startsWith('http')}
 | 
			
		||||
{#if filteredItems.length > 0 || prompt.split(' ')?.at(0)?.substring(1).startsWith('http')}
 | 
			
		||||
	<div class="md:px-2 mb-3 text-left w-full">
 | 
			
		||||
		<div class="flex w-full rounded-lg border border-gray-100 dark:border-gray-700">
 | 
			
		||||
			<div class=" bg-gray-100 dark:bg-gray-700 w-10 rounded-l-lg text-center">
 | 
			
		||||
| 
						 | 
				
			
			@ -101,7 +110,7 @@
 | 
			
		|||
						>
 | 
			
		||||
							{#if doc.type === 'collection'}
 | 
			
		||||
								<div class=" font-medium text-black line-clamp-1">
 | 
			
		||||
									#{doc.name}
 | 
			
		||||
									{doc?.title ?? `#${doc.name}`}
 | 
			
		||||
								</div>
 | 
			
		||||
 | 
			
		||||
								<div class=" text-xs text-gray-600 line-clamp-1">Collection</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -140,7 +140,7 @@
 | 
			
		|||
 | 
			
		||||
									<div class="flex flex-col justify-center -space-y-0.5">
 | 
			
		||||
										<div class=" dark:text-gray-100 text-sm font-medium line-clamp-1">
 | 
			
		||||
											#{file.name}
 | 
			
		||||
											{file?.title ?? `#${file.name}`}
 | 
			
		||||
										</div>
 | 
			
		||||
 | 
			
		||||
										<div class=" text-gray-500 text-sm">Collection</div>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue