refac
This commit is contained in:
1 parent
a0c2ec3d2c
commit
91762ed807
8 files changed
+77
-78
No files matched your search
@@ -22,6 +22,7 @@ from open_webui.models.functions import (
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.plugin import (
|
||||
get_functions_cache,
|
||||
get_function_module_from_cache,
|
||||
load_function_module_by_id,
|
||||
replace_imports,
|
||||
@@ -205,7 +206,7 @@ async def create_new_function(
|
||||
)
|
||||
form_data.meta.manifest = frontmatter
|
||||
|
||||
FUNCTIONS = request.app.state.FUNCTIONS
|
||||
FUNCTIONS = get_functions_cache(request)
|
||||
FUNCTIONS[form_data.id] = function_module
|
||||
|
||||
function = await Functions.insert_new_function(user.id, function_type, form_data, db=db)
|
||||
@@ -322,7 +323,7 @@ async def update_function_by_id(
|
||||
function_module, function_type, frontmatter = await load_function_module_by_id(id, content=form_data.content)
|
||||
form_data.meta.manifest = frontmatter
|
||||
|
||||
FUNCTIONS = request.app.state.FUNCTIONS
|
||||
FUNCTIONS = get_functions_cache(request)
|
||||
FUNCTIONS[id] = function_module
|
||||
|
||||
updated = {**form_data.model_dump(exclude={'id'}), 'type': function_type}
|
||||
@@ -363,9 +364,8 @@ async def delete_function_by_id(
|
||||
result = await Functions.delete_function_by_id(id, db=db)
|
||||
|
||||
if result:
|
||||
FUNCTIONS = request.app.state.FUNCTIONS
|
||||
if id in FUNCTIONS:
|
||||
del FUNCTIONS[id]
|
||||
FUNCTIONS = get_functions_cache(request)
|
||||
FUNCTIONS.pop(id, None)
|
||||
|
||||
return result
|
||||
|
||||
|
||||
@@ -773,14 +773,15 @@ async def edit_images(request: Request, form_data: EditImageForm, user=Depends(g
|
||||
# global image-edit switch and the per-user image-generation permission. The internal
|
||||
# callers (edit_image tool, chat middleware) gate themselves and call image_edits()
|
||||
# directly, so they are unaffected by this wrapper.
|
||||
if not request.app.state.config.ENABLE_IMAGE_EDIT:
|
||||
image_config = await get_image_config()
|
||||
if not image_config.ENABLE_IMAGE_EDIT:
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
if user.role != 'admin' and not await has_permission(
|
||||
user.id, 'features.image_generation', request.app.state.config.USER_PERMISSIONS
|
||||
user.id, 'features.image_generation', image_config.USER_PERMISSIONS
|
||||
):
|
||||
raise HTTPException(
|
||||
status_code=403,
|
||||
|
||||
@@ -532,11 +532,7 @@ async def get_model_profile_image(
|
||||
|
||||
# Fallback: check arena models stored in config (not in the DB)
|
||||
if not profile_image_url:
|
||||
arena_models = getattr(
|
||||
getattr(request.app.state, 'config', None),
|
||||
'EVALUATION_ARENA_MODELS',
|
||||
[],
|
||||
)
|
||||
arena_models = await Config.get('evaluation.arena.models', []) or []
|
||||
for arena_model in arena_models:
|
||||
if arena_model.get('id') == id:
|
||||
profile_image_url = arena_model.get('meta', {}).get('profile_image_url')
|
||||
|
||||
@@ -31,6 +31,7 @@ from open_webui.utils.access_control import (
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
from open_webui.utils.plugin import (
|
||||
get_tools_cache,
|
||||
get_tool_module_from_cache,
|
||||
load_tool_module_by_id,
|
||||
replace_imports,
|
||||
@@ -70,8 +71,9 @@ async def get_tools(
|
||||
tools = []
|
||||
|
||||
# Local Tools
|
||||
tools_cache = get_tools_cache(request)
|
||||
for tool in await Tools.get_tools(defer_content=True, db=db):
|
||||
tool_module = request.app.state.TOOLS.get(tool.id) if hasattr(request.app.state, 'TOOLS') else None
|
||||
tool_module = tools_cache.get(tool.id)
|
||||
tools.append(
|
||||
ToolUserResponse(
|
||||
**{
|
||||
@@ -368,7 +370,7 @@ async def create_new_tools(
|
||||
tool_module, frontmatter = await load_tool_module_by_id(form_data.id, content=form_data.content)
|
||||
form_data.meta.manifest = frontmatter
|
||||
|
||||
TOOLS = request.app.state.TOOLS
|
||||
TOOLS = get_tools_cache(request)
|
||||
TOOLS[form_data.id] = tool_module
|
||||
|
||||
specs = get_tool_specs(TOOLS[form_data.id])
|
||||
@@ -498,7 +500,7 @@ async def update_tools_by_id(
|
||||
tool_module, frontmatter = await load_tool_module_by_id(id, content=form_data.content)
|
||||
form_data.meta.manifest = frontmatter
|
||||
|
||||
TOOLS = request.app.state.TOOLS
|
||||
TOOLS = get_tools_cache(request)
|
||||
TOOLS[id] = tool_module
|
||||
|
||||
specs = get_tool_specs(TOOLS[id])
|
||||
@@ -624,9 +626,8 @@ async def delete_tools_by_id(
|
||||
|
||||
result = await Tools.delete_tool_by_id(id, db=db)
|
||||
if result:
|
||||
TOOLS = request.app.state.TOOLS
|
||||
if id in TOOLS:
|
||||
del TOOLS[id]
|
||||
TOOLS = get_tools_cache(request)
|
||||
TOOLS.pop(id, None)
|
||||
|
||||
return result
|
||||
|
||||
@@ -708,11 +709,7 @@ async def get_tools_valves_spec_by_id(
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
if id in request.app.state.TOOLS:
|
||||
tools_module = request.app.state.TOOLS[id]
|
||||
else:
|
||||
tools_module, _ = await load_tool_module_by_id(id)
|
||||
request.app.state.TOOLS[id] = tools_module
|
||||
tools_module, _ = await get_tool_module_from_cache(request, id)
|
||||
|
||||
if hasattr(tools_module, 'Valves'):
|
||||
Valves = tools_module.Valves
|
||||
@@ -759,11 +756,7 @@ async def update_tools_valves_by_id(
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
if id in request.app.state.TOOLS:
|
||||
tools_module = request.app.state.TOOLS[id]
|
||||
else:
|
||||
tools_module, _ = await load_tool_module_by_id(id)
|
||||
request.app.state.TOOLS[id] = tools_module
|
||||
tools_module, _ = await get_tool_module_from_cache(request, id)
|
||||
|
||||
if not hasattr(tools_module, 'Valves'):
|
||||
raise HTTPException(
|
||||
@@ -858,11 +851,7 @@ async def get_tools_user_valves_spec_by_id(
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
if id in request.app.state.TOOLS:
|
||||
tools_module = request.app.state.TOOLS[id]
|
||||
else:
|
||||
tools_module, _ = await load_tool_module_by_id(id)
|
||||
request.app.state.TOOLS[id] = tools_module
|
||||
tools_module, _ = await get_tool_module_from_cache(request, id)
|
||||
|
||||
if hasattr(tools_module, 'UserValves'):
|
||||
UserValves = tools_module.UserValves
|
||||
@@ -904,11 +893,7 @@ async def update_tools_user_valves_by_id(
|
||||
detail=ERROR_MESSAGES.ACCESS_PROHIBITED,
|
||||
)
|
||||
|
||||
if id in request.app.state.TOOLS:
|
||||
tools_module = request.app.state.TOOLS[id]
|
||||
else:
|
||||
tools_module, _ = await load_tool_module_by_id(id)
|
||||
request.app.state.TOOLS[id] = tools_module
|
||||
tools_module, _ = await get_tool_module_from_cache(request, id)
|
||||
|
||||
if hasattr(tools_module, 'UserValves'):
|
||||
UserValves = tools_module.UserValves
|
||||
|
||||
Reference in new issue
Block a user