chore: format

This commit is contained in:
Timothy Jaeryang Baek
2026-07-20 22:11:42 -04:00
parent 4a42543fc3
commit 49e57f4e7e
16 changed files with 44 additions and 60 deletions
@@ -254,8 +254,7 @@ async def filter_allowed_access_grants(
access_grants = strip_user_access_grants(access_grants)
if any(
(grant.get('principal_type') if isinstance(grant, dict) else getattr(grant, 'principal_type', None))
== 'group'
(grant.get('principal_type') if isinstance(grant, dict) else getattr(grant, 'principal_type', None)) == 'group'
for grant in access_grants
) and not await has_permission(
user_id,
+2 -6
View File
@@ -467,9 +467,7 @@ def convert_openai_to_anthropic_response(
}
async def openai_stream_to_anthropic_stream(
openai_stream_generator, model: str = '', input_tokens: int = 0
):
async def openai_stream_to_anthropic_stream(openai_stream_generator, model: str = '', input_tokens: int = 0):
"""
Convert an OpenAI SSE streaming response to Anthropic Messages SSE format.
@@ -560,9 +558,7 @@ async def openai_stream_to_anthropic_stream(
# Update usage if present
if data.get('usage'):
input_tokens = data['usage'].get(
'input_tokens', data['usage'].get('prompt_tokens', input_tokens)
)
input_tokens = data['usage'].get('input_tokens', data['usage'].get('prompt_tokens', input_tokens))
output_tokens = data['usage'].get(
'output_tokens', data['usage'].get('completion_tokens', output_tokens)
)
@@ -240,9 +240,7 @@ async def get_chat_context_usage(chat: Any, model_id: str | None = None) -> dict
usage = messages[idx].get('usage') or (messages[idx].get('info') or {}).get('usage')
input_tokens = (usage or {}).get('input_tokens') or (usage or {}).get('prompt_tokens')
if isinstance(usage, dict) and input_tokens:
tokens = int(input_tokens or 0) + int(
usage.get('output_tokens') or usage.get('completion_tokens') or 0
)
tokens = int(input_tokens or 0) + int(usage.get('output_tokens') or usage.get('completion_tokens') or 0)
tokens += _estimate_messages_tokens(messages[idx + 1 :])
return _build_context_usage(tokens, threshold)
+4 -9
View File
@@ -110,10 +110,7 @@ async def process_pending_internal_messages(
and meta.get('type') == 'subagent'
and meta.get('status') in (None, 'pending')
)
or (
meta.get('internal') is True
and meta.get('type') == 'timer'
)
or (meta.get('internal') is True and meta.get('type') == 'timer')
)
]
if not pending:
@@ -137,11 +134,9 @@ async def process_pending_internal_messages(
if message.get('parentId') == parent_id
and (message.get('model') or model_id) == model_id
and (
(
meta.get('internal') is True
and meta.get('type') == 'subagent'
and meta.get('status') in (None, 'pending')
)
meta.get('internal') is True
and meta.get('type') == 'subagent'
and meta.get('status') in (None, 'pending')
)
]
combined_content = '\n\n'.join(message.get('content', '') for message in batch if message.get('content'))
+5 -11
View File
@@ -25,8 +25,8 @@ from open_webui.utils.misc import get_message_list
log = logging.getLogger(__name__)
_RELATIVE_TIME = re.compile(r"^(?:\+|in\s+)?(\d+)\s*(s|sec(?:onds?)?|m|min(?:utes?)?|h|hours?|d|days?)$")
_RFC3339_TIME = re.compile(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$")
_RELATIVE_TIME = re.compile(r'^(?:\+|in\s+)?(\d+)\s*(s|sec(?:onds?)?|m|min(?:utes?)?|h|hours?|d|days?)$')
_RFC3339_TIME = re.compile(r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|[+-]\d{2}:\d{2})$')
_TIME_UNITS_NS = {
's': 1_000_000_000,
'm': 60 * 1_000_000_000,
@@ -49,15 +49,13 @@ def parse_timer_at(value: str) -> int:
if not _RFC3339_TIME.fullmatch(raw):
raise ValueError(
'at must be a relative time such as 10s or in 10 seconds, '
'or an RFC 3339 timestamp with a timezone.'
'at must be a relative time such as 10s or in 10 seconds, or an RFC 3339 timestamp with a timezone.'
)
try:
parsed = datetime.fromisoformat(raw.replace('Z', '+00:00'))
except ValueError as exc:
raise ValueError(
'at must be a relative time such as 10s or in 10 seconds, '
'or an RFC 3339 timestamp with a timezone.'
'at must be a relative time such as 10s or in 10 seconds, or an RFC 3339 timestamp with a timezone.'
) from exc
if parsed.tzinfo is None or parsed.utcoffset() is None:
raise ValueError('absolute at values must include an explicit timezone.')
@@ -182,11 +180,7 @@ async def claim_due_timers(now_ns: int, limit: int = 10) -> list[tuple[str, str]
stmt = stmt.with_for_update(skip_locked=True)
result = await db.execute(stmt)
rows = [
row
for row in result.scalars().all()
if int((row.meta or {}).get('timer_at') or 0) <= now_ns
]
rows = [row for row in result.scalars().all() if int((row.meta or {}).get('timer_at') or 0) <= now_ns]
rows.sort(key=lambda row: int((row.meta or {}).get('timer_at') or 0))
rows = rows[:limit]