Skip to content

Commit 49e57f4

Browse files
committed
chore: format
1 parent 4a42543 commit 49e57f4

16 files changed

Lines changed: 44 additions & 60 deletions

File tree

backend/open_webui/main.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,9 +1402,9 @@ async def run_initial_title_generation():
14021402
'content_preview': user_message.get('content', '')[:300],
14031403
},
14041404
)
1405-
if not getattr(request.state, 'internal', False) and not (
1406-
user_message.get('meta') or {}
1407-
).get('internal'):
1405+
if not getattr(request.state, 'internal', False) and not (user_message.get('meta') or {}).get(
1406+
'internal'
1407+
):
14081408
try:
14091409
from open_webui.utils.timers import cancel_timers_for_chat
14101410

@@ -1815,9 +1815,7 @@ async def generate_messages(
18151815
},
18161816
)
18171817
elif isinstance(response, dict):
1818-
return convert_openai_to_anthropic_response(
1819-
response, model=requested_model, input_tokens=input_tokens
1820-
)
1818+
return convert_openai_to_anthropic_response(response, model=requested_model, input_tokens=input_tokens)
18211819
else:
18221820
# Passthrough for error responses (JSONResponse, PlainTextResponse, etc.)
18231821
return response

backend/open_webui/models/chats.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1593,12 +1593,14 @@ async def get_chats_by_user_id_and_search_text(
15931593

15941594
# Check if there are any tags to filter
15951595
if 'none' in tag_ids:
1596-
stmt = stmt.filter(text("""
1596+
stmt = stmt.filter(
1597+
text("""
15971598
NOT EXISTS (
15981599
SELECT 1
15991600
FROM json_each(Chat.meta, '$.tags') AS tag
16001601
)
1601-
"""))
1602+
""")
1603+
)
16021604
elif tag_ids:
16031605
stmt = stmt.filter(
16041606
and_(
@@ -1641,12 +1643,14 @@ async def get_chats_by_user_id_and_search_text(
16411643
).params(title_key=f'%{search_text}%', content_key=search_text.lower())
16421644

16431645
if 'none' in tag_ids:
1644-
stmt = stmt.filter(text("""
1646+
stmt = stmt.filter(
1647+
text("""
16451648
NOT EXISTS (
16461649
SELECT 1
16471650
FROM json_array_elements_text(Chat.meta->'tags') AS tag
16481651
)
1649-
"""))
1652+
""")
1653+
)
16501654
elif tag_ids:
16511655
stmt = stmt.filter(
16521656
and_(

backend/open_webui/retrieval/utils.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1340,9 +1340,7 @@ async def get_sources_from_items(
13401340
folder = await Folders.get_folder_by_id(folder_id)
13411341
if folder and (user.role == 'admin' or await has_folder_access(user.id, folder, 'read', db=None)):
13421342
files = (folder.data or {}).get('files', [])
1343-
folder_items.update(
1344-
(entry.get('type'), entry.get('id')) for entry in files if isinstance(entry, dict)
1345-
)
1343+
folder_items.update((entry.get('type'), entry.get('id')) for entry in files if isinstance(entry, dict))
13461344
items.extend(files)
13471345

13481346
for item in items:

backend/open_webui/retrieval/vector/dbs/milvus_multitenancy.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,7 @@ def _create_shared_collection(self, mt_collection_name: str, dimension: int):
156156
except MilvusException as e:
157157
# The index only accelerates resource_id filters; never fail
158158
# collection creation over it.
159-
log.warning(
160-
f'Could not create {RESOURCE_ID_FIELD} index on {mt_collection_name}: {e}'
161-
)
159+
log.warning(f'Could not create {RESOURCE_ID_FIELD} index on {mt_collection_name}: {e}')
162160
log.info(f'Created shared collection: {mt_collection_name}')
163161
return collection
164162

backend/open_webui/routers/files.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,7 @@ async def _process_handler(db_session):
203203
else:
204204
# Keep the generic file status stream open until the
205205
# KB-specific vector write and durable link both finish.
206-
await Files.update_file_data_by_id(
207-
file_item.id, {'status': 'processing'}, db=db_session
208-
)
206+
await Files.update_file_data_by_id(file_item.id, {'status': 'processing'}, db=db_session)
209207
await process_file(
210208
request,
211209
ProcessFileForm(file_id=file_item.id, collection_name=knowledge_id),

backend/open_webui/routers/notes.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,9 +582,7 @@ async def update_note_by_id(
582582
event_data = note.model_dump()
583583
if form_data.data is not None:
584584
event_data['data'] = {
585-
key: note.data.get(key)
586-
for key in form_data.data.keys()
587-
if note.data is not None and key in note.data
585+
key: note.data.get(key) for key in form_data.data.keys() if note.data is not None and key in note.data
588586
}
589587

590588
await sio.emit(

backend/open_webui/utils/access_control/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,8 +254,7 @@ async def filter_allowed_access_grants(
254254
access_grants = strip_user_access_grants(access_grants)
255255

256256
if any(
257-
(grant.get('principal_type') if isinstance(grant, dict) else getattr(grant, 'principal_type', None))
258-
== 'group'
257+
(grant.get('principal_type') if isinstance(grant, dict) else getattr(grant, 'principal_type', None)) == 'group'
259258
for grant in access_grants
260259
) and not await has_permission(
261260
user_id,

backend/open_webui/utils/anthropic.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -467,9 +467,7 @@ def convert_openai_to_anthropic_response(
467467
}
468468

469469

470-
async def openai_stream_to_anthropic_stream(
471-
openai_stream_generator, model: str = '', input_tokens: int = 0
472-
):
470+
async def openai_stream_to_anthropic_stream(openai_stream_generator, model: str = '', input_tokens: int = 0):
473471
"""
474472
Convert an OpenAI SSE streaming response to Anthropic Messages SSE format.
475473
@@ -560,9 +558,7 @@ async def openai_stream_to_anthropic_stream(
560558

561559
# Update usage if present
562560
if data.get('usage'):
563-
input_tokens = data['usage'].get(
564-
'input_tokens', data['usage'].get('prompt_tokens', input_tokens)
565-
)
561+
input_tokens = data['usage'].get('input_tokens', data['usage'].get('prompt_tokens', input_tokens))
566562
output_tokens = data['usage'].get(
567563
'output_tokens', data['usage'].get('completion_tokens', output_tokens)
568564
)

backend/open_webui/utils/context_compaction.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,9 +240,7 @@ async def get_chat_context_usage(chat: Any, model_id: str | None = None) -> dict
240240
usage = messages[idx].get('usage') or (messages[idx].get('info') or {}).get('usage')
241241
input_tokens = (usage or {}).get('input_tokens') or (usage or {}).get('prompt_tokens')
242242
if isinstance(usage, dict) and input_tokens:
243-
tokens = int(input_tokens or 0) + int(
244-
usage.get('output_tokens') or usage.get('completion_tokens') or 0
245-
)
243+
tokens = int(input_tokens or 0) + int(usage.get('output_tokens') or usage.get('completion_tokens') or 0)
246244
tokens += _estimate_messages_tokens(messages[idx + 1 :])
247245
return _build_context_usage(tokens, threshold)
248246

backend/open_webui/utils/subagents.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,7 @@ async def process_pending_internal_messages(
110110
and meta.get('type') == 'subagent'
111111
and meta.get('status') in (None, 'pending')
112112
)
113-
or (
114-
meta.get('internal') is True
115-
and meta.get('type') == 'timer'
116-
)
113+
or (meta.get('internal') is True and meta.get('type') == 'timer')
117114
)
118115
]
119116
if not pending:
@@ -137,11 +134,9 @@ async def process_pending_internal_messages(
137134
if message.get('parentId') == parent_id
138135
and (message.get('model') or model_id) == model_id
139136
and (
140-
(
141-
meta.get('internal') is True
142-
and meta.get('type') == 'subagent'
143-
and meta.get('status') in (None, 'pending')
144-
)
137+
meta.get('internal') is True
138+
and meta.get('type') == 'subagent'
139+
and meta.get('status') in (None, 'pending')
145140
)
146141
]
147142
combined_content = '\n\n'.join(message.get('content', '') for message in batch if message.get('content'))

0 commit comments

Comments
 (0)