chore: format

This commit is contained in:
Timothy Jaeryang Baek committed 2026-08-25 16:53:53 -04:00
1 parent f71e9570c0
commit 5c62cc0517
99 files changed
+12026 -5908

No files matched your search

+1 -3
View File
@@ -1108,9 +1108,7 @@ async def chat_completion(
model = request.app.state.MODELS[model_id]
model_info = await Models.get_model_by_id(model_id)
missing_base_model = bool(
model_info
and model_info.base_model_id
and model_info.base_model_id not in request.app.state.MODELS
model_info and model_info.base_model_id and model_info.base_model_id not in request.app.state.MODELS
)
if missing_base_model and ENABLE_CUSTOM_MODEL_FALLBACK:
@@ -5,6 +5,7 @@ Revises: 1ce6ade7d93b
Create Date: 2026-08-10 23:20:20.374826
"""
import json
from typing import Sequence, Union
+2 -1
View File
@@ -31,7 +31,8 @@ def search_sougou(
params = JSONCodec.dumps({'Query': query, 'Cnt': 20})
common_client = CommonClient('tms', '2020-12-29', cred, '', profile=client_profile)
results = [
JSONCodec.loads(page) for page in common_client.call_json('SearchPro', JSONCodec.loads(params))['Response']['Pages']
JSONCodec.loads(page)
for page in common_client.call_json('SearchPro', JSONCodec.loads(params))['Response']['Pages']
]
sorted_results = sorted(results, key=lambda x: x.get('scour', 0.0), reverse=True)
if filter_list:
+1
View File
@@ -79,6 +79,7 @@ async def delete_file_resource(file: FileModel, db: AsyncSession) -> bool:
return result
############################
# Knowledge Base Embedding
############################
+4 -3
View File
@@ -2205,9 +2205,10 @@ async def _fetch_url(url: str, max_size_mb: int | str | None) -> dict:
if not is_attachment and base_content_type in {'', 'application/octet-stream', 'binary/octet-stream'}:
sample = first_chunk[:4096].lstrip().lower()
if sample.startswith(
(b'<!doctype html', b'<html', b'<head', b'<body', b'<?xml')
) or b'<html' in sample[:1024]:
if (
sample.startswith((b'<!doctype html', b'<html', b'<head', b'<body', b'<?xml'))
or b'<html' in sample[:1024]
):
return {'kind': 'web'}
if max_bytes and content_length:
+2 -6
View File
@@ -73,9 +73,7 @@ async def get_tools(
tools = []
bypass_access_control = user.role == 'admin' and BYPASS_ADMIN_ACCESS_CONTROL
user_group_ids = (
set()
if bypass_access_control
else {group.id for group in await Groups.get_groups_by_member_id(user.id, db=db)}
set() if bypass_access_control else {group.id for group in await Groups.get_groups_by_member_id(user.id, db=db)}
)
# Local Tools
@@ -210,9 +208,7 @@ async def get_tool_list(user=Depends(get_verified_user), db: AsyncSession = Depe
bypass_access_control = user.role == 'admin' and BYPASS_ADMIN_ACCESS_CONTROL
user_group_ids = (
set()
if bypass_access_control
else {group.id for group in await Groups.get_groups_by_member_id(user.id, db=db)}
set() if bypass_access_control else {group.id for group in await Groups.get_groups_by_member_id(user.id, db=db)}
)
tools = await Tools.get_tools(
defer_content=True,
+1 -5
View File
@@ -103,11 +103,7 @@ else:
# Timeout duration in seconds
TIMEOUT_DURATION = 3
SESSION_POOL_TIMEOUT = (
max(WEBSOCKET_HEARTBEAT_INTERVAL * 4, 120)
if WEBSOCKET_HEARTBEAT_INTERVAL is not None
else 120
)
SESSION_POOL_TIMEOUT = max(WEBSOCKET_HEARTBEAT_INTERVAL * 4, 120) if WEBSOCKET_HEARTBEAT_INTERVAL is not None else 120
# Dictionary to maintain the user pool
+1 -3
View File
@@ -1559,9 +1559,7 @@ async def search_chats(
start = max(0, idx - 50)
end = min(len(content), idx + len(needle) + 100)
snippet = (
('...' if start > 0 else '')
+ content[start:end]
+ ('...' if end < len(content) else '')
('...' if start > 0 else '') + content[start:end] + ('...' if end < len(content) else '')
)
break
if snippet:
+1 -5
View File
@@ -1990,11 +1990,7 @@ async def chat_completion_files_handler(
__event_emitter__ = extra_params['__event_emitter__']
sources = []
files = [
item
for item in (body.get('metadata', {}).get('files', None) or [])
if item.get('type') != 'filesystem'
]
files = [item for item in (body.get('metadata', {}).get('files', None) or []) if item.get('type') != 'filesystem']
if files:
# Check if all files are in full context mode
all_full_context = all(item.get('context') == 'full' for item in files)
+1 -3
View File
@@ -318,9 +318,7 @@ def get_reasoning_details(payload: dict):
return None
provider_fields = payload.get('provider_specific_fields') or {}
provider_details = (
provider_fields.get('reasoning_details') if isinstance(provider_fields, dict) else None
)
provider_details = provider_fields.get('reasoning_details') if isinstance(provider_fields, dict) else None
return payload.get('reasoning_details') or provider_details
+1 -5
View File
@@ -2320,11 +2320,7 @@ class OAuthManager:
raise jwt.InvalidTokenError(str(e))
signing_key = next(
(
key
for key in jwk_set.keys
if key.key_id == token_kid and key.public_key_use in ['sig', None]
),
(key for key in jwk_set.keys if key.key_id == token_kid and key.public_key_use in ['sig', None]),
None,
)
if not signing_key:
+1 -4
View File
@@ -339,10 +339,7 @@ async def delegate(
for file in metadata.get('files') or []
if str(file.get('id') or '') in requested_file_ids
or str(file.get('url') or '') in requested_file_ids
or (
isinstance(file.get('file'), dict)
and str(file.get('file', {}).get('id') or '') in requested_file_ids
)
or (isinstance(file.get('file'), dict) and str(file.get('file', {}).get('id') or '') in requested_file_ids)
]
found_file_ids = {
str(value)
+1 -2
View File
@@ -43,8 +43,7 @@ async def resolve_tool_call_output(
(
item
for item in output
if item.get('type') == 'function_call'
and (item.get('call_id') or item.get('id')) == form_data.call_id
if item.get('type') == 'function_call' and (item.get('call_id') or item.get('id')) == form_data.call_id
),
None,
)
+6 -11
View File
@@ -954,10 +954,10 @@ def add_terminal_display_file_inline_param(spec: dict) -> dict:
return spec
spec['description'] = (
f"{spec.get('description', '')} "
"Set inline=true when the file should be shown inline in the chat message instead of opening the file viewer. "
"Set page for PDF, DOCX, and PPTX files when you want the preview to open at a specific 1-based page or slide. "
"After display_file succeeds, do not display the same file again or emit Markdown for it."
f'{spec.get("description", "")} '
'Set inline=true when the file should be shown inline in the chat message instead of opening the file viewer. '
'Set page for PDF, DOCX, and PPTX files when you want the preview to open at a specific 1-based page or slide. '
'After display_file succeeds, do not display the same file again or emit Markdown for it.'
).strip()
parameters = spec.setdefault('parameters', {'type': 'object', 'properties': {}, 'required': []})
parameters.setdefault('type', 'object')
@@ -1411,11 +1411,7 @@ async def get_terminal_tools(
context_id = terminal_context_id(connection, metadata, terminal_context)
config = terminal_context_config(connection, terminal_context)
if (
isinstance(config, dict)
and config.get('context_id') in {'chat_id', 'automation_id'}
and not context_id
):
if isinstance(config, dict) and config.get('context_id') in {'chat_id', 'automation_id'} and not context_id:
raise RuntimeError(f"Terminal server '{terminal_id}' requires a saved {terminal_context} context")
if context_id:
headers[TERMINAL_CONTEXT_HEADER] = context_id
@@ -1586,8 +1582,7 @@ async def get_tool_servers_data(servers: list[dict[str, Any]]) -> list[dict[str,
'openapi': response,
'info': response.get('info', {}),
'specs': [
add_terminal_display_file_inline_param(spec)
for spec in convert_openapi_to_tool_payload(response)
add_terminal_display_file_inline_param(spec) for spec in convert_openapi_to_tool_payload(response)
],
}