feat: mark websearch docs differently from standard docs

This commit is contained in:
Jun Siang Cheah 2024-05-12 16:05:00 +08:00
parent 3baeda7edc
commit d98051862d
3 changed files with 44 additions and 11 deletions

View File

@ -159,6 +159,38 @@
<div class=" text-gray-500 text-sm">{$i18n.t('Collection')}</div> <div class=" text-gray-500 text-sm">{$i18n.t('Collection')}</div>
</div> </div>
</button> </button>
{:else if file.type === 'websearch'}
<button
class="h-16 w-[15rem] flex items-center space-x-3 px-2.5 dark:bg-gray-600 rounded-xl border border-gray-200 dark:border-none text-left"
type="button"
>
<div class="p-2.5 bg-red-400 text-white rounded-lg">
<svg
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="currentColor"
class="w-6 h-6"
>
<path d="M11.625 16.5a1.875 1.875 0 1 0 0-3.75 1.875 1.875 0 0 0 0 3.75Z" />
<path
fill-rule="evenodd"
d="M5.625 1.5H9a3.75 3.75 0 0 1 3.75 3.75v1.875c0 1.036.84 1.875 1.875 1.875H16.5a3.75 3.75 0 0 1 3.75 3.75v7.875c0 1.035-.84 1.875-1.875 1.875H5.625a1.875 1.875 0 0 1-1.875-1.875V3.375c0-1.036.84-1.875 1.875-1.875Zm6 16.5c.66 0 1.277-.19 1.797-.518l1.048 1.048a.75.75 0 0 0 1.06-1.06l-1.047-1.048A3.375 3.375 0 1 0 11.625 18Z"
clip-rule="evenodd"
/>
<path
d="M14.25 5.25a5.23 5.23 0 0 0-1.279-3.434 9.768 9.768 0 0 1 6.963 6.963A5.23 5.23 0 0 0 16.5 7.5h-1.875a.375.375 0 0 1-.375-.375V5.25Z"
/>
</svg>
</div>
<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}
</div>
<div class=" text-gray-500 text-sm">{$i18n.t('Search Results')}</div>
</div>
</button>
{/if} {/if}
</div> </div>
{/each} {/each}

View File

@ -334,7 +334,7 @@
parentMessage.files.push({ parentMessage.files.push({
collection_name: searchDocument!.collection_name, collection_name: searchDocument!.collection_name,
name: searchQuery, name: searchQuery,
type: 'doc', type: 'websearch',
upload_status: true, upload_status: true,
error: '' error: ''
}); });
@ -401,7 +401,7 @@
const docs = messages const docs = messages
.filter((message) => message?.files ?? null) .filter((message) => message?.files ?? null)
.map((message) => .map((message) =>
message.files.filter((item) => item.type === 'doc' || item.type === 'collection') message.files.filter((item) => ['doc', 'collection', 'websearch'].includes(item.type))
) )
.flat(1); .flat(1);
@ -594,7 +594,7 @@
const docs = messages const docs = messages
.filter((message) => message?.files ?? null) .filter((message) => message?.files ?? null)
.map((message) => .map((message) =>
message.files.filter((item) => item.type === 'doc' || item.type === 'collection') message.files.filter((item) => ['doc', 'collection', 'websearch'].includes(item.type))
) )
.flat(1); .flat(1);

View File

@ -30,7 +30,11 @@
getTagsById, getTagsById,
updateChatById updateChatById
} from '$lib/apis/chats'; } from '$lib/apis/chats';
import { generateOpenAIChatCompletion, generateSearchQuery, generateTitle } from '$lib/apis/openai'; import {
generateOpenAIChatCompletion,
generateSearchQuery,
generateTitle
} from '$lib/apis/openai';
import MessageInput from '$lib/components/chat/MessageInput.svelte'; import MessageInput from '$lib/components/chat/MessageInput.svelte';
import Messages from '$lib/components/chat/Messages.svelte'; import Messages from '$lib/components/chat/Messages.svelte';
@ -321,10 +325,7 @@
} }
responseMessage.progress = $i18n.t("Searching the web for '{{searchQuery}}'", { searchQuery }); responseMessage.progress = $i18n.t("Searching the web for '{{searchQuery}}'", { searchQuery });
messages = messages; messages = messages;
const searchDocument = await runWebSearch( const searchDocument = await runWebSearch(localStorage.token, searchQuery);
localStorage.token,
searchQuery,
);
if (!searchDocument) { if (!searchDocument) {
toast.warning($i18n.t('No search results found')); toast.warning($i18n.t('No search results found'));
responseMessage.progress = undefined; responseMessage.progress = undefined;
@ -338,7 +339,7 @@
parentMessage.files.push({ parentMessage.files.push({
collection_name: searchDocument!.collection_name, collection_name: searchDocument!.collection_name,
name: searchQuery, name: searchQuery,
type: 'doc', type: 'websearch',
upload_status: true, upload_status: true,
error: '' error: ''
}); });
@ -405,7 +406,7 @@
const docs = messages const docs = messages
.filter((message) => message?.files ?? null) .filter((message) => message?.files ?? null)
.map((message) => .map((message) =>
message.files.filter((item) => item.type === 'doc' || item.type === 'collection') message.files.filter((item) => ['doc', 'collection', 'websearch'].includes(item.type))
) )
.flat(1); .flat(1);
@ -598,7 +599,7 @@
const docs = messages const docs = messages
.filter((message) => message?.files ?? null) .filter((message) => message?.files ?? null)
.map((message) => .map((message) =>
message.files.filter((item) => item.type === 'doc' || item.type === 'collection') message.files.filter((item) => ['doc', 'collection', 'websearch'].includes(item.type))
) )
.flat(1); .flat(1);