mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 12:25:20 +00:00
enh/refac: function sync endpoint
This commit is contained in:
parent
3220088411
commit
df7b5ec907
1 changed files with 17 additions and 2 deletions
|
|
@ -131,14 +131,29 @@ async def load_function_from_url(
|
||||||
############################
|
############################
|
||||||
|
|
||||||
|
|
||||||
class SyncFunctionsForm(FunctionForm):
|
class SyncFunctionsForm(BaseModel):
|
||||||
functions: list[FunctionModel] = []
|
functions: list[FunctionModel] = []
|
||||||
|
|
||||||
|
|
||||||
@router.post("/sync", response_model=Optional[FunctionModel])
|
@router.post("/sync", response_model=list[FunctionModel])
|
||||||
async def sync_functions(
|
async def sync_functions(
|
||||||
request: Request, form_data: SyncFunctionsForm, user=Depends(get_admin_user)
|
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)
|
return Functions.sync_functions(user.id, form_data.functions)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue