mirror of
https://github.com/open-webui/open-webui
synced 2024-11-16 05:24:02 +00:00
feat: model selector fuzzy search
Co-Authored-By: Aryan Kothari <87589047+thearyadev@users.noreply.github.com>
This commit is contained in:
parent
039c5c540b
commit
6ac40552b4
9
package-lock.json
generated
9
package-lock.json
generated
@ -20,6 +20,7 @@
|
|||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"eventsource-parser": "^1.1.2",
|
"eventsource-parser": "^1.1.2",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
|
"fuse.js": "^7.0.0",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"i18next": "^23.10.0",
|
"i18next": "^23.10.0",
|
||||||
"i18next-browser-languagedetector": "^7.2.0",
|
"i18next-browser-languagedetector": "^7.2.0",
|
||||||
@ -4820,6 +4821,14 @@
|
|||||||
"url": "https://github.com/sponsors/ljharb"
|
"url": "https://github.com/sponsors/ljharb"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/fuse.js": {
|
||||||
|
"version": "7.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/fuse.js/-/fuse.js-7.0.0.tgz",
|
||||||
|
"integrity": "sha512-14F4hBIxqKvD4Zz/XjDc3y94mNZN6pRv3U13Udo0lNLCWRBUsrMv2xwcF/y/Z5sV6+FQW+/ow68cHpm4sunt8Q==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=10"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/gc-hook": {
|
"node_modules/gc-hook": {
|
||||||
"version": "0.3.1",
|
"version": "0.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/gc-hook/-/gc-hook-0.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/gc-hook/-/gc-hook-0.3.1.tgz",
|
||||||
|
@ -60,6 +60,7 @@
|
|||||||
"dayjs": "^1.11.10",
|
"dayjs": "^1.11.10",
|
||||||
"eventsource-parser": "^1.1.2",
|
"eventsource-parser": "^1.1.2",
|
||||||
"file-saver": "^2.0.5",
|
"file-saver": "^2.0.5",
|
||||||
|
"fuse.js": "^7.0.0",
|
||||||
"highlight.js": "^11.9.0",
|
"highlight.js": "^11.9.0",
|
||||||
"i18next": "^23.10.0",
|
"i18next": "^23.10.0",
|
||||||
"i18next-browser-languagedetector": "^7.2.0",
|
"i18next-browser-languagedetector": "^7.2.0",
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { DropdownMenu } from 'bits-ui';
|
import { DropdownMenu } from 'bits-ui';
|
||||||
import { marked } from 'marked';
|
import { marked } from 'marked';
|
||||||
|
import Fuse from 'fuse.js';
|
||||||
|
|
||||||
import { flyAndScale } from '$lib/utils/transitions';
|
import { flyAndScale } from '$lib/utils/transitions';
|
||||||
import { createEventDispatcher, onMount, getContext, tick } from 'svelte';
|
import { createEventDispatcher, onMount, getContext, tick } from 'svelte';
|
||||||
@ -45,17 +46,28 @@
|
|||||||
|
|
||||||
let selectedModelIdx = 0;
|
let selectedModelIdx = 0;
|
||||||
|
|
||||||
$: filteredItems = items.filter(
|
const fuse = new Fuse(
|
||||||
(item) =>
|
items
|
||||||
(searchValue
|
.filter((item) => !item.model?.info?.meta?.hidden)
|
||||||
? item.value.toLowerCase().includes(searchValue.toLowerCase()) ||
|
.map((item) => {
|
||||||
item.label.toLowerCase().includes(searchValue.toLowerCase()) ||
|
const _item = {
|
||||||
(item.model?.info?.meta?.tags ?? []).some((tag) =>
|
...item,
|
||||||
tag.name.toLowerCase().includes(searchValue.toLowerCase())
|
modelName: item.model?.name,
|
||||||
)
|
tags: item.model?.info?.meta?.tags?.map((tag) => tag.name).join(' ')
|
||||||
: true) && !(item.model?.info?.meta?.hidden ?? false)
|
};
|
||||||
|
return _item;
|
||||||
|
}),
|
||||||
|
{
|
||||||
|
keys: ['value', 'label', 'tags', 'modelName']
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$: filteredItems = searchValue
|
||||||
|
? fuse.search(searchValue).map((e) => {
|
||||||
|
return e.item;
|
||||||
|
})
|
||||||
|
: items.filter((item) => !item.model?.info?.meta?.hidden);
|
||||||
|
|
||||||
const pullModelHandler = async () => {
|
const pullModelHandler = async () => {
|
||||||
const sanitizedModelTag = searchValue.trim().replace(/^ollama\s+(run|pull)\s+/, '');
|
const sanitizedModelTag = searchValue.trim().replace(/^ollama\s+(run|pull)\s+/, '');
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user