refac: always on web search

This commit is contained in:
Timothy Jaeryang Baek 2025-02-05 00:37:47 -08:00
parent 336984c254
commit d4a18a5765
3 changed files with 34 additions and 22 deletions

View File

@ -117,7 +117,7 @@
let selectedToolIds = [];
let imageGenerationEnabled = false;
let webSearchEnabled = $settings?.alwaysOnWebSearch ?? false;
let webSearchEnabled = false;
let codeInterpreterEnabled = false;
let chat = null;
let tags = [];
@ -143,7 +143,7 @@
prompt = '';
files = [];
selectedToolIds = [];
webSearchEnabled = false;
imageGenerationEnabled = false;
if (chatIdProp && (await loadChat())) {
@ -718,7 +718,7 @@
if ($page.url.searchParams.get('web-search') === 'true') {
webSearchEnabled = true;
}
if ($page.url.searchParams.get('image-generation') === 'true') {
imageGenerationEnabled = true;
}
@ -1550,9 +1550,20 @@
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
features: {
image_generation: imageGenerationEnabled,
code_interpreter: codeInterpreterEnabled,
web_search: webSearchEnabled
image_generation:
$config?.features?.enable_image_generation &&
($user.role === 'admin' || $user?.permissions?.features?.image_generation)
? imageGenerationEnabled
: false,
code_interpreter:
$user.role === 'admin' || $user?.permissions?.features?.code_interpreter
? codeInterpreterEnabled
: false,
web_search:
$config?.features?.enable_web_search &&
($user.role === 'admin' || $user?.permissions?.features?.web_search)
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
: false
},
variables: {
...getPromptVariables(

View File

@ -390,7 +390,7 @@
</div>
<div class="w-full relative">
{#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || imageGenerationEnabled || codeInterpreterEnabled}
{#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || ($settings?.webSearch ?? false) === 'always' || imageGenerationEnabled || codeInterpreterEnabled}
<div
class="px-3 pb-0.5 pt-1.5 text-left w-full flex flex-col absolute bottom-0 left-0 right-0 bg-gradient-to-t from-white dark:from-gray-900 z-10"
>
@ -426,7 +426,7 @@
</div>
{/if}
{#if webSearchEnabled}
{#if webSearchEnabled || ($settings?.webSearch ?? false) === 'always'}
<div class="flex items-center justify-between w-full">
<div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
<div class="pl-1">
@ -1135,7 +1135,8 @@
<button
on:click|preventDefault={() => (webSearchEnabled = !webSearchEnabled)}
type="button"
class="px-1.5 sm:px-2.5 py-1.5 flex gap-1.5 items-center text-sm rounded-full font-medium transition-colors duration-300 focus:outline-none max-w-full overflow-hidden {webSearchEnabled
class="px-1.5 sm:px-2.5 py-1.5 flex gap-1.5 items-center text-sm rounded-full font-medium transition-colors duration-300 focus:outline-none max-w-full overflow-hidden {webSearchEnabled ||
($settings?.webSearch ?? false) === 'always'
? 'bg-blue-100 dark:bg-blue-500/20 text-blue-500 dark:text-blue-400'
: 'bg-transparent text-gray-600 dark:text-gray-400 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800'}"
>
@ -1243,7 +1244,8 @@
<div class=" flex items-center">
<Tooltip content={$i18n.t('Call')}>
<button
class=" {webSearchEnabled
class=" {webSearchEnabled ||
($settings?.webSearch ?? false) === 'always'
? 'bg-blue-500 text-white hover:bg-blue-400 '
: 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100'} transition rounded-full p-1.5 self-center"
type="button"
@ -1298,7 +1300,7 @@
<button
id="send-message-button"
class="{prompt !== ''
? webSearchEnabled
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
? 'bg-blue-500 text-white hover:bg-blue-400 '
: 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100 '
: 'text-white bg-gray-200 dark:text-gray-900 dark:bg-gray-700 disabled'} transition rounded-full p-1.5 self-center"

View File

@ -52,7 +52,7 @@
let voiceInterruption = false;
let hapticFeedback = false;
let alwaysOnWebSearch = false;
let webSearch = null;
const toggleSplitLargeChunks = async () => {
splitLargeChunks = !splitLargeChunks;
@ -200,9 +200,9 @@
});
};
const toggleAlwaysOnWebSearch = async () => {
alwaysOnWebSearch = !alwaysOnWebSearch;
saveSettings({ alwaysOnWebSearch });
const toggleWebSearch = async () => {
webSearch = webSearch === null ? 'always' : null;
saveSettings({ webSearch: webSearch });
};
onMount(async () => {
@ -242,8 +242,7 @@
}
backgroundImageUrl = $settings.backgroundImageUrl ?? null;
alwaysOnWebSearch = $settings.alwaysOnWebSearch ?? false;
webSearch = $settings.webSearch ?? null;
});
</script>
@ -677,19 +676,19 @@
<div>
<div class=" py-0.5 flex w-full justify-between">
<div class=" self-center text-xs">{$i18n.t('Always-On Web Search')}</div>
<div class=" self-center text-xs">{$i18n.t('Web Search in Chat')}</div>
<button
class="p-1 px-3 text-xs flex rounded transition"
on:click={() => {
toggleAlwaysOnWebSearch();
toggleWebSearch();
}}
type="button"
>
{#if alwaysOnWebSearch === true}
<span class="ml-2 self-center">{$i18n.t('On')}</span>
{#if webSearch === 'always'}
<span class="ml-2 self-center">{$i18n.t('Always')}</span>
{:else}
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
{/if}
</button>
</div>