Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/custom instruction #903

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/lib/stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type SettingsStore = {
customPrompts: Record<string, string>;
recentlySaved: boolean;
assistants: Array<ObjectId | string>;
customInstruction: string;
};

type SettingsStoreWritable = Writable<SettingsStore> & {
Expand Down
3 changes: 3 additions & 0 deletions src/lib/types/Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export interface Settings extends Timestamps {
customPrompts?: Record<string, string>;

assistants?: Assistant["_id"][];

customInstruction?: string;
}

// TODO: move this to a constant file along with other constants
Expand All @@ -30,4 +32,5 @@ export const DEFAULT_SETTINGS = {
hideEmojiOnSidebar: false,
customPrompts: {},
assistants: [],
customInstruction: "",
};
1 change: 1 addition & 0 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
customPrompts: settings?.customPrompts ?? {},
assistants: userAssistants,
customInstruction: settings?.customInstruction ?? "",
},
models: models.map((model) => ({
id: model.id,
Expand Down
5 changes: 4 additions & 1 deletion src/routes/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,17 @@
model = data.models[0].id;
}
}
let customPreprompt = $settings.customPrompts[$settings.activeModel]
? $settings.customInstruction + "\n" + $settings.customPrompts[$settings.activeModel]
: undefined;
const res = await fetch(`${base}/conversation`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
model,
preprompt: $settings.customPrompts[$settings.activeModel],
preprompt: customPreprompt,
assistantId: data.assistant?._id,
}),
});
Expand Down
9 changes: 9 additions & 0 deletions src/routes/settings/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import CarbonCheckmark from "~icons/carbon/checkmark";
import CarbonAdd from "~icons/carbon/add";

import LicenseIcon from "~icons/carbon/license";
import UserIcon from "~icons/carbon/user";
import { fade, fly } from "svelte/transition";
export let data;
Expand Down Expand Up @@ -76,6 +77,14 @@
{/if}
</a>
{/each}
<a
href="{base}/settings/custom"
class="group flex h-10 flex-none items-center gap-2 pl-3 pr-2 text-sm text-gray-500 hover:bg-gray-100 md:rounded-xl
{$page.url.pathname === `${base}/settings/custom` ? '!bg-gray-100 !text-gray-800' : ''}"
>
<LicenseIcon />
<div class="truncate">Custom Instructions</div>
</a>
<!-- if its huggingchat, the number of assistants owned by the user must be non-zero to show the UI -->
{#if data.enableAssistants}
<h3 bind:this={assistantsSection} class="pb-3 pl-3 pt-5 text-[.8rem] text-gray-800 sm:pl-1">
Expand Down
1 change: 1 addition & 0 deletions src/routes/settings/+server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export async function POST({ request, locals }) {
ethicsModalAccepted: z.boolean().optional(),
activeModel: z.string().default(DEFAULT_SETTINGS.activeModel),
customPrompts: z.record(z.string()).default({}),
customInstruction: z.string().default(""),
})
.parse(body);

Expand Down
32 changes: 32 additions & 0 deletions src/routes/settings/custom/+page.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script lang="ts">
import { useSettingsStore } from "$lib/stores/settings";

const settings = useSettingsStore();

$: if ($settings.customInstruction === undefined) {
$settings.customInstruction = "";
}

$: hasCustomInstruction = $settings.customInstruction !== "";
</script>

<div class="flex flex-col items-start">
<div class="flex w-full flex-col gap-2">
<div class="flex w-full flex-row content-between">
<h3 class="mb-1.5 text-lg font-semibold text-gray-800">Custom Instructions</h3>
{#if hasCustomInstruction}
<button
class="ml-auto underline decoration-gray-300 hover:decoration-gray-700"
on:click|stopPropagation={() => ($settings.customInstruction = "")}
>
Reset
</button>
{/if}
</div>
<textarea
rows="10"
class="w-full resize-none rounded-md border-2 bg-gray-100 p-2"
bind:value={$settings.customInstruction}
/>
</div>
</div>
5 changes: 5 additions & 0 deletions src/routes/settings/custom/+page.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function load({ parent }) {
const data = await parent();

return data;
}
Loading