Skip to content

Commit 1bc8316

Browse files
authored
Merge branch 'main' into front/setting_page_theme
2 parents 9737ef1 + 69684cd commit 1bc8316

File tree

17 files changed

+184
-38
lines changed

17 files changed

+184
-38
lines changed

.env

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,4 +133,6 @@ EXPOSE_API=true
133133

134134
ENABLE_ASSISTANTS=false #set to true to enable assistants feature
135135

136-
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
136+
ALTERNATIVE_REDIRECT_URLS=`[]` #valide alternative redirect URL for OAuth
137+
138+
WEBHOOK_URL_REPORT_ASSISTANT=#provide webhook url to get notified when an assistant gets reported

.github/workflows/deploy-release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ jobs:
2525
OPENID_CONFIG: ${{ secrets.OPENID_CONFIG }}
2626
MONGODB_URL: ${{ secrets.MONGODB_URL }}
2727
HF_DEPLOYMENT_TOKEN: ${{ secrets.HF_DEPLOYMENT_TOKEN }}
28+
WEBHOOK_URL_REPORT_ASSISTANT: ${{ secrets.WEBHOOK_URL_REPORT_ASSISTANT }}
2829
run: npm run updateProdEnv
2930
sync-to-hub:
3031
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ The following is the default `chatPromptTemplate`, although newlines and indenti
226226

227227
#### Multi modal model
228228

229-
We currently only support IDEFICS as a multimodal model, hosted on TGI. You can enable it by using the followin config (if you have a PRO HF Api token):
229+
We currently only support IDEFICS as a multimodal model, hosted on TGI. You can enable it by using the following config (if you have a PRO HF Api token):
230230

231231
```env
232232
{

scripts/updateProdEnv.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const SERPER_API_KEY = process.env.SERPER_API_KEY;
66
const OPENID_CONFIG = process.env.OPENID_CONFIG;
77
const MONGODB_URL = process.env.MONGODB_URL;
88
const HF_TOKEN = process.env.HF_TOKEN ?? process.env.HF_ACCESS_TOKEN; // token used for API requests in prod
9+
const WEBHOOK_URL_REPORT_ASSISTANT = process.env.WEBHOOK_URL_REPORT_ASSISTANT; // slack webhook url used to get "report assistant" events
910

1011
// Read the content of the file .env.template
1112
const PUBLIC_CONFIG = fs.readFileSync(".env.template", "utf8");
@@ -16,6 +17,7 @@ MONGODB_URL=${MONGODB_URL}
1617
OPENID_CONFIG=${OPENID_CONFIG}
1718
SERPER_API_KEY=${SERPER_API_KEY}
1819
HF_TOKEN=${HF_TOKEN}
20+
WEBHOOK_URL_REPORT_ASSISTANT=${WEBHOOK_URL_REPORT_ASSISTANT}
1921
`;
2022

2123
// Make an HTTP POST request to add the space secrets

src/lib/components/Pagination.svelte

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts">
22
import { page } from "$app/stores";
3+
import { getHref } from "$lib/utils/getHref";
34
import PaginationArrow from "./PaginationArrow.svelte";
45
56
export let classNames = "";
@@ -12,12 +13,6 @@
1213
$: pageIndex = parseInt($page.url.searchParams.get("p") ?? "0");
1314
$: pageIndexes = getPageIndexes(pageIndex, numTotalPages);
1415
15-
function getHref(url: URL | string, pageIdx: number) {
16-
const newUrl = new URL(url);
17-
newUrl.searchParams.set("p", pageIdx.toString());
18-
return newUrl.toString();
19-
}
20-
2116
function getPageIndexes(pageIdx: number, nTotalPages: number) {
2217
let pageIdxs: number[] = [];
2318
@@ -66,7 +61,7 @@
6661
>
6762
<li>
6863
<PaginationArrow
69-
href={getHref($page.url, pageIndex - 1)}
64+
href={getHref($page.url, { newKeys: { p: (pageIndex - 1).toString() } })}
7065
direction="previous"
7166
isDisabled={pageIndex - 1 < 0}
7267
/>
@@ -81,15 +76,15 @@
8176
: ''}
8277
"
8378
class:pointer-events-none={pageIdx === ELLIPSIS_IDX || pageIndex === pageIdx}
84-
href={getHref($page.url, pageIdx)}
79+
href={getHref($page.url, { newKeys: { p: pageIdx.toString() } })}
8580
>
8681
{pageIdx === ELLIPSIS_IDX ? "..." : pageIdx + 1}
8782
</a>
8883
</li>
8984
{/each}
9085
<li>
9186
<PaginationArrow
92-
href={getHref($page.url, pageIndex + 1)}
87+
href={getHref($page.url, { newKeys: { p: (pageIndex + 1).toString() } })}
9388
direction="next"
9489
isDisabled={pageIndex + 1 >= numTotalPages}
9590
/>

src/lib/components/SystemPromptModal.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
type="button"
1313
class="mx-auto flex items-center gap-1.5 rounded-full border border-gray-100 bg-gray-50 px-3 py-1 text-xs text-gray-500 hover:bg-gray-100 dark:border-gray-800 dark:bg-gray-800 dark:text-gray-400 dark:hover:bg-gray-700"
1414
on:click={() => (isOpen = !isOpen)}
15-
on:keypress={(e) => e.key === "Enter" && (isOpen = !isOpen)}
15+
on:keydown={(e) => e.key === "Enter" && (isOpen = !isOpen)}
1616
>
1717
<CarbonBlockchain class="text-xxs" /> Using Custom System Prompt
1818
</button>

src/lib/components/WebSearchToggle.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
<div
1010
class="flex h-8 cursor-pointer select-none items-center gap-2 rounded-lg border bg-white p-1.5 shadow-sm hover:shadow-none dark:border-gray-800 dark:bg-gray-900"
1111
on:click={toggle}
12-
on:keypress={toggle}
12+
on:keydown={toggle}
1313
aria-checked={$webSearchParameters.useSearch}
1414
aria-label="web search toggle"
1515
role="switch"
1616
tabindex="0"
1717
>
18-
<Switch name="useSearch" bind:checked={$webSearchParameters.useSearch} on:click on:keypress />
18+
<Switch name="useSearch" bind:checked={$webSearchParameters.useSearch} on:click on:keydown />
1919
<div class="whitespace-nowrap text-sm text-gray-800 dark:text-gray-200">Search web</div>
2020
<div class="group relative w-max">
2121
<CarbonInformation class="text-xs text-gray-500" />

src/lib/components/chat/AssistantIntroduction.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@
4747
<p class="pt-2 text-sm text-gray-400 dark:text-gray-500">
4848
Created by <a
4949
class="hover:underline"
50-
href="https://hf.co/{assistant.createdByName}"
51-
target="_blank"
50+
href="{base}/assistants?user={assistant.createdByName}"
5251
>
5352
{assistant.createdByName}
5453
</a>

src/lib/components/chat/ChatInput.svelte

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
// submit on enter
2323
if (event.key === "Enter" && !event.shiftKey && !isCompositionOn) {
2424
event.preventDefault();
25+
// blur to close keyboard on mobile
26+
textareaElement.blur();
27+
// refocus so that user on desktop can start typing without needing to reclick on textarea
28+
if (innerWidth > TABLET_VIEWPORT_WIDTH) {
29+
textareaElement.focus();
30+
}
2531
dispatch("submit"); // use a custom event instead of `event.target.form.requestSubmit()` as it does not work on Safari 14
2632
}
2733
}
@@ -53,7 +59,7 @@
5359
on:keydown={handleKeydown}
5460
on:compositionstart={() => (isCompositionOn = true)}
5561
on:compositionend={() => (isCompositionOn = false)}
56-
on:keypress
62+
on:beforeinput
5763
{placeholder}
5864
/>
5965
</div>

src/lib/components/chat/ChatMessage.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@
138138
class="group relative -mb-8 flex items-start justify-start gap-4 pb-8 leading-relaxed"
139139
role="presentation"
140140
on:click={() => (isTapped = !isTapped)}
141-
on:keypress={() => (isTapped = !isTapped)}
141+
on:keydown={() => (isTapped = !isTapped)}
142142
>
143143
{#if $page.data?.assistant?.avatar}
144144
<img

src/lib/components/chat/ChatWindow.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@
212212
placeholder="Ask anything"
213213
bind:value={message}
214214
on:submit={handleSubmit}
215-
on:keypress={(ev) => {
215+
on:beforeinput={(ev) => {
216216
if ($page.data.loginRequired) {
217217
ev.preventDefault();
218218
loginModalOpen = true;

src/lib/utils/getHref.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
export function getHref(
2+
url: URL | string,
3+
modifications: {
4+
newKeys?: Record<string, string | undefined | null>;
5+
existingKeys?: { behaviour: "delete_except" | "delete"; keys: string[] };
6+
}
7+
) {
8+
const newUrl = new URL(url);
9+
const { newKeys, existingKeys } = modifications;
10+
11+
// exsiting keys logic
12+
if (existingKeys) {
13+
const { behaviour, keys } = existingKeys;
14+
if (behaviour === "delete") {
15+
for (const key of keys) {
16+
newUrl.searchParams.delete(key);
17+
}
18+
} else {
19+
// delete_except
20+
const keysToPreserve = keys;
21+
for (const key of [...newUrl.searchParams.keys()]) {
22+
if (!keysToPreserve.includes(key)) {
23+
newUrl.searchParams.delete(key);
24+
}
25+
}
26+
}
27+
}
28+
29+
// new keys logic
30+
if (newKeys) {
31+
for (const [key, val] of Object.entries(newKeys)) {
32+
if (val) {
33+
newUrl.searchParams.set(key, val);
34+
} else {
35+
newUrl.searchParams.delete(key);
36+
}
37+
}
38+
}
39+
40+
return newUrl.toString();
41+
}

src/routes/assistant/[assistantId]/+page.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@
7373
<p class="mt-2 text-sm text-gray-500">
7474
Created by <a
7575
class="hover:underline"
76-
href="https://hf.co/{data.assistant.createdByName}"
77-
target="_blank"
76+
href="{base}/assistants?user={data.assistant.createdByName}"
7877
>
7978
{data.assistant.createdByName}
8079
</a>

src/routes/assistants/+page.server.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,33 @@ import { base } from "$app/paths";
22
import { ENABLE_ASSISTANTS } from "$env/static/private";
33
import { collections } from "$lib/server/database.js";
44
import type { Assistant } from "$lib/types/Assistant";
5-
import { redirect } from "@sveltejs/kit";
5+
import { error, redirect } from "@sveltejs/kit";
66
import type { Filter } from "mongodb";
77

88
const NUM_PER_PAGE = 24;
99

10-
export const load = async ({ url }) => {
10+
export const load = async ({ url, locals }) => {
1111
if (!ENABLE_ASSISTANTS) {
1212
throw redirect(302, `${base}/`);
1313
}
1414

1515
const modelId = url.searchParams.get("modelId");
1616
const pageIndex = parseInt(url.searchParams.get("p") ?? "0");
17+
const createdByName = url.searchParams.get("user");
18+
const createdByCurrentUser = locals.user?.username && locals.user.username === createdByName;
19+
20+
if (createdByName) {
21+
const existingUser = await collections.users.findOne({ username: createdByName });
22+
if (!existingUser) {
23+
throw error(404, `User "${createdByName}" doesn't exist`);
24+
}
25+
}
1726

1827
// 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
1928
const filter: Filter<Assistant> = {
20-
userCount: { $gt: 1 },
2129
modelId: modelId ?? { $exists: true },
22-
featured: true,
30+
...(!createdByCurrentUser && { userCount: { $gt: 1 } }),
31+
...(createdByName ? { createdByName } : { featured: true }),
2332
};
2433
const assistants = await collections.assistants
2534
.find(filter)

src/routes/assistants/+page.svelte

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,23 @@
1010
1111
import CarbonAdd from "~icons/carbon/add";
1212
import CarbonHelpFilled from "~icons/carbon/help-filled";
13+
import CarbonClose from "~icons/carbon/close";
14+
import CarbonArrowUpRight from "~icons/carbon/arrow-up-right";
15+
import CarbonEarthAmerica from "~icons/carbon/earth-americas-filled";
16+
// import CarbonViewOff from "~icons/carbon/view-off-filled";
1317
import Pagination from "$lib/components/Pagination.svelte";
18+
import { getHref } from "$lib/utils/getHref";
1419
1520
export let data: PageData;
1621
22+
$: assistantsCreator = $page.url.searchParams.get("user");
23+
$: createdByMe = data.user?.username && data.user.username === assistantsCreator;
24+
1725
const onModelChange = (e: Event) => {
18-
const newUrl = new URL($page.url);
19-
newUrl.search = ""; // clear searchParams (such as "p" for pagination)
20-
if ((e.target as HTMLSelectElement).value) {
21-
newUrl.searchParams.set("modelId", (e.target as HTMLSelectElement).value);
22-
}
26+
const newUrl = getHref($page.url, {
27+
newKeys: { modelId: (e.target as HTMLSelectElement).value },
28+
existingKeys: { behaviour: "delete_except", keys: ["user"] },
29+
});
2330
goto(newUrl);
2431
};
2532
</script>
@@ -79,12 +86,71 @@
7986
<CarbonAdd />Create New assistant
8087
</a>
8188
</div>
82-
<div class="mt-10 grid grid-cols-2 gap-3 sm:gap-5 md:grid-cols-3 lg:grid-cols-4">
83-
{#each data.assistants as assistant}
89+
90+
<div class="mt-7 flex items-center gap-x-2 text-sm">
91+
{#if assistantsCreator && !createdByMe}
92+
<div
93+
class="flex items-center gap-1.5 rounded-full border border-gray-300 bg-gray-50 px-3 py-1 dark:border-gray-600 dark:bg-gray-700 dark:text-white"
94+
>
95+
{assistantsCreator}'s Assistants
96+
<a
97+
href={getHref($page.url, {
98+
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] },
99+
})}
100+
class="group"
101+
><CarbonClose
102+
class="text-xs group-hover:text-gray-800 dark:group-hover:text-gray-300"
103+
/></a
104+
>
105+
</div>
106+
{#if isHuggingChat}
107+
<a
108+
href="https://hf.co/{assistantsCreator}"
109+
target="_blank"
110+
class="ml-auto flex items-center text-xs text-gray-500 underline hover:text-gray-800 dark:text-gray-400 dark:hover:text-gray-300"
111+
><CarbonArrowUpRight class="mr-1 flex-none text-[0.58rem]" target="_blank" />View {assistantsCreator}
112+
on HF</a
113+
>
114+
{/if}
115+
{:else}
116+
<a
117+
href={getHref($page.url, {
118+
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] },
119+
})}
120+
class="flex items-center gap-1.5 rounded-full border px-3 py-1 {!assistantsCreator
121+
? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white'
122+
: 'border-transparent text-gray-400 hover:text-gray-800 dark:hover:text-gray-300'}"
123+
>
124+
<CarbonEarthAmerica class="text-xs" />
125+
Community
126+
</a>
127+
{#if data.user?.username}
128+
<a
129+
href={getHref($page.url, {
130+
newKeys: { user: data.user.username },
131+
existingKeys: { behaviour: "delete", keys: ["modelId", "p"] },
132+
})}
133+
class="flex items-center gap-1.5 rounded-full border px-3 py-1 {assistantsCreator &&
134+
createdByMe
135+
? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white'
136+
: 'border-transparent text-gray-400 hover:text-gray-800 dark:hover:text-gray-300'}"
137+
>{data.user.username}
138+
</a>
139+
{/if}
140+
{/if}
141+
</div>
142+
143+
<div class="mt-8 grid grid-cols-2 gap-3 sm:gap-5 md:grid-cols-3 lg:grid-cols-4">
144+
{#each data.assistants as assistant (assistant._id)}
84145
<a
85146
href="{base}/assistant/{assistant._id}"
86-
class="flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40"
147+
class="relative flex flex-col items-center justify-center overflow-hidden text-balance rounded-xl border bg-gray-50/50 px-4 py-6 text-center shadow hover:bg-gray-50 hover:shadow-inner max-sm:px-4 sm:h-64 sm:pb-4 dark:border-gray-800/70 dark:bg-gray-950/20 dark:hover:bg-gray-950/40"
87148
>
149+
<!-- {#if assistant.userCount && assistant.userCount > 1}
150+
<div class="absolute right-2 top-2" title="share with others to make it public">
151+
<CarbonViewOff class="opacity-70" />
152+
</div>
153+
{/if} -->
88154
{#if assistant.avatar}
89155
<img
90156
src="{base}/settings/assistants/{assistant._id}/avatar.jpg"
@@ -110,8 +176,7 @@
110176
<p class="mt-auto pt-2 text-xs text-gray-400 dark:text-gray-500">
111177
Created by <a
112178
class="hover:underline"
113-
href="https://hf.co/{assistant.createdByName}"
114-
target="_blank"
179+
href="{base}/assistants?user={assistant.createdByName}"
115180
>
116181
{assistant.createdByName}
117182
</a>

0 commit comments

Comments
 (0)