-
Notifications
You must be signed in to change notification settings - Fork 901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Assistants] Filter on names #841
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
30796e5
[Assistants] Filter on names
mishig25 00784d4
Add `$text` index on `assistant.name` (#844)
mishig25 3dd82df
add maxlength
mishig25 c575708
better experience
mishig25 285b6fe
use `$meta: "textScore"`
mishig25 c0387ce
Update src/routes/assistants/+page.server.ts
mishig25 d65f7c1
null, not undefined
mishig25 65b5d89
Merge branch 'main' into assistants_search
nsarrazin 9365a75
Merge branch 'main' into assistants_search
mishig25 05a8cf2
Merge branch 'main' into assistants_search
mishig25 08e8256
[Assistants] Filter on names (using searchTokens) (#873)
mishig25 f8bb522
Merge branch 'main' into assistants_search
mishig25 34ed43b
input
gary149 1d0da52
rm extra whitespace
gary149 cffcff5
Merge branch 'main' into assistants_search
mishig25 e696796
hide UI before migration
mishig25 4cc41c0
rm ad-hoc migration
mishig25 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* A debounce function that works in both browser and Nodejs. | ||
* For pure Nodejs work, prefer the `Debouncer` class. | ||
*/ | ||
export function debounce<T extends unknown[]>( | ||
callback: (...rest: T) => unknown, | ||
limit: number | ||
): (...rest: T) => void { | ||
let timer: ReturnType<typeof setTimeout>; | ||
|
||
return function (...rest) { | ||
clearTimeout(timer); | ||
timer = setTimeout(() => { | ||
callback(...rest); | ||
}, limit); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const PUNCTUATION_REGEX = /\p{P}/gu; | ||
|
||
function removeDiacritics(s: string, form: "NFD" | "NFKD" = "NFD"): string { | ||
return s.normalize(form).replace(/[\u0300-\u036f]/g, ""); | ||
} | ||
|
||
export function generateSearchTokens(value: string): string[] { | ||
const fullTitleToken = removeDiacritics(value) | ||
.replace(PUNCTUATION_REGEX, "") | ||
.replaceAll(/\s+/g, "") | ||
.toLowerCase(); | ||
return [ | ||
...new Set([ | ||
...removeDiacritics(value) | ||
.split(/\s+/) | ||
.map((word) => word.replace(PUNCTUATION_REGEX, "").toLowerCase()) | ||
.filter((word) => word.length), | ||
...(fullTitleToken.length ? [fullTitleToken] : []), | ||
]), | ||
]; | ||
} | ||
|
||
function escapeForRegExp(s: string): string { | ||
return s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string | ||
} | ||
|
||
export function generateQueryTokens(query: string): RegExp[] { | ||
return removeDiacritics(query) | ||
.split(/\s+/) | ||
.map((word) => word.replace(PUNCTUATION_REGEX, "").toLowerCase()) | ||
.filter((word) => word.length) | ||
.map((token) => new RegExp(`^${escapeForRegExp(token)}`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
import { PUBLIC_APP_ASSETS, PUBLIC_ORIGIN } from "$env/static/public"; | ||
import { isHuggingChat } from "$lib/utils/isHuggingChat"; | ||
|
||
import { tick } from "svelte"; | ||
import { goto } from "$app/navigation"; | ||
import { base } from "$app/paths"; | ||
import { page } from "$app/stores"; | ||
|
@@ -14,16 +15,22 @@ | |
import CarbonArrowUpRight from "~icons/carbon/arrow-up-right"; | ||
import CarbonEarthAmerica from "~icons/carbon/earth-americas-filled"; | ||
import CarbonUserMultiple from "~icons/carbon/user-multiple"; | ||
import CarbonSearch from "~icons/carbon/search"; | ||
import Pagination from "$lib/components/Pagination.svelte"; | ||
import { formatUserCount } from "$lib/utils/formatUserCount"; | ||
import { getHref } from "$lib/utils/getHref"; | ||
import { debounce } from "$lib/utils/debounce"; | ||
import { useSettingsStore } from "$lib/stores/settings"; | ||
|
||
export let data: PageData; | ||
|
||
$: assistantsCreator = $page.url.searchParams.get("user"); | ||
$: createdByMe = data.user?.username && data.user.username === assistantsCreator; | ||
|
||
const SEARCH_DEBOUNCE_DELAY = 400; | ||
let filterInputEl: HTMLInputElement; | ||
let searchDisabled = false; | ||
|
||
const onModelChange = (e: Event) => { | ||
const newUrl = getHref($page.url, { | ||
newKeys: { modelId: (e.target as HTMLSelectElement).value }, | ||
|
@@ -32,6 +39,18 @@ | |
goto(newUrl); | ||
}; | ||
|
||
const filterOnName = debounce(async (e: Event) => { | ||
searchDisabled = true; | ||
const value = (e.target as HTMLInputElement).value; | ||
const newUrl = getHref($page.url, { newKeys: { q: value } }); | ||
await goto(newUrl); | ||
setTimeout(async () => { | ||
searchDisabled = false; | ||
await tick(); | ||
filterInputEl.focus(); | ||
}, 0); | ||
}, SEARCH_DEBOUNCE_DELAY); | ||
|
||
const settings = useSettingsStore(); | ||
</script> | ||
|
||
|
@@ -99,7 +118,7 @@ | |
{assistantsCreator}'s Assistants | ||
<a | ||
href={getHref($page.url, { | ||
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] }, | ||
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p", "q"] }, | ||
})} | ||
class="group" | ||
><CarbonClose | ||
|
@@ -119,7 +138,7 @@ | |
{:else} | ||
<a | ||
href={getHref($page.url, { | ||
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p"] }, | ||
existingKeys: { behaviour: "delete", keys: ["user", "modelId", "p", "q"] }, | ||
})} | ||
class="flex items-center gap-1.5 rounded-full border px-3 py-1 {!assistantsCreator | ||
? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white' | ||
|
@@ -132,16 +151,31 @@ | |
<a | ||
href={getHref($page.url, { | ||
newKeys: { user: data.user.username }, | ||
existingKeys: { behaviour: "delete", keys: ["modelId", "p"] }, | ||
existingKeys: { behaviour: "delete", keys: ["modelId", "p", "q"] }, | ||
})} | ||
class="flex items-center gap-1.5 rounded-full border px-3 py-1 {assistantsCreator && | ||
class="flex items-center gap-1.5 truncate rounded-full border px-3 py-1 {assistantsCreator && | ||
createdByMe | ||
? 'border-gray-300 bg-gray-50 dark:border-gray-600 dark:bg-gray-700 dark:text-white' | ||
: 'border-transparent text-gray-400 hover:text-gray-800 dark:hover:text-gray-300'}" | ||
>{data.user.username} | ||
</a> | ||
{/if} | ||
{/if} | ||
<div | ||
class="relative ml-auto flex hidden h-[30px] w-40 items-center rounded-full border px-2 has-[:focus]:border-gray-400 sm:w-64 dark:border-gray-600" | ||
> | ||
<CarbonSearch class="pointer-events-none absolute left-2 text-xs text-gray-400" /> | ||
<input | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get weird behaviour (undefined is the default value then it's not obvious that there're results) Screen.Recording.2024-02-20.at.14.07.59.movThere was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
class="h-[30px] w-full bg-transparent pl-5 focus:outline-none" | ||
placeholder="Filter by name" | ||
value={data.query} | ||
on:input={filterOnName} | ||
bind:this={filterInputEl} | ||
maxlength="150" | ||
type="search" | ||
disabled={searchDisabled} | ||
/> | ||
</div> | ||
</div> | ||
|
||
<div class="mt-8 grid grid-cols-2 gap-3 sm:gap-5 md:grid-cols-3 lg:grid-cols-4"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
taking advantage of svelte partial hydration without creating explicit API routes for now