Skip to content
Merged
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
5 changes: 4 additions & 1 deletion src/lib/components/Modal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@

onDestroy(() => {
if (!browser) return;
document.getElementById("app")?.removeAttribute("inert");
// remove inert attribute if this is the last modal
if (document.querySelectorAll('[role="dialog"]:not(#app *)').length === 1) {
document.getElementById("app")?.removeAttribute("inert");
}
});
</script>

Expand Down
120 changes: 80 additions & 40 deletions src/lib/components/SettingsModal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -11,57 +11,97 @@
export let settings: Pick<Settings, "shareConversationsWithModelAuthors">;

let shareConversationsWithModelAuthors = settings.shareConversationsWithModelAuthors;
let isConfirmingDeletion = false;

const dispatch = createEventDispatcher<{ close: void }>();
</script>

<Modal on:close>
<form
class="flex w-full flex-col gap-5 p-6"
use:enhance={() => {
dispatch("close");
}}
method="post"
action="{base}/settings"
>
<div class="flex w-full flex-col gap-5 p-6">
<div class="flex items-start justify-between text-xl font-semibold text-gray-800">
<h2>Settings</h2>
<button type="button" class="group" on:click={() => dispatch("close")}>
<CarbonClose class="text-gray-900 group-hover:text-gray-500" />
</button>
</div>
<form
class="flex flex-col gap-5"
use:enhance={() => {
dispatch("close");
}}
method="post"
action="{base}/settings"
>
<label class="flex cursor-pointer select-none items-center gap-2 text-gray-500">
{#each Object.entries(settings).filter(([k]) => k !== "shareConversationsWithModelAuthors") as [key, val]}
<input type="hidden" name={key} value={val} />
{/each}
<Switch
name="shareConversationsWithModelAuthors"
bind:checked={shareConversationsWithModelAuthors}
/>
Share conversations with model authors
</label>

<label class="flex cursor-pointer select-none items-center gap-2 text-gray-500">
{#each Object.entries(settings).filter(([k]) => k !== "shareConversationsWithModelAuthors") as [key, val]}
<input type="hidden" name={key} value={val} />
{/each}
<Switch
name="shareConversationsWithModelAuthors"
bind:checked={shareConversationsWithModelAuthors}
/>
Share conversations with model authors
</label>
<p class="text-gray-800">
Sharing your data will help improve the training data and make open models better over time.
</p>
<p class="text-gray-800">
You can change this setting at any time, it applies to all your conversations.
</p>
<p class="text-gray-800">
Read more about this model's authors,
<a
href="https://open-assistant.io/"
target="_blank"
rel="noreferrer"
class="underline decoration-gray-300 hover:decoration-gray-700">Open Assistant</a
>.
</p>
<form
method="post"
action="{base}/conversations?/delete"
on:submit|preventDefault={() => (isConfirmingDeletion = true)}
>
<button type="submit" class="underline decoration-gray-300 hover:decoration-gray-700">
Delete all conversations
</button>
</form>
<button
type="submit"
class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all focus-visible:outline-none focus-visible:ring hover:ring"
>
Apply
</button>
</form>

<p class="text-gray-800">
Sharing your data will help improve the training data and make open models better over time.
</p>
<p class="text-gray-800">
You can change this setting at any time, it applies to all your conversations.
</p>
<p class="text-gray-800">
Read more about this model's authors,
<a
href="https://open-assistant.io/"
target="_blank"
rel="noreferrer"
class="underline decoration-gray-300 hover:decoration-gray-700">Open Assistant</a
>.
</p>
<button
type="submit"
class="mt-2 rounded-full bg-black px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all focus-visible:outline-none focus-visible:ring hover:ring"
>
Apply
</button>
</form>
{#if isConfirmingDeletion}
<Modal on:close={() => (isConfirmingDeletion = false)}>
<form
use:enhance={() => {
dispatch("close");
}}
method="post"
action="{base}/conversations?/delete"
class="flex w-full flex-col gap-5 p-6"
>
<div class="flex items-start justify-between text-xl font-semibold text-gray-800">
<h2>Are you sure?</h2>
<button type="button" class="group" on:click={() => (isConfirmingDeletion = false)}>
<CarbonClose class="text-gray-900 group-hover:text-gray-500" />
</button>
</div>
<p class="text-gray-800">
This action will delete all your conversations. This cannot be undone.
</p>
<button
type="submit"
class="mt-2 rounded-full bg-red-700 px-5 py-2 text-lg font-semibold text-gray-100 ring-gray-400 ring-offset-1 transition-all focus-visible:outline-none focus-visible:ring hover:ring"
>
Confirm deletion
</button>
</form>
</Modal>
{/if}
</div>
</Modal>
17 changes: 17 additions & 0 deletions src/routes/conversations/+page.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { base } from "$app/paths";
import { authCondition } from "$lib/server/auth";
import { collections } from "$lib/server/database";
import { redirect } from "@sveltejs/kit";

export const actions = {
delete: async function ({ locals }) {
// double check we have a user to delete conversations for
if (locals.user?._id || locals.sessionId) {
await collections.conversations.deleteMany({
...authCondition(locals),
});
}

throw redirect(303, `${base}/`);
},
};