-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat(settings)/conv_deletion_refactor
- Loading branch information
Showing
10 changed files
with
177 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<script lang="ts"> | ||
import { goto } from "$app/navigation"; | ||
import { base } from "$app/paths"; | ||
import { page } from "$app/state"; | ||
import IconDazzled from "./icons/IconDazzled.svelte"; | ||
import Modal from "./Modal.svelte"; | ||
let { onClose }: { onClose: () => void } = $props(); | ||
</script> | ||
|
||
<Modal on:close={onClose}> | ||
<div | ||
class="from-primary-500/40 via-primary-500/10 to-primary-500/0 flex w-full flex-col items-center gap-3 bg-gradient-to-b px-5 pb-4 pt-9 text-center sm:px-6" | ||
> | ||
<div class="flex flex-wrap items-center gap-2"> | ||
<IconDazzled classNames="text-3xl mx-auto" /> | ||
<h2 class="flex flex-wrap items-center text-lg font-semibold text-gray-800"> | ||
This model is currently overloaded. | ||
</h2> | ||
</div> | ||
|
||
<p class="text-sm text-gray-500"> | ||
Please try again later or consider using a different model. We currently have {page.data | ||
.models.length} models available. | ||
</p> | ||
|
||
<div class="flex w-full flex-col items-center gap-4 pt-4"> | ||
<button | ||
onclick={() => (onClose(), goto(`${base}/models`))} | ||
class="flex w-full flex-wrap items-center justify-center whitespace-nowrap rounded-full border-2 border-black bg-black px-5 py-2 text-lg font-semibold text-gray-100 transition-colors hover:bg-gray-900" | ||
> | ||
See all available models | ||
</button> | ||
<button | ||
onclick={onClose} | ||
class="flex w-fit flex-wrap items-center justify-center whitespace-nowrap px-2 py-1 text-gray-600 transition-colors hover:text-gray-900" | ||
> | ||
Close | ||
</button> | ||
</div> | ||
</div> | ||
</Modal> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
src/routes/api/conversation/[id]/message/[messageId]/+server.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { authCondition } from "$lib/server/auth"; | ||
import { collections } from "$lib/server/database"; | ||
import { error } from "@sveltejs/kit"; | ||
import { ObjectId } from "mongodb"; | ||
|
||
export async function DELETE({ locals, params }) { | ||
const messageId = params.messageId; | ||
|
||
if (!messageId || typeof messageId !== "string") { | ||
error(400, "Invalid message id"); | ||
} | ||
|
||
const conversation = await collections.conversations.findOne({ | ||
...authCondition(locals), | ||
_id: new ObjectId(params.id), | ||
}); | ||
|
||
if (!conversation) { | ||
error(404, "Conversation not found"); | ||
} | ||
|
||
const filteredMessages = conversation.messages | ||
.filter( | ||
(message) => | ||
// not the message AND the message is not in ancestors | ||
!(message.id === messageId) && message.ancestors && !message.ancestors.includes(messageId) | ||
) | ||
.map((message) => { | ||
// remove the message from children if it's there | ||
if (message.children && message.children.includes(messageId)) { | ||
message.children = message.children.filter((child) => child !== messageId); | ||
} | ||
return message; | ||
}); | ||
|
||
await collections.conversations.updateOne( | ||
{ _id: conversation._id, ...authCondition(locals) }, | ||
{ $set: { messages: filteredMessages } } | ||
); | ||
|
||
return new Response(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.