Skip to content

Commit d4a18a5

Browse files
committed
refac: always on web search
1 parent 336984c commit d4a18a5

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

src/lib/components/chat/Chat.svelte

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@
117117
118118
let selectedToolIds = [];
119119
let imageGenerationEnabled = false;
120-
let webSearchEnabled = $settings?.alwaysOnWebSearch ?? false;
120+
let webSearchEnabled = false;
121121
let codeInterpreterEnabled = false;
122122
let chat = null;
123123
let tags = [];
@@ -143,7 +143,7 @@
143143
prompt = '';
144144
files = [];
145145
selectedToolIds = [];
146-
146+
webSearchEnabled = false;
147147
imageGenerationEnabled = false;
148148
149149
if (chatIdProp && (await loadChat())) {
@@ -718,7 +718,7 @@
718718
if ($page.url.searchParams.get('web-search') === 'true') {
719719
webSearchEnabled = true;
720720
}
721-
721+
722722
if ($page.url.searchParams.get('image-generation') === 'true') {
723723
imageGenerationEnabled = true;
724724
}
@@ -1550,9 +1550,20 @@
15501550
tool_ids: selectedToolIds.length > 0 ? selectedToolIds : undefined,
15511551
15521552
features: {
1553-
image_generation: imageGenerationEnabled,
1554-
code_interpreter: codeInterpreterEnabled,
1555-
web_search: webSearchEnabled
1553+
image_generation:
1554+
$config?.features?.enable_image_generation &&
1555+
($user.role === 'admin' || $user?.permissions?.features?.image_generation)
1556+
? imageGenerationEnabled
1557+
: false,
1558+
code_interpreter:
1559+
$user.role === 'admin' || $user?.permissions?.features?.code_interpreter
1560+
? codeInterpreterEnabled
1561+
: false,
1562+
web_search:
1563+
$config?.features?.enable_web_search &&
1564+
($user.role === 'admin' || $user?.permissions?.features?.web_search)
1565+
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
1566+
: false
15561567
},
15571568
variables: {
15581569
...getPromptVariables(

src/lib/components/chat/MessageInput.svelte

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@
390390
</div>
391391

392392
<div class="w-full relative">
393-
{#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || imageGenerationEnabled || codeInterpreterEnabled}
393+
{#if atSelectedModel !== undefined || selectedToolIds.length > 0 || webSearchEnabled || ($settings?.webSearch ?? false) === 'always' || imageGenerationEnabled || codeInterpreterEnabled}
394394
<div
395395
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"
396396
>
@@ -426,7 +426,7 @@
426426
</div>
427427
{/if}
428428

429-
{#if webSearchEnabled}
429+
{#if webSearchEnabled || ($settings?.webSearch ?? false) === 'always'}
430430
<div class="flex items-center justify-between w-full">
431431
<div class="flex items-center gap-2.5 text-sm dark:text-gray-500">
432432
<div class="pl-1">
@@ -1135,7 +1135,8 @@
11351135
<button
11361136
on:click|preventDefault={() => (webSearchEnabled = !webSearchEnabled)}
11371137
type="button"
1138-
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
1138+
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 ||
1139+
($settings?.webSearch ?? false) === 'always'
11391140
? 'bg-blue-100 dark:bg-blue-500/20 text-blue-500 dark:text-blue-400'
11401141
: 'bg-transparent text-gray-600 dark:text-gray-400 border-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800'}"
11411142
>
@@ -1243,7 +1244,8 @@
12431244
<div class=" flex items-center">
12441245
<Tooltip content={$i18n.t('Call')}>
12451246
<button
1246-
class=" {webSearchEnabled
1247+
class=" {webSearchEnabled ||
1248+
($settings?.webSearch ?? false) === 'always'
12471249
? 'bg-blue-500 text-white hover:bg-blue-400 '
12481250
: '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"
12491251
type="button"
@@ -1298,7 +1300,7 @@
12981300
<button
12991301
id="send-message-button"
13001302
class="{prompt !== ''
1301-
? webSearchEnabled
1303+
? webSearchEnabled || ($settings?.webSearch ?? false) === 'always'
13021304
? 'bg-blue-500 text-white hover:bg-blue-400 '
13031305
: 'bg-black text-white hover:bg-gray-900 dark:bg-white dark:text-black dark:hover:bg-gray-100 '
13041306
: 'text-white bg-gray-200 dark:text-gray-900 dark:bg-gray-700 disabled'} transition rounded-full p-1.5 self-center"

src/lib/components/chat/Settings/Interface.svelte

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
let voiceInterruption = false;
5353
let hapticFeedback = false;
5454
55-
let alwaysOnWebSearch = false;
55+
let webSearch = null;
5656
5757
const toggleSplitLargeChunks = async () => {
5858
splitLargeChunks = !splitLargeChunks;
@@ -200,9 +200,9 @@
200200
});
201201
};
202202
203-
const toggleAlwaysOnWebSearch = async () => {
204-
alwaysOnWebSearch = !alwaysOnWebSearch;
205-
saveSettings({ alwaysOnWebSearch });
203+
const toggleWebSearch = async () => {
204+
webSearch = webSearch === null ? 'always' : null;
205+
saveSettings({ webSearch: webSearch });
206206
};
207207
208208
onMount(async () => {
@@ -242,8 +242,7 @@
242242
}
243243
244244
backgroundImageUrl = $settings.backgroundImageUrl ?? null;
245-
246-
alwaysOnWebSearch = $settings.alwaysOnWebSearch ?? false;
245+
webSearch = $settings.webSearch ?? null;
247246
});
248247
</script>
249248

@@ -677,19 +676,19 @@
677676

678677
<div>
679678
<div class=" py-0.5 flex w-full justify-between">
680-
<div class=" self-center text-xs">{$i18n.t('Always-On Web Search')}</div>
679+
<div class=" self-center text-xs">{$i18n.t('Web Search in Chat')}</div>
681680

682681
<button
683682
class="p-1 px-3 text-xs flex rounded transition"
684683
on:click={() => {
685-
toggleAlwaysOnWebSearch();
684+
toggleWebSearch();
686685
}}
687686
type="button"
688687
>
689-
{#if alwaysOnWebSearch === true}
690-
<span class="ml-2 self-center">{$i18n.t('On')}</span>
688+
{#if webSearch === 'always'}
689+
<span class="ml-2 self-center">{$i18n.t('Always')}</span>
691690
{:else}
692-
<span class="ml-2 self-center">{$i18n.t('Off')}</span>
691+
<span class="ml-2 self-center">{$i18n.t('Default')}</span>
693692
{/if}
694693
</button>
695694
</div>

0 commit comments

Comments
 (0)