Skip to content

Commit e76995d

Browse files
committed
persistant custom instruction
1 parent 2ef069b commit e76995d

File tree

6 files changed

+48
-0
lines changed

6 files changed

+48
-0
lines changed

src/lib/stores/settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type SettingsStore = {
1515
customPrompts: Record<string, string>;
1616
recentlySaved: boolean;
1717
assistants: Array<ObjectId | string>;
18+
customInstruction: string;
1819
};
1920

2021
export function useSettingsStore() {

src/lib/types/Settings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export interface Settings extends Timestamps {
2121
customPrompts?: Record<string, string>;
2222

2323
assistants?: Assistant["_id"][];
24+
25+
customInstruction?: string;
2426
}
2527

2628
// TODO: move this to a constant file along with other constants
@@ -30,4 +32,5 @@ export const DEFAULT_SETTINGS = {
3032
hideEmojiOnSidebar: false,
3133
customPrompts: {},
3234
assistants: [],
35+
customInstruction: "",
3336
};

src/routes/+layout.server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
139139
DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
140140
customPrompts: settings?.customPrompts ?? {},
141141
assistants: settings?.assistants?.map((el) => el.toString()) ?? [],
142+
customInstruction: settings?.customInstruction ?? "",
142143
},
143144
models: models.map((model) => ({
144145
id: model.id,

src/routes/settings/+server.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export async function POST({ request, locals }) {
1515
ethicsModalAccepted: z.boolean().optional(),
1616
activeModel: z.string().default(DEFAULT_SETTINGS.activeModel),
1717
customPrompts: z.record(z.string()).default({}),
18+
customInstruction: z.string().default(""),
1819
})
1920
.parse(body);
2021

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script lang="ts">
2+
import { useSettingsStore } from "$lib/stores/settings";
3+
4+
const settings = useSettingsStore();
5+
6+
$: if ($settings.customInstruction === undefined) {
7+
$settings.customInstruction = "";
8+
}
9+
10+
$: hasCustomInstruction =
11+
$settings.customInstruction !== "";
12+
</script>
13+
14+
<div class="flex flex-col items-start">
15+
<div class="flex w-full flex-col gap-2">
16+
<div class="flex w-full flex-row content-between">
17+
<h3 class="mb-1.5 text-lg font-semibold text-gray-800">Custom Instructions</h3>
18+
{#if hasCustomInstruction}
19+
<button
20+
class="ml-auto underline decoration-gray-300 hover:decoration-gray-700"
21+
on:click|stopPropagation={() =>
22+
($settings.customInstruction = "")}
23+
>
24+
Reset
25+
</button>
26+
{/if}
27+
</div>
28+
<textarea
29+
rows="10"
30+
class="w-full resize-none rounded-md border-2 bg-gray-100 p-2"
31+
bind:value={$settings.customInstruction}
32+
/>
33+
</div>
34+
</div>

src/routes/settings/custom/+page.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { base } from "$app/paths";
2+
import { redirect } from "@sveltejs/kit";
3+
4+
export async function load({ parent, params }) {
5+
const data = await parent();
6+
7+
return data;
8+
}

0 commit comments

Comments
 (0)