chore: format

This commit is contained in:
Timothy Jaeryang Baek
2026-07-27 00:12:47 -04:00
parent e53ff57fb5
commit 20647bd2d5
20 changed files with 67 additions and 70 deletions
@@ -378,9 +378,7 @@ async def check_model_access(
raise HTTPException(status_code=403, detail='Model not found')
# Enforce access on chained base models
if not await has_base_model_access(
user.id, model_info, user_role=user.role, user_group_ids=user_group_ids
):
if not await has_base_model_access(user.id, model_info, user_role=user.role, user_group_ids=user_group_ids):
raise HTTPException(status_code=403, detail='Model not found')
else:
if user.role != 'admin':
+1 -1
View File
@@ -477,7 +477,7 @@ async def execute_automation(app, automation: AutomationModel) -> None:
{'role': 'user', 'content': prompt},
],
'meta': {'automation_id': automation.id},
}
},
),
)
+3 -10
View File
@@ -205,9 +205,7 @@ async def _load_config() -> dict:
'enable': bool(values.get('chat.context_compaction.enable', False)),
'token_threshold': token_threshold,
'token_cap': _parse_positive_int(values.get('chat.context_compaction.token_cap')) or token_threshold,
'retention_percentage': _clamp_retention_percentage(
values.get('chat.context_compaction.retention_percentage')
),
'retention_percentage': _clamp_retention_percentage(values.get('chat.context_compaction.retention_percentage')),
'prompt_template': values.get('chat.context_compaction.prompt_template', '') or '',
}
@@ -261,14 +259,9 @@ async def get_chat_context_usage(chat: Any, model_id: str | None = None) -> dict
for idx in range(len(messages) - 1, -1, -1):
usage = messages[idx].get('usage') or (messages[idx].get('info') or {}).get('usage')
input_tokens = (
(usage or {}).get('prompt_tokens')
or (usage or {}).get('input_tokens')
)
input_tokens = (usage or {}).get('prompt_tokens') or (usage or {}).get('input_tokens')
if isinstance(usage, dict) and input_tokens:
tokens = int(input_tokens or 0) + int(
usage.get('completion_tokens') or usage.get('output_tokens') or 0
)
tokens = int(input_tokens or 0) + int(usage.get('completion_tokens') or usage.get('output_tokens') or 0)
tokens += _estimate_messages_tokens(messages[idx + 1 :])
return _build_context_usage(tokens, threshold)
+3 -1
View File
@@ -70,7 +70,9 @@ def custom_headers_require_user_groups(custom_headers: Optional[dict]) -> bool:
)
async def get_user_groups_for_custom_headers(custom_headers: Optional[dict], user: Optional[Any] = None) -> Optional[list]:
async def get_user_groups_for_custom_headers(
custom_headers: Optional[dict], user: Optional[Any] = None
) -> Optional[list]:
"""Fetch the user's groups only when a header value actually references a groups placeholder."""
if user is None or not custom_headers_require_user_groups(custom_headers):
return None
+3 -15
View File
@@ -3567,11 +3567,7 @@ async def non_streaming_chat_response_handler(response, ctx):
}
)
title = (
await Chats.get_chat_title_by_id(metadata['chat_id'])
if save_to_chat
else ''
)
title = await Chats.get_chat_title_by_id(metadata['chat_id']) if save_to_chat else ''
# Use output from backend if provided (OR-compliant backends),
# otherwise generate from response content
@@ -3648,11 +3644,7 @@ async def non_streaming_chat_response_handler(response, ctx):
except Exception as e:
log.debug(f'Error occurred while processing request: {e}')
chat_id = metadata.get('chat_id')
if (
getattr(request.state, 'internal', False) is not True
and chat_id
and is_saved_chat_id(chat_id)
):
if getattr(request.state, 'internal', False) is not True and chat_id and is_saved_chat_id(chat_id):
webui_url = await Config.get('webui.url')
await publish_event(
request,
@@ -5337,11 +5329,7 @@ async def streaming_chat_response_handler(response, ctx):
if item.get('status') == 'in_progress':
item['status'] = 'completed'
title = (
await Chats.get_chat_title_by_id(metadata['chat_id'])
if save_to_chat
else ''
)
title = await Chats.get_chat_title_by_id(metadata['chat_id']) if save_to_chat else ''
data = {
'done': True,
'output': output,
+1 -3
View File
@@ -194,9 +194,7 @@ def get_output_text(output: list | None) -> str:
continue
text = ''.join(
str(part.get('text'))
for part in parts
if isinstance(part, dict) and part.get('text') is not None
str(part.get('text')) for part in parts if isinstance(part, dict) and part.get('text') is not None
)
if text.strip():
texts.append(text)