nsarrazin HF staff commited on
Commit
7d34920
1 Parent(s): 96d25a6

Move featured assistant check behind `REQUIRE_FEATURED_ASSISTANTS` (#1043)

Browse files

Move featured assistant check behind `REQUIRE_FEATURED_ASSISTANTS` env var (#997)

.env CHANGED
@@ -145,6 +145,7 @@ EXPOSE_API=true
145
 
146
  ENABLE_ASSISTANTS=false #set to true to enable assistants feature
147
  ENABLE_ASSISTANTS_RAG=false # /!\ This will let users specify arbitrary URLs that the server will then request. Make sure you have the proper firewall rules in place.
 
148
  ENABLE_LOCAL_FETCH=false #set to true to disable the blocklist for local fetches. Only enable this if you have the proper firewall rules to prevent SSRF attacks and understand the implications.
149
  ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
150
  WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assistant gets reported
 
145
 
146
  ENABLE_ASSISTANTS=false #set to true to enable assistants feature
147
  ENABLE_ASSISTANTS_RAG=false # /!\ This will let users specify arbitrary URLs that the server will then request. Make sure you have the proper firewall rules in place.
148
+ REQUIRE_FEATURED_ASSISTANTS=false
149
  ENABLE_LOCAL_FETCH=false #set to true to disable the blocklist for local fetches. Only enable this if you have the proper firewall rules to prevent SSRF attacks and understand the implications.
150
  ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
151
  WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assistant gets reported
.env.template CHANGED
@@ -283,6 +283,7 @@ PUBLIC_APPLE_APP_ID=6476778843
283
 
284
  ENABLE_ASSISTANTS=true
285
  ENABLE_ASSISTANTS_RAG=true
 
286
  EXPOSE_API=true
287
 
288
  ALTERNATIVE_REDIRECT_URLS=`[
 
283
 
284
  ENABLE_ASSISTANTS=true
285
  ENABLE_ASSISTANTS_RAG=true
286
+ REQUIRE_FEATURED_ASSISTANTS=true
287
  EXPOSE_API=true
288
 
289
  ALTERNATIVE_REDIRECT_URLS=`[
src/routes/api/assistants/+server.ts CHANGED
@@ -3,6 +3,7 @@ import type { Assistant } from "$lib/types/Assistant";
3
  import type { User } from "$lib/types/User";
4
  import { generateQueryTokens } from "$lib/utils/searchTokens.js";
5
  import type { Filter } from "mongodb";
 
6
 
7
  const NUM_PER_PAGE = 24;
8
 
@@ -24,12 +25,16 @@ export async function GET({ url, locals }) {
24
  }
25
  }
26
 
 
 
27
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
28
  const filter: Filter<Assistant> = {
29
  ...(modelId && { modelId }),
30
- ...(!createdByCurrentUser && { userCount: { $gt: 1 } }),
31
- ...(user ? { createdById: user._id } : { featured: true }),
 
32
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
 
33
  };
34
  const assistants = await collections.assistants
35
  .find(filter)
 
3
  import type { User } from "$lib/types/User";
4
  import { generateQueryTokens } from "$lib/utils/searchTokens.js";
5
  import type { Filter } from "mongodb";
6
+ import { REQUIRE_FEATURED_ASSISTANTS } from "$env/static/private";
7
 
8
  const NUM_PER_PAGE = 24;
9
 
 
25
  }
26
  }
27
 
28
+ const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
29
+
30
  // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
31
  const filter: Filter<Assistant> = {
32
  ...(modelId && { modelId }),
33
+ ...(!createdByCurrentUser &&
34
+ REQUIRE_FEATURED_ASSISTANTS === "true" && { userCount: { $gt: 1 } }),
35
+ ...(user && { createdById: user._id }),
36
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
37
+ ...shouldBeFeatured,
38
  };
39
  const assistants = await collections.assistants
40
  .find(filter)
src/routes/assistants/+page.server.ts CHANGED
@@ -1,5 +1,5 @@
1
  import { base } from "$app/paths";
2
- import { ENABLE_ASSISTANTS } from "$env/static/private";
3
  import { collections } from "$lib/server/database.js";
4
  import { SortKey, type Assistant } from "$lib/types/Assistant";
5
  import type { User } from "$lib/types/User";
@@ -21,6 +21,8 @@ export const load = async ({ url, locals }) => {
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.POPULAR;
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23
 
 
 
24
  let user: Pick<User, "_id"> | null = null;
25
  if (username) {
26
  user = await collections.users.findOne<Pick<User, "_id">>(
@@ -32,12 +34,14 @@ export const load = async ({ url, locals }) => {
32
  }
33
  }
34
 
35
- // fetch the top assistants sorted by user count from biggest to smallest, filter out all assistants with only 1 users. filter by model too if modelId is provided
36
  const filter: Filter<Assistant> = {
37
  ...(modelId && { modelId }),
38
- ...(!createdByCurrentUser && { userCount: { $gt: 1 } }),
39
- ...(user ? { createdById: user._id } : { featured: true }),
 
40
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
 
41
  };
42
  const assistants = await collections.assistants
43
  .find(filter)
 
1
  import { base } from "$app/paths";
2
+ import { ENABLE_ASSISTANTS, REQUIRE_FEATURED_ASSISTANTS } from "$env/static/private";
3
  import { collections } from "$lib/server/database.js";
4
  import { SortKey, type Assistant } from "$lib/types/Assistant";
5
  import type { User } from "$lib/types/User";
 
21
  const sort = url.searchParams.get("sort")?.trim() ?? SortKey.POPULAR;
22
  const createdByCurrentUser = locals.user?.username && locals.user.username === username;
23
 
24
+ const shouldBeFeatured = REQUIRE_FEATURED_ASSISTANTS === "true" ? { featured: true } : {};
25
+
26
  let user: Pick<User, "_id"> | null = null;
27
  if (username) {
28
  user = await collections.users.findOne<Pick<User, "_id">>(
 
34
  }
35
  }
36
 
37
+ // fetch the top assistants sorted by user count from biggest to smallest. filter by model too if modelId is provided or query if query is provided
38
  const filter: Filter<Assistant> = {
39
  ...(modelId && { modelId }),
40
+ ...(!createdByCurrentUser &&
41
+ REQUIRE_FEATURED_ASSISTANTS === "true" && { userCount: { $gt: 1 } }),
42
+ ...(user && { createdById: user._id }),
43
  ...(query && { searchTokens: { $all: generateQueryTokens(query) } }),
44
+ ...shouldBeFeatured,
45
  };
46
  const assistants = await collections.assistants
47
  .find(filter)