forked from open-webui/open-webui
		
	feat: model filter frontend integration
This commit is contained in:
		
							parent
							
								
									b550e23bf6
								
							
						
					
					
						commit
						81daf4ceb9
					
				
					 4 changed files with 83 additions and 6 deletions
				
			
		|  | @ -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; | ||||
| }; | ||||
|  |  | |||
|  | @ -1,4 +1,5 @@ | |||
| <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(); | ||||
| 	}} | ||||
| > | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Timothy J. Baek
						Timothy J. Baek