Spaces:
Running
Running
![coyotte508's picture](https://cdn-avatars.huggingface.co/v1/production/uploads/61d2f90c3c2083e1c08af22d/jn21aKijwBnopk7aUJUkq.png)
coyotte508
HF staff
✨ Add model id to be able to switch models while keeping conversations valid (#181)
cf7ac8d
unverified
import { base } from "$app/paths"; | |
import { collections } from "$lib/server/database"; | |
import { redirect } from "@sveltejs/kit"; | |
import { z } from "zod"; | |
import { defaultModel, models } from "$lib/server/models"; | |
import { validateModel } from "$lib/utils/models.js"; | |
export const actions = { | |
default: async function ({ request, locals }) { | |
const formData = await request.formData(); | |
const { ethicsModalAccepted, ...settings } = z | |
.object({ | |
shareConversationsWithModelAuthors: z.boolean({ coerce: true }).default(true), | |
ethicsModalAccepted: z.boolean({ coerce: true }).optional(), | |
activeModel: validateModel(models), | |
}) | |
.parse({ | |
shareConversationsWithModelAuthors: formData.get("shareConversationsWithModelAuthors"), | |
ethicsModalAccepted: formData.get("ethicsModalAccepted"), | |
activeModel: formData.get("activeModel") ?? defaultModel.id, | |
}); | |
await collections.settings.updateOne( | |
{ | |
sessionId: locals.sessionId, | |
}, | |
{ | |
$set: { | |
...settings, | |
...(ethicsModalAccepted && { ethicsModalAcceptedAt: new Date() }), | |
updatedAt: new Date(), | |
}, | |
$setOnInsert: { | |
createdAt: new Date(), | |
}, | |
}, | |
{ | |
upsert: true, | |
} | |
); | |
throw redirect(303, request.headers.get("referer") || base || "/"); | |
}, | |
}; | |