mirror of
https://github.com/open-webui/open-webui.git
synced 2026-08-28 05:27:35 +00:00
refac: mirror native FC code_interpreter authz gates onto legacy XML-tag path (#24724)
The native function-calling tool resolver in utils/tools.py applies five gates before exposing execute_code as a builtin tool: builtin-category enable, ENABLE_CODE_INTERPRETER global config, model capability, features.code_interpreter request flag, and the per-user features.code_interpreter permission. The legacy XML-tag detection path in streaming_chat_response_handler applied only the request-flag gate. Brings the legacy path to parity by running the same five-gate check before activating tag detection. Behaviour change is limited to deployments that previously relied on the asymmetry — admins who set ENABLE_CODE_INTERPRETER=False or revoked the per-user permission, on the legacy tool-calling mode, with the client supplying features.code_interpreter=true. Any of those three conditions met now correctly disables tag detection. Co-authored-by: sfwani <sfwani@users.noreply.github.com>
This commit is contained in:
parent
c93f071700
commit
507b8b213c
1 changed files with 21 additions and 2 deletions
|
|
@ -72,7 +72,7 @@ from open_webui.socket.main import (
|
|||
get_event_call,
|
||||
get_event_emitter,
|
||||
)
|
||||
from open_webui.utils.access_control import has_connection_access
|
||||
from open_webui.utils.access_control import has_connection_access, has_permission
|
||||
from open_webui.utils.access_control.files import get_accessible_folder_files
|
||||
from open_webui.utils.chat import generate_chat_completion
|
||||
from open_webui.utils.code_interpreter import execute_code_jupyter
|
||||
|
|
@ -3853,7 +3853,26 @@ async def streaming_chat_response_handler(response, ctx):
|
|||
|
||||
reasoning_tags_param = metadata.get('params', {}).get('reasoning_tags')
|
||||
DETECT_REASONING_TAGS = reasoning_tags_param is not False
|
||||
DETECT_CODE_INTERPRETER = metadata.get('features', {}).get('code_interpreter', False)
|
||||
|
||||
# Mirror the five gates from utils/tools.py get_builtin_tools so the
|
||||
# legacy XML-tag path enforces the same authz as native FC.
|
||||
features = metadata.get('features', {}) or {}
|
||||
model_capabilities = (model.get('info', {}).get('meta', {}).get('capabilities') or {})
|
||||
builtin_tools_meta = model.get('info', {}).get('meta', {}).get('builtinTools', {})
|
||||
DETECT_CODE_INTERPRETER = (
|
||||
bool(features.get('code_interpreter'))
|
||||
and builtin_tools_meta.get('code_interpreter', True)
|
||||
and getattr(request.app.state.config, 'ENABLE_CODE_INTERPRETER', True)
|
||||
and model_capabilities.get('code_interpreter', True)
|
||||
and (
|
||||
getattr(user, 'role', None) == 'admin'
|
||||
or await has_permission(
|
||||
getattr(user, 'id', ''),
|
||||
'features.code_interpreter',
|
||||
request.app.state.config.USER_PERMISSIONS,
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
reasoning_tags = []
|
||||
if DETECT_REASONING_TAGS:
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue