diff --git a/backend/open_webui/routers/functions.py b/backend/open_webui/routers/functions.py index 96d8215fb3..73b608cd35 100644 --- a/backend/open_webui/routers/functions.py +++ b/backend/open_webui/routers/functions.py @@ -131,14 +131,29 @@ async def load_function_from_url( ############################ -class SyncFunctionsForm(FunctionForm): +class SyncFunctionsForm(BaseModel): functions: list[FunctionModel] = [] -@router.post("/sync", response_model=Optional[FunctionModel]) +@router.post("/sync", response_model=list[FunctionModel]) async def sync_functions( request: Request, form_data: SyncFunctionsForm, user=Depends(get_admin_user) ): + try: + for function in form_data.functions: + function.content = replace_imports(function.content) + function_module, function_type, frontmatter = load_function_module_by_id( + function.id, + content=function.content, + ) + except Exception as e: + log.exception(f"Failed to load a function: {e}") + raise HTTPException( + status_code=status.HTTP_400_BAD_REQUEST, + detail=ERROR_MESSAGES.DEFAULT(e), + ) + + return Functions.sync_functions(user.id, form_data.functions)