refac
This commit is contained in:
@@ -45,6 +45,7 @@ from open_webui.models.config import Config
|
||||
from open_webui.models.folders import Folders
|
||||
from open_webui.models.functions import Functions
|
||||
from open_webui.models.models import Models
|
||||
from open_webui.models.notes import Notes
|
||||
from open_webui.models.oauth_sessions import OAuthSessions
|
||||
from open_webui.models.users import UserModel, Users
|
||||
from open_webui.retrieval.utils import get_sources_from_items
|
||||
@@ -74,6 +75,7 @@ from open_webui.socket.main import (
|
||||
get_event_emitter,
|
||||
)
|
||||
from open_webui.utils.access_control import has_connection_access, has_permission
|
||||
from open_webui.models.access_grants import AccessGrants
|
||||
from open_webui.utils.access_control.folders import has_folder_access
|
||||
from open_webui.utils.chat import generate_chat_completion
|
||||
from open_webui.utils.code_interpreter import execute_code_jupyter
|
||||
@@ -2526,6 +2528,30 @@ async def process_chat_payload(request, form_data, user, metadata, model):
|
||||
chat = None
|
||||
if metadata.get('chat_id') and not metadata['chat_id'].startswith(('local:', 'channel:')):
|
||||
chat = await Chats.get_chat_by_id(metadata['chat_id'])
|
||||
|
||||
if chat and (chat.meta or {}).get('internal') is True and (chat.meta or {}).get('type') == 'note':
|
||||
note_id = (chat.meta or {}).get('note_id')
|
||||
note = await Notes.get_note_by_id(note_id) if note_id else None
|
||||
if note and (
|
||||
user.role == 'admin'
|
||||
or note.user_id == user.id
|
||||
or await AccessGrants.has_access(
|
||||
user_id=user.id,
|
||||
resource_type='note',
|
||||
resource_id=note.id,
|
||||
permission='read',
|
||||
)
|
||||
):
|
||||
note_files = [
|
||||
file
|
||||
for file in ((note.data or {}).get('files') or [])
|
||||
if isinstance(file, dict)
|
||||
and file.get('type') != 'image'
|
||||
and not (file.get('content_type') or '').startswith('image/')
|
||||
]
|
||||
if note_files:
|
||||
files = [*(files or []), *note_files]
|
||||
|
||||
use_builtin_tools = (
|
||||
(chat and (chat.meta or {}).get('internal') is True and (chat.meta or {}).get('type') == 'note')
|
||||
or (
|
||||
|
||||
Reference in New Issue
Block a user