Spaces:
Paused
Paused
fix: (#621)
Browse files- query param sets model correctly
- fix bugs related to preprompt
src/lib/components/chat/ChatIntroduction.svelte
CHANGED
|
@@ -9,15 +9,16 @@
|
|
| 9 |
import AnnouncementBanner from "../AnnouncementBanner.svelte";
|
| 10 |
import type { Model } from "$lib/types/Model";
|
| 11 |
import ModelCardMetadata from "../ModelCardMetadata.svelte";
|
| 12 |
-
import type { LayoutData } from "../../../routes/$types";
|
| 13 |
import { findCurrentModel } from "$lib/utils/models";
|
| 14 |
import { base } from "$app/paths";
|
|
|
|
| 15 |
|
| 16 |
export let currentModel: Model;
|
| 17 |
-
export let settings: LayoutData["settings"];
|
| 18 |
export let models: Model[];
|
| 19 |
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
|
| 23 |
? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
|
|
|
|
| 9 |
import AnnouncementBanner from "../AnnouncementBanner.svelte";
|
| 10 |
import type { Model } from "$lib/types/Model";
|
| 11 |
import ModelCardMetadata from "../ModelCardMetadata.svelte";
|
|
|
|
| 12 |
import { findCurrentModel } from "$lib/utils/models";
|
| 13 |
import { base } from "$app/paths";
|
| 14 |
+
import { useSettingsStore } from "$lib/stores/settings";
|
| 15 |
|
| 16 |
export let currentModel: Model;
|
|
|
|
| 17 |
export let models: Model[];
|
| 18 |
|
| 19 |
+
const settings = useSettingsStore();
|
| 20 |
+
|
| 21 |
+
$: currentModelMetadata = findCurrentModel(models, $settings.activeModel);
|
| 22 |
|
| 23 |
const announcementBanners = PUBLIC_ANNOUNCEMENT_BANNERS
|
| 24 |
? JSON.parse(PUBLIC_ANNOUNCEMENT_BANNERS)
|
src/lib/components/chat/ChatMessages.svelte
CHANGED
|
@@ -5,20 +5,17 @@
|
|
| 5 |
import { tick } from "svelte";
|
| 6 |
import { randomUUID } from "$lib/utils/randomUuid";
|
| 7 |
import type { Model } from "$lib/types/Model";
|
| 8 |
-
import type { LayoutData } from "../../../routes/$types";
|
| 9 |
import ChatIntroduction from "./ChatIntroduction.svelte";
|
| 10 |
import ChatMessage from "./ChatMessage.svelte";
|
| 11 |
import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
|
| 12 |
import { browser } from "$app/environment";
|
| 13 |
import SystemPromptModal from "../SystemPromptModal.svelte";
|
| 14 |
-
import { page } from "$app/stores";
|
| 15 |
|
| 16 |
export let messages: Message[];
|
| 17 |
export let loading: boolean;
|
| 18 |
export let pending: boolean;
|
| 19 |
export let isAuthor: boolean;
|
| 20 |
export let currentModel: Model;
|
| 21 |
-
export let settings: LayoutData["settings"];
|
| 22 |
export let models: Model[];
|
| 23 |
export let preprompt: string | undefined;
|
| 24 |
export let readOnly: boolean;
|
|
@@ -45,7 +42,7 @@
|
|
| 45 |
>
|
| 46 |
<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">
|
| 47 |
{#each messages as message, i}
|
| 48 |
-
{#if i === 0 && preprompt
|
| 49 |
<SystemPromptModal preprompt={preprompt ?? ""} />
|
| 50 |
{/if}
|
| 51 |
<ChatMessage
|
|
@@ -59,7 +56,7 @@
|
|
| 59 |
on:vote
|
| 60 |
/>
|
| 61 |
{:else}
|
| 62 |
-
<ChatIntroduction {
|
| 63 |
{/each}
|
| 64 |
{#if pending}
|
| 65 |
<ChatMessage
|
|
|
|
| 5 |
import { tick } from "svelte";
|
| 6 |
import { randomUUID } from "$lib/utils/randomUuid";
|
| 7 |
import type { Model } from "$lib/types/Model";
|
|
|
|
| 8 |
import ChatIntroduction from "./ChatIntroduction.svelte";
|
| 9 |
import ChatMessage from "./ChatMessage.svelte";
|
| 10 |
import type { WebSearchUpdate } from "$lib/types/MessageUpdate";
|
| 11 |
import { browser } from "$app/environment";
|
| 12 |
import SystemPromptModal from "../SystemPromptModal.svelte";
|
|
|
|
| 13 |
|
| 14 |
export let messages: Message[];
|
| 15 |
export let loading: boolean;
|
| 16 |
export let pending: boolean;
|
| 17 |
export let isAuthor: boolean;
|
| 18 |
export let currentModel: Model;
|
|
|
|
| 19 |
export let models: Model[];
|
| 20 |
export let preprompt: string | undefined;
|
| 21 |
export let readOnly: boolean;
|
|
|
|
| 42 |
>
|
| 43 |
<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">
|
| 44 |
{#each messages as message, i}
|
| 45 |
+
{#if i === 0 && preprompt && preprompt != currentModel.preprompt}
|
| 46 |
<SystemPromptModal preprompt={preprompt ?? ""} />
|
| 47 |
{/if}
|
| 48 |
<ChatMessage
|
|
|
|
| 56 |
on:vote
|
| 57 |
/>
|
| 58 |
{:else}
|
| 59 |
+
<ChatIntroduction {models} {currentModel} on:message />
|
| 60 |
{/each}
|
| 61 |
{#if pending}
|
| 62 |
<ChatMessage
|
src/lib/components/chat/ChatWindow.svelte
CHANGED
|
@@ -88,7 +88,6 @@
|
|
| 88 |
<ChatMessages
|
| 89 |
{loading}
|
| 90 |
{pending}
|
| 91 |
-
settings={$page.data.settings}
|
| 92 |
{currentModel}
|
| 93 |
{models}
|
| 94 |
{messages}
|
|
|
|
| 88 |
<ChatMessages
|
| 89 |
{loading}
|
| 90 |
{pending}
|
|
|
|
| 91 |
{currentModel}
|
| 92 |
{models}
|
| 93 |
{messages}
|
src/routes/+layout.server.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
import { redirect } from "@sveltejs/kit";
|
| 2 |
import type { LayoutServerLoad } from "./$types";
|
| 3 |
import { collections } from "$lib/server/database";
|
| 4 |
import type { Conversation } from "$lib/types/Conversation";
|
|
@@ -14,26 +13,10 @@ import {
|
|
| 14 |
USE_LOCAL_WEBSEARCH,
|
| 15 |
} from "$env/static/private";
|
| 16 |
|
| 17 |
-
export const load: LayoutServerLoad = async ({ locals, depends
|
| 18 |
const { conversations } = collections;
|
| 19 |
-
const urlModel = url.searchParams.get("model");
|
| 20 |
-
|
| 21 |
depends(UrlDependency.ConversationList);
|
| 22 |
|
| 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 |
-
|
| 37 |
const settings = await collections.settings.findOne(authCondition(locals));
|
| 38 |
|
| 39 |
// If the active model in settings is not valid, set it to the default model. This can happen if model was disabled.
|
|
|
|
|
|
|
| 1 |
import type { LayoutServerLoad } from "./$types";
|
| 2 |
import { collections } from "$lib/server/database";
|
| 3 |
import type { Conversation } from "$lib/types/Conversation";
|
|
|
|
| 13 |
USE_LOCAL_WEBSEARCH,
|
| 14 |
} from "$env/static/private";
|
| 15 |
|
| 16 |
+
export const load: LayoutServerLoad = async ({ locals, depends }) => {
|
| 17 |
const { conversations } = collections;
|
|
|
|
|
|
|
| 18 |
depends(UrlDependency.ConversationList);
|
| 19 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
const settings = await collections.settings.findOne(authCondition(locals));
|
| 21 |
|
| 22 |
// 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
CHANGED
|
@@ -16,6 +16,7 @@
|
|
| 16 |
import { PUBLIC_APP_ASSETS, PUBLIC_APP_NAME } from "$env/static/public";
|
| 17 |
import titleUpdate from "$lib/stores/titleUpdate";
|
| 18 |
import { createSettingsStore } from "$lib/stores/settings";
|
|
|
|
| 19 |
|
| 20 |
export let data;
|
| 21 |
|
|
@@ -104,7 +105,14 @@
|
|
| 104 |
$titleUpdate = null;
|
| 105 |
}
|
| 106 |
|
| 107 |
-
createSettingsStore(data.settings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
</script>
|
| 109 |
|
| 110 |
<svelte:head>
|
|
|
|
| 16 |
import { PUBLIC_APP_ASSETS, PUBLIC_APP_NAME } from "$env/static/public";
|
| 17 |
import titleUpdate from "$lib/stores/titleUpdate";
|
| 18 |
import { createSettingsStore } from "$lib/stores/settings";
|
| 19 |
+
import { browser } from "$app/environment";
|
| 20 |
|
| 21 |
export let data;
|
| 22 |
|
|
|
|
| 105 |
$titleUpdate = null;
|
| 106 |
}
|
| 107 |
|
| 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 |
+
}
|
| 116 |
</script>
|
| 117 |
|
| 118 |
<svelte:head>
|
src/routes/+page.svelte
CHANGED
|
@@ -5,12 +5,15 @@
|
|
| 5 |
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
|
| 6 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
| 7 |
import { pendingMessage } from "$lib/stores/pendingMessage";
|
|
|
|
| 8 |
import { findCurrentModel } from "$lib/utils/models";
|
| 9 |
|
| 10 |
export let data;
|
| 11 |
let loading = false;
|
| 12 |
let files: File[] = [];
|
| 13 |
|
|
|
|
|
|
|
| 14 |
async function createConversation(message: string) {
|
| 15 |
try {
|
| 16 |
loading = true;
|
|
@@ -20,8 +23,8 @@
|
|
| 20 |
"Content-Type": "application/json",
|
| 21 |
},
|
| 22 |
body: JSON.stringify({
|
| 23 |
-
model:
|
| 24 |
-
preprompt:
|
| 25 |
}),
|
| 26 |
});
|
| 27 |
|
|
@@ -57,7 +60,7 @@
|
|
| 57 |
<ChatWindow
|
| 58 |
on:message={(ev) => createConversation(ev.detail)}
|
| 59 |
{loading}
|
| 60 |
-
currentModel={findCurrentModel([...data.models, ...data.oldModels],
|
| 61 |
models={data.models}
|
| 62 |
bind:files
|
| 63 |
/>
|
|
|
|
| 5 |
import ChatWindow from "$lib/components/chat/ChatWindow.svelte";
|
| 6 |
import { ERROR_MESSAGES, error } from "$lib/stores/errors";
|
| 7 |
import { pendingMessage } from "$lib/stores/pendingMessage";
|
| 8 |
+
import { useSettingsStore } from "$lib/stores/settings.js";
|
| 9 |
import { findCurrentModel } from "$lib/utils/models";
|
| 10 |
|
| 11 |
export let data;
|
| 12 |
let loading = false;
|
| 13 |
let files: File[] = [];
|
| 14 |
|
| 15 |
+
const settings = useSettingsStore();
|
| 16 |
+
|
| 17 |
async function createConversation(message: string) {
|
| 18 |
try {
|
| 19 |
loading = true;
|
|
|
|
| 23 |
"Content-Type": "application/json",
|
| 24 |
},
|
| 25 |
body: JSON.stringify({
|
| 26 |
+
model: $settings.activeModel,
|
| 27 |
+
preprompt: $settings.customPrompts[data.settings.activeModel],
|
| 28 |
}),
|
| 29 |
});
|
| 30 |
|
|
|
|
| 60 |
<ChatWindow
|
| 61 |
on:message={(ev) => createConversation(ev.detail)}
|
| 62 |
{loading}
|
| 63 |
+
currentModel={findCurrentModel([...data.models, ...data.oldModels], $settings.activeModel)}
|
| 64 |
models={data.models}
|
| 65 |
bind:files
|
| 66 |
/>
|