feat: global filter

This commit is contained in:
Timothy J. Baek 2024-06-23 18:39:27 -07:00
parent d8c112d8b0
commit 3a629ffe00
2 changed files with 62 additions and 53 deletions

View File

@ -376,9 +376,18 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
) )
model = app.state.MODELS[model_id] model = app.state.MODELS[model_id]
filter_ids = [
function.id
for function in Functions.get_functions_by_type(
"filter", active_only=True
)
]
# Check if the model has any filters # Check if the model has any filters
if "info" in model and "meta" in model["info"]: if "info" in model and "meta" in model["info"]:
for filter_id in model["info"]["meta"].get("filterIds", []): filter_ids.extend(model["info"]["meta"].get("filterIds", []))
filter_ids = list(set(filter_ids))
for filter_id in filter_ids:
filter = Functions.get_function_by_id(filter_id) filter = Functions.get_function_by_id(filter_id)
if filter: if filter:
if filter_id in webui_app.state.FUNCTIONS: if filter_id in webui_app.state.FUNCTIONS:
@ -411,13 +420,11 @@ class ChatCompletionMiddleware(BaseHTTPMiddleware):
try: try:
if hasattr(function_module, "UserValves"): if hasattr(function_module, "UserValves"):
__user__["valves"] = ( __user__["valves"] = function_module.UserValves(
function_module.UserValves(
**Functions.get_user_valves_by_id_and_user_id( **Functions.get_user_valves_by_id_and_user_id(
filter_id, user.id filter_id, user.id
) )
) )
)
except Exception as e: except Exception as e:
print(e) print(e)
@ -863,6 +870,7 @@ async def generate_chat_completions(form_data: dict, user=Depends(get_verified_u
pipe = model.get("pipe") pipe = model.get("pipe")
if pipe: if pipe:
async def job(): async def job():
pipe_id = form_data["model"] pipe_id = form_data["model"]
if "." in pipe_id: if "." in pipe_id:

View File

@ -227,8 +227,9 @@
<div class=" self-center mx-1"> <div class=" self-center mx-1">
<Switch <Switch
bind:state={func.is_active} bind:state={func.is_active}
on:change={(e) => { on:change={async (e) => {
toggleFunctionById(localStorage.token, func.id); toggleFunctionById(localStorage.token, func.id);
models.set(await getModels(localStorage.token));
}} }}
/> />
</div> </div>