Skip to content

Commit 41f29a4

Browse files
authored
Add feature to unlist a model (#625)
1 parent a32541c commit 41f29a4

File tree

6 files changed

+31
-3
lines changed

6 files changed

+31
-3
lines changed

src/lib/server/models.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ const modelConfig = z.object({
6565
.passthrough()
6666
.optional(),
6767
multimodal: z.boolean().default(false),
68+
unlisted: z.boolean().default(false),
6869
});
6970

7071
const modelsRaw = z.array(modelConfig).parse(JSON.parse(MODELS));
@@ -156,4 +157,7 @@ export const smallModel = TASK_MODEL
156157
defaultModel
157158
: defaultModel;
158159

159-
export type BackendModel = Optional<typeof defaultModel, "preprompt" | "parameters" | "multimodal">;
160+
export type BackendModel = Optional<
161+
typeof defaultModel,
162+
"preprompt" | "parameters" | "multimodal" | "unlisted"
163+
>;

src/lib/types/Model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ export type Model = Pick<
1414
| "datasetUrl"
1515
| "preprompt"
1616
| "multimodal"
17+
| "unlisted"
1718
>;

src/routes/+layout.server.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,17 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
2727
});
2828
}
2929

30+
// if the model is unlisted, set the active model to the default model
31+
if (
32+
settings?.activeModel &&
33+
models.find((m) => m.id === settings?.activeModel)?.unlisted === true
34+
) {
35+
settings.activeModel = defaultModel.id;
36+
await collections.settings.updateOne(authCondition(locals), {
37+
$set: { activeModel: defaultModel.id },
38+
});
39+
}
40+
3041
// get the number of messages where `from === "assistant"` across all conversations.
3142
const totalMessages =
3243
(
@@ -89,6 +100,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
89100
parameters: model.parameters,
90101
preprompt: model.preprompt,
91102
multimodal: model.multimodal,
103+
unlisted: model.unlisted,
92104
})),
93105
oldModels,
94106
user: locals.user && {

src/routes/conversation/+server.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ export const POST: RequestHandler = async ({ locals, request }) => {
3939
}
4040

4141
const model = models.find((m) => m.name === values.model);
42+
43+
if (!model) {
44+
throw error(400, "Invalid model");
45+
}
46+
47+
if (model.unlisted) {
48+
throw error(400, "Can't start a conversation with an unlisted model");
49+
}
50+
4251
// Use the model preprompt if there is no conversation/preprompt in the request body
4352
preprompt = preprompt === undefined ? model?.preprompt : preprompt;
4453

src/routes/settings/+layout.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
<div
4949
class="col-span-1 flex flex-col overflow-y-auto whitespace-nowrap max-md:-mx-4 max-md:h-[160px] max-md:border md:pr-6"
5050
>
51-
{#each data.models as model}
51+
{#each data.models.filter((el) => !el.unlisted) as model}
5252
<a
5353
href="{base}/settings/{model.id}"
5454
class="group flex h-11 flex-none items-center gap-3 pl-3 pr-2 text-gray-500 hover:bg-gray-100 md:rounded-xl {model.id ===

src/routes/settings/[...model]/+page.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { redirect } from "@sveltejs/kit";
44
export async function load({ parent, params }) {
55
const data = await parent();
66

7-
if (!data.models.map(({ id }) => id).includes(params.model)) {
7+
const model = data.models.find(({ id }) => id === params.model);
8+
9+
if (!model || model.unlisted) {
810
throw redirect(302, `${base}/settings`);
911
}
1012

0 commit comments

Comments
 (0)