Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
open-webui
Commits
81daf4ce
Commit
81daf4ce
authored
Mar 09, 2024
by
Timothy J. Baek
Browse files
feat: model filter frontend integration
parent
b550e23b
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
83 additions
and
6 deletions
+83
-6
backend/apps/ollama/main.py
backend/apps/ollama/main.py
+6
-3
backend/apps/openai/main.py
backend/apps/openai/main.py
+5
-3
src/lib/apis/index.ts
src/lib/apis/index.ts
+62
-0
src/lib/components/admin/Settings/Users.svelte
src/lib/components/admin/Settings/Users.svelte
+10
-0
No files found.
backend/apps/ollama/main.py
View file @
81daf4ce
...
...
@@ -135,12 +135,15 @@ async def get_ollama_tags(
):
if
url_idx
==
None
:
models
=
await
get_all_models
()
if
app
.
state
.
MODEL_FILTER_ENABLED
:
if
user
.
role
==
"user"
:
models
[
"models"
]
=
filter
(
models
[
"models"
]
=
list
(
filter
(
lambda
model
:
model
[
"name"
]
in
app
.
state
.
MODEL_LIST
,
models
[
"models"
],
)
)
return
models
return
models
else
:
...
...
backend/apps/openai/main.py
View file @
81daf4ce
...
...
@@ -196,10 +196,12 @@ async def get_models(url_idx: Optional[int] = None, user=Depends(get_current_use
models
=
await
get_all_models
()
if
app
.
state
.
MODEL_FILTER_ENABLED
:
if
user
.
role
==
"user"
:
models
[
"data"
]
=
filter
(
models
[
"data"
]
=
list
(
filter
(
lambda
model
:
model
[
"id"
]
in
app
.
state
.
MODEL_LIST
,
models
[
"data"
],
)
)
return
models
return
models
else
:
...
...
src/lib/apis/index.ts
View file @
81daf4ce
...
...
@@ -77,3 +77,65 @@ export const getVersionUpdates = async () => {
return
res
;
};
export
const
getModelFilterConfig
=
async
(
token
:
string
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_BASE_URL
}
/api/config/model/filter`
,
{
method
:
'
GET
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
Authorization
:
`Bearer
${
token
}
`
}
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
error
=
err
;
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
export
const
updateModelFilterConfig
=
async
(
token
:
string
,
enabled
:
boolean
,
models
:
string
[]
)
=>
{
let
error
=
null
;
const
res
=
await
fetch
(
`
${
WEBUI_BASE_URL
}
/api/config/model/filter`
,
{
method
:
'
POST
'
,
headers
:
{
'
Content-Type
'
:
'
application/json
'
,
Authorization
:
`Bearer
${
token
}
`
},
body
:
JSON
.
stringify
({
enabled
:
enabled
,
models
:
models
})
})
.
then
(
async
(
res
)
=>
{
if
(
!
res
.
ok
)
throw
await
res
.
json
();
return
res
.
json
();
})
.
catch
((
err
)
=>
{
console
.
log
(
err
);
error
=
err
;
return
null
;
});
if
(
error
)
{
throw
error
;
}
return
res
;
};
src/lib/components/admin/Settings/Users.svelte
View file @
81daf4ce
<script lang="ts">
import { getModelFilterConfig, updateModelFilterConfig } from '$lib/apis';
import { getSignUpEnabledStatus, toggleSignUpEnabledStatus } from '$lib/apis/auths';
import { getUserPermissions, updateUserPermissions } from '$lib/apis/users';
import { models } from '$lib/stores';
...
...
@@ -16,6 +17,13 @@
onMount(async () => {
permissions = await getUserPermissions(localStorage.token);
const res = await getModelFilterConfig(localStorage.token);
if (res) {
whitelistEnabled = res.enabled;
whitelistModels = res.models.length > 0 ? res.models : [''];
}
});
</script>
...
...
@@ -24,6 +32,8 @@
on:submit|preventDefault={async () => {
// console.log('submit');
await updateUserPermissions(localStorage.token, permissions);
await updateModelFilterConfig(localStorage.token, whitelistEnabled, whitelistModels);
saveHandler();
}}
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment