nsarrazin HF staff commited on
Commit
41f29a4
1 Parent(s): a32541c

Add feature to unlist a model (#625)

Browse files
src/lib/server/models.ts CHANGED
@@ -65,6 +65,7 @@ const modelConfig = z.object({
65
  .passthrough()
66
  .optional(),
67
  multimodal: z.boolean().default(false),
 
68
  });
69
 
70
  const modelsRaw = z.array(modelConfig).parse(JSON.parse(MODELS));
@@ -156,4 +157,7 @@ export const smallModel = TASK_MODEL
156
  defaultModel
157
  : defaultModel;
158
 
159
- export type BackendModel = Optional<typeof defaultModel, "preprompt" | "parameters" | "multimodal">;
 
 
 
 
65
  .passthrough()
66
  .optional(),
67
  multimodal: z.boolean().default(false),
68
+ unlisted: z.boolean().default(false),
69
  });
70
 
71
  const modelsRaw = z.array(modelConfig).parse(JSON.parse(MODELS));
 
157
  defaultModel
158
  : defaultModel;
159
 
160
+ export type BackendModel = Optional<
161
+ typeof defaultModel,
162
+ "preprompt" | "parameters" | "multimodal" | "unlisted"
163
+ >;
src/lib/types/Model.ts CHANGED
@@ -14,4 +14,5 @@ export type Model = Pick<
14
  | "datasetUrl"
15
  | "preprompt"
16
  | "multimodal"
 
17
  >;
 
14
  | "datasetUrl"
15
  | "preprompt"
16
  | "multimodal"
17
+ | "unlisted"
18
  >;
src/routes/+layout.server.ts CHANGED
@@ -27,6 +27,17 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
27
  });
28
  }
29
 
 
 
 
 
 
 
 
 
 
 
 
30
  // get the number of messages where `from === "assistant"` across all conversations.
31
  const totalMessages =
32
  (
@@ -89,6 +100,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
89
  parameters: model.parameters,
90
  preprompt: model.preprompt,
91
  multimodal: model.multimodal,
 
92
  })),
93
  oldModels,
94
  user: locals.user && {
 
27
  });
28
  }
29
 
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
+
41
  // get the number of messages where `from === "assistant"` across all conversations.
42
  const totalMessages =
43
  (
 
100
  parameters: model.parameters,
101
  preprompt: model.preprompt,
102
  multimodal: model.multimodal,
103
+ unlisted: model.unlisted,
104
  })),
105
  oldModels,
106
  user: locals.user && {
src/routes/conversation/+server.ts CHANGED
@@ -39,6 +39,15 @@ export const POST: RequestHandler = async ({ locals, request }) => {
39
  }
40
 
41
  const model = models.find((m) => m.name === values.model);
 
 
 
 
 
 
 
 
 
42
  // Use the model preprompt if there is no conversation/preprompt in the request body
43
  preprompt = preprompt === undefined ? model?.preprompt : preprompt;
44
 
 
39
  }
40
 
41
  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
+
51
  // Use the model preprompt if there is no conversation/preprompt in the request body
52
  preprompt = preprompt === undefined ? model?.preprompt : preprompt;
53
 
src/routes/settings/+layout.svelte CHANGED
@@ -48,7 +48,7 @@
48
  <div
49
  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"
50
  >
51
- {#each data.models as model}
52
  <a
53
  href="{base}/settings/{model.id}"
54
  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 ===
 
48
  <div
49
  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"
50
  >
51
+ {#each data.models.filter((el) => !el.unlisted) as model}
52
  <a
53
  href="{base}/settings/{model.id}"
54
  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 CHANGED
@@ -4,7 +4,9 @@ import { redirect } from "@sveltejs/kit";
4
  export async function load({ parent, params }) {
5
  const data = await parent();
6
 
7
- if (!data.models.map(({ id }) => id).includes(params.model)) {
 
 
8
  throw redirect(302, `${base}/settings`);
9
  }
10
 
 
4
  export async function load({ parent, params }) {
5
  const data = await parent();
6
 
7
+ const model = data.models.find(({ id }) => id === params.model);
8
+
9
+ if (!model || model.unlisted) {
10
  throw redirect(302, `${base}/settings`);
11
  }
12