mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-17 04:34:13 +00:00
chore: format
This commit is contained in:
parent
b1d3cb4a3b
commit
4b81b12ed4
5 changed files with 35 additions and 14 deletions
|
|
@ -1318,9 +1318,7 @@ class ChatTable:
|
|||
chat.current_message_id = history['currentId']
|
||||
chat.updated_at = int(time.time())
|
||||
for mid, message in turn.items():
|
||||
await ChatMessages.upsert_message(
|
||||
mid, chat_id, message.get('user_id') or chat.user_id, message, db=db
|
||||
)
|
||||
await ChatMessages.upsert_message(mid, chat_id, message.get('user_id') or chat.user_id, message, db=db)
|
||||
if parent_id:
|
||||
turn[parent_id] = history['messages'][parent_id]
|
||||
return {'messages': turn, 'currentId': history['currentId']}
|
||||
|
|
|
|||
|
|
@ -422,20 +422,38 @@ class MessageTable:
|
|||
stmt = select(Message).filter_by(channel_id=channel_id, parent_id=parent_id)
|
||||
if around or before:
|
||||
anchor = await db.get(Message, before or around)
|
||||
if not anchor or anchor.channel_id != channel_id or (anchor.id != parent_id and anchor.parent_id != parent_id):
|
||||
if (
|
||||
not anchor
|
||||
or anchor.channel_id != channel_id
|
||||
or (anchor.id != parent_id and anchor.parent_id != parent_id)
|
||||
):
|
||||
return []
|
||||
if before:
|
||||
stmt = stmt.where(or_(Message.created_at < anchor.created_at,
|
||||
and_(Message.created_at == anchor.created_at, Message.id < anchor.id)))
|
||||
stmt = stmt.where(
|
||||
or_(
|
||||
Message.created_at < anchor.created_at,
|
||||
and_(Message.created_at == anchor.created_at, Message.id < anchor.id),
|
||||
)
|
||||
)
|
||||
skip = 0
|
||||
else:
|
||||
# A bounded window starts just above the match, even in very old threads.
|
||||
newer = select(func.count()).select_from(Message).where(
|
||||
Message.channel_id == channel_id, Message.parent_id == parent_id,
|
||||
or_(Message.created_at > anchor.created_at,
|
||||
and_(Message.created_at == anchor.created_at, Message.id > anchor.id)))
|
||||
newer = (
|
||||
select(func.count())
|
||||
.select_from(Message)
|
||||
.where(
|
||||
Message.channel_id == channel_id,
|
||||
Message.parent_id == parent_id,
|
||||
or_(
|
||||
Message.created_at > anchor.created_at,
|
||||
and_(Message.created_at == anchor.created_at, Message.id > anchor.id),
|
||||
),
|
||||
)
|
||||
)
|
||||
skip = max(0, (await db.scalar(newer)) - 10)
|
||||
result = await db.execute(stmt.order_by(Message.created_at.desc(), Message.id.desc()).offset(skip).limit(limit))
|
||||
result = await db.execute(
|
||||
stmt.order_by(Message.created_at.desc(), Message.id.desc()).offset(skip).limit(limit)
|
||||
)
|
||||
all_messages = list(result.scalars().all())
|
||||
|
||||
# If length of all_messages is less than limit, then add the parent message
|
||||
|
|
|
|||
|
|
@ -1702,7 +1702,9 @@ async def get_channel_thread_messages(
|
|||
if user.role != 'admin' and not await channel_has_access(user.id, channel, permission='read', db=db):
|
||||
raise HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=ERROR_MESSAGES.DEFAULT())
|
||||
|
||||
message_list = await Messages.get_messages_by_parent_id(id, message_id, skip, min(max(limit, 1), 100), db=db, around=around, before=before)
|
||||
message_list = await Messages.get_messages_by_parent_id(
|
||||
id, message_id, skip, min(max(limit, 1), 100), db=db, around=around, before=before
|
||||
)
|
||||
|
||||
if not message_list:
|
||||
return []
|
||||
|
|
|
|||
|
|
@ -122,7 +122,9 @@ for package in sorted(metadata['packages'], key=lambda p: (p['name'], p['version
|
|||
f'Source: https://crates.io/api/v1/crates/{package["name"]}/{package["version"]}/download\n'
|
||||
+ '\n'.join(references)
|
||||
)
|
||||
notices.extend(f'\nLicense and notice text [{number}]\n--------------------------------\n{text}' for text, number in texts.items())
|
||||
notices.extend(
|
||||
f'\nLicense and notice text [{number}]\n--------------------------------\n{text}' for text, number in texts.items()
|
||||
)
|
||||
(OUTPUT / 'THIRD_PARTY_LICENSES.txt').write_text('\n'.join(notices) + '\n')
|
||||
with tempfile.NamedTemporaryFile(mode='w', suffix='.json') as temp:
|
||||
json.dump(metadata, temp)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import JSZip from 'jszip';
|
|||
|
||||
export const elements = (node: Document | Element, name: string): Element[] =>
|
||||
Array.from(node.getElementsByTagNameNS('*', name));
|
||||
export const children = (node: Node): Element[] => Array.from(node.childNodes).filter((n) => n.nodeType === 1) as Element[];
|
||||
export const children = (node: Node): Element[] =>
|
||||
Array.from(node.childNodes).filter((n) => n.nodeType === 1) as Element[];
|
||||
export const attr = (node: Element, name: string) =>
|
||||
Array.from(node.attributes).find((a) => a.localName === name)?.value ?? '';
|
||||
export const text = (node: Element, paragraph = 'p') => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue