Skip to content

Commit 0fcf19a

Browse files
authored
fix: (#621)
- query param sets model correctly - fix bugs related to preprompt
1 parent 4846e0f commit 0fcf19a

File tree

6 files changed

+22
-31
lines changed

6 files changed

+22
-31
lines changed

src/lib/components/chat/ChatIntroduction.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,16 @@
99
import AnnouncementBanner from "../AnnouncementBanner.svelte";
1010
import type { Model } from "$lib/types/Model";
1111
import ModelCardMetadata from "../ModelCardMetadata.svelte";
12-
import type { LayoutData } from "../../../routes/$types";
1312
import { findCurrentModel } from "$lib/utils/models";
1413
import { base } from "$app/paths";
14+
import { useSettingsStore } from "$lib/stores/settings";
1515
1616
export let currentModel: Model;
17-
export let settings: LayoutData["settings"];
1817
export let models: Model[];
1918
20-
$: currentModelMetadata = findCurrentModel(models, settings.activeModel);
19+
const settings = useSettingsStore();
20+
21+
$: currentModelMetadata = findCurrentModel(models, $settings.activeModel);
2122
2223
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
2324
? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS)

src/lib/components/chat/ChatMessages.svelte

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,17 @@
55
import { tick } from "svelte";
66
import { randomUUID } from "$lib/utils/randomUuid";
77
import type { Model } from "$lib/types/Model";
8-
import type { LayoutData } from "../../../routes/$types";
98
import ChatIntroduction from "./ChatIntroduction.svelte";
109
import ChatMessage from "./ChatMessage.svelte";
1110
import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
1211
import { browser } from "$app/environment";
1312
import SystemPromptModal from "../SystemPromptModal.svelte";
14-
import { page } from "$app/stores";
1513
1614
export let messages: Message[];
1715
export let loading: boolean;
1816
export let pending: boolean;
1917
export let isAuthor: boolean;
2018
export let currentModel: Model;
21-
export let settings: LayoutData["settings"];
2219
export let models: Model[];
2320
export let preprompt: string | undefined;
2421
export let readOnly: boolean;
@@ -45,7 +42,7 @@
4542
>
4643
<div class="mx-auto flex h-full max-w-3xl flex-col gap-6 px-5 pt-6 sm:gap-8 xl:max-w-4xl">
4744
{#each messages as message, i}
48-
{#if i === 0 && preprompt !== $page.data.settings.customPrompts[currentModel.id]}
45+
{#if i === 0 && preprompt && preprompt != currentModel.preprompt}
4946
<SystemPromptModal preprompt={preprompt ?? ""} />
5047
{/if}
5148
<ChatMessage
@@ -59,7 +56,7 @@
5956
on:vote
6057
/>
6158
{:else}
62-
<ChatIntroduction {settings} {models} {currentModel} on:message />
59+
<ChatIntroduction {models} {currentModel} on:message />
6360
{/each}
6461
{#if pending}
6562
<ChatMessage

src/lib/components/chat/ChatWindow.svelte

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@
8888
<ChatMessages
8989
{loading}
9090
{pending}
91-
settings={$page.data.settings}
9291
{currentModel}
9392
{models}
9493
{messages}

src/routes/+layout.server.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { redirect } from "@sveltejs/kit";
21
import type { LayoutServerLoad } from "./$types";
32
import { collections } from "$lib/server/database";
43
import type { Conversation } from "$lib/types/Conversation";
@@ -14,26 +13,10 @@ import {
1413
USE_LOCAL_WEBSEARCH,
1514
} from "$env/static/private";
1615

17-
export const load: LayoutServerLoad = async ({ locals, depends, url }) => {
16+
export const load: LayoutServerLoad = async ({ locals, depends }) => {
1817
const { conversations } = collections;
19-
const urlModel = url.searchParams.get("model");
20-
2118
depends(UrlDependency.ConversationList);
2219

23-
if (urlModel) {
24-
const isValidModel = validateModel(models).safeParse(urlModel).success;
25-
26-
if (isValidModel) {
27-
await collections.settings.updateOne(
28-
authCondition(locals),
29-
{ $set: { activeModel: urlModel } },
30-
{ upsert: true }
31-
);
32-
}
33-
34-
throw redirect(302, url.pathname);
35-
}
36-
3720
const settings = await collections.settings.findOne(authCondition(locals));
3821

3922
// If the active model in settings is not valid, set it to the default model. This can happen if model was disabled.

src/routes/+layout.svelte

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import { PUBLIC_APP_ASSETS, PUBLIC_APP_NAME } from "$env/static/public";
1717
import titleUpdate from "$lib/stores/titleUpdate";
1818
import { createSettingsStore } from "$lib/stores/settings";
19+
import { browser } from "$app/environment";
1920
2021
export let data;
2122
@@ -104,7 +105,14 @@
104105
$titleUpdate = null;
105106
}
106107
107-
createSettingsStore(data.settings);
108+
const settings = createSettingsStore(data.settings);
109+
110+
$: if (browser && $page.url.searchParams.has("model")) {
111+
if ($settings.activeModel === $page.url.searchParams.get("model")) {
112+
goto("/?");
113+
}
114+
$settings.activeModel = $page.url.searchParams.get("model") ?? $settings.activeModel;
115+
}
108116
</script>
109117

110118
<svelte:head>

src/routes/+page.svelte

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@
55
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
66
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
77
import { pendingMessage } from "$lib/stores/pendingMessage";
8+
import { useSettingsStore } from "$lib/stores/settings.js";
89
import { findCurrentModel } from "$lib/utils/models";
910
1011
export let data;
1112
let loading = false;
1213
let files: File[] = [];
1314
15+
const settings = useSettingsStore();
16+
1417
async function createConversation(message: string) {
1518
try {
1619
loading = true;
@@ -20,8 +23,8 @@
2023
"Content-Type": "application/json",
2124
},
2225
body: JSON.stringify({
23-
model: data.settings.activeModel,
24-
preprompt: data.settings.customPrompts[data.settings.activeModel],
26+
model: $settings.activeModel,
27+
preprompt: $settings.customPrompts[data.settings.activeModel],
2528
}),
2629
});
2730
@@ -57,7 +60,7 @@
5760
<ChatWindow
5861
on:message={(ev) => createConversation(ev.detail)}
5962
{loading}
60-
currentModel={findCurrentModel([...data.models, ...data.oldModels], data.settings.activeModel)}
63+
currentModel={findCurrentModel([...data.models, ...data.oldModels], $settings.activeModel)}
6164
models={data.models}
6265
bind:files
6366
/>

0 commit comments

Comments
 (0)