Timothy Jaeryang Baek 2 周之前
父节点
当前提交
b1006a2b57
共有 1 个文件被更改,包括 39 次插入25 次删除
  1. 39 25
      src/lib/components/chat/MessageInput/InputMenu.svelte

+ 39 - 25
src/lib/components/chat/MessageInput/InputMenu.svelte

@@ -5,6 +5,8 @@
 	import { flyAndScale } from '$lib/utils/transitions';
 	import { flyAndScale } from '$lib/utils/transitions';
 
 
 	import { config, user, tools as _tools, mobile, knowledge, chats } from '$lib/stores';
 	import { config, user, tools as _tools, mobile, knowledge, chats } from '$lib/stores';
+	import { getKnowledgeBases } from '$lib/apis/knowledge';
+
 	import { createPicker } from '$lib/utils/google-drive-picker';
 	import { createPicker } from '$lib/utils/google-drive-picker';
 
 
 	import Dropdown from '$lib/components/common/Dropdown.svelte';
 	import Dropdown from '$lib/components/common/Dropdown.svelte';
@@ -67,6 +69,16 @@
 		}
 		}
 	};
 	};
 
 
+	const init = async () => {
+		if ($knowledge === null) {
+			await knowledge.set(await getKnowledgeBases(localStorage.token));
+		}
+	};
+
+	$: if (show) {
+		init();
+	}
+
 	const onSelect = (item) => {
 	const onSelect = (item) => {
 		if (files.find((f) => f.id === item.id)) {
 		if (files.find((f) => f.id === item.id)) {
 			return;
 			return;
@@ -220,35 +232,37 @@
 						</Tooltip>
 						</Tooltip>
 					{/if}
 					{/if}
 
 
-					<Tooltip
-						content={fileUploadCapableModels.length !== selectedModels.length
-							? $i18n.t('Model(s) do not support file upload')
-							: !fileUploadEnabled
-								? $i18n.t('You do not have permission to upload files.')
-								: ''}
-						className="w-full"
-					>
-						<button
-							class="flex gap-2 w-full items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 rounded-xl {!fileUploadEnabled
-								? 'opacity-50'
-								: ''}"
-							on:click={() => {
-								tab = 'knowledge';
-							}}
+					{#if ($knowledge ?? []).length > 0}
+						<Tooltip
+							content={fileUploadCapableModels.length !== selectedModels.length
+								? $i18n.t('Model(s) do not support file upload')
+								: !fileUploadEnabled
+									? $i18n.t('You do not have permission to upload files.')
+									: ''}
+							className="w-full"
 						>
 						>
-							<Database />
+							<button
+								class="flex gap-2 w-full items-center px-3 py-1.5 text-sm cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-800/50 rounded-xl {!fileUploadEnabled
+									? 'opacity-50'
+									: ''}"
+								on:click={() => {
+									tab = 'knowledge';
+								}}
+							>
+								<Database />
 
 
-							<div class="flex items-center w-full justify-between">
-								<div class=" line-clamp-1">
-									{$i18n.t('Attach Knowledge')}
-								</div>
+								<div class="flex items-center w-full justify-between">
+									<div class=" line-clamp-1">
+										{$i18n.t('Attach Knowledge')}
+									</div>
 
 
-								<div class="text-gray-500">
-									<ChevronRight />
+									<div class="text-gray-500">
+										<ChevronRight />
+									</div>
 								</div>
 								</div>
-							</div>
-						</button>
-					</Tooltip>
+							</button>
+						</Tooltip>
+					{/if}
 
 
 					{#if ($chats ?? []).length > 0}
 					{#if ($chats ?? []).length > 0}
 						<Tooltip
 						<Tooltip