mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-07-20 12:10:50 +08:00
Merge branch 'main' into 766_admin_enhancement
This commit is contained in:
@@ -54,6 +54,7 @@ class PublicSettings(pydantic.BaseModel):
|
||||
|
||||
PROJECT_NAME: str
|
||||
API_V1_STR: str
|
||||
MESSAGE_SIZE_LIMIT: int
|
||||
DEBUG_USE_SEED_DATA: bool
|
||||
DEBUG_ALLOW_SELF_LABELING: bool
|
||||
DEBUG_SKIP_EMBEDDING_COMPUTATION: bool
|
||||
|
||||
@@ -111,7 +111,7 @@ def get_users_cursor(
|
||||
n = lt
|
||||
return p, n
|
||||
|
||||
def remove_extra_item(items: list[protocol.FrontEndUser], lt: str | None, gt: str):
|
||||
def remove_extra_item(items: list[protocol.FrontEndUser], lt: str | None, gt: str | None):
|
||||
num_rows = len(items)
|
||||
if qry_max_count > max_count and num_rows == qry_max_count:
|
||||
assert not (lt and gt)
|
||||
|
||||
@@ -72,6 +72,7 @@ class Settings(BaseSettings):
|
||||
DATABASE_MAX_TX_RETRY_COUNT: int = 3
|
||||
|
||||
RATE_LIMIT: bool = True
|
||||
MESSAGE_SIZE_LIMIT: int = 2000
|
||||
REDIS_HOST: str = "localhost"
|
||||
REDIS_PORT: str = "6379"
|
||||
|
||||
|
||||
@@ -465,6 +465,13 @@ class TreeManager:
|
||||
f"Frontend reports text reply to {interaction.message_id=} with {interaction.text=} by {interaction.user=}."
|
||||
)
|
||||
|
||||
# ensure message size is below the predefined limit
|
||||
if len(interaction.text) > settings.MESSAGE_SIZE_LIMIT:
|
||||
logger.error(
|
||||
f"Message size {len(interaction.text)=} exceeds size limit of {settings.MESSAGE_SIZE_LIMIT=}."
|
||||
)
|
||||
raise OasstError("Message size too long.", OasstErrorCode.TASK_MESSAGE_TOO_LONG)
|
||||
|
||||
# here we store the text reply in the database
|
||||
message = pr.store_text_reply(
|
||||
text=interaction.text,
|
||||
|
||||
@@ -153,7 +153,7 @@ class UserRepository:
|
||||
if api_client_id != self.api_client.id:
|
||||
raise OasstError("Forbidden", OasstErrorCode.API_CLIENT_NOT_AUTHORIZED, HTTP_403_FORBIDDEN)
|
||||
|
||||
qry = self.db.query(User).order_by(User.username, User.id)
|
||||
qry = self.db.query(User)
|
||||
|
||||
if gte_username is not None:
|
||||
if gt_id:
|
||||
@@ -184,8 +184,14 @@ class UserRepository:
|
||||
pattern = "%{}%".format(search_text.replace("\\", "\\\\").replace("_", "\\_").replace("%", "\\%"))
|
||||
qry = qry.filter(User.username.like(pattern))
|
||||
|
||||
if limit is not None:
|
||||
qry = qry.limit(limit)
|
||||
if limit is not None and lte_username and not gte_username:
|
||||
# select top rows but return results in ascernding order
|
||||
sub_qry = qry.order_by(User.username.desc(), User.id.desc()).limit(limit).subquery("u")
|
||||
qry = self.db.query(User).select_entity_from(sub_qry).order_by(User.username, User.id)
|
||||
else:
|
||||
qry = qry.order_by(User.username, User.id)
|
||||
if limit is not None:
|
||||
qry = qry.limit(limit)
|
||||
|
||||
return qry.all()
|
||||
|
||||
@@ -210,7 +216,7 @@ class UserRepository:
|
||||
# Unprivileged api client asks for foreign users
|
||||
raise OasstError("Forbidden", OasstErrorCode.API_CLIENT_NOT_AUTHORIZED, HTTP_403_FORBIDDEN)
|
||||
|
||||
qry = self.db.query(User).order_by(User.display_name, User.id)
|
||||
qry = self.db.query(User)
|
||||
|
||||
if gte_display_name is not None:
|
||||
if gt_id:
|
||||
@@ -254,8 +260,14 @@ class UserRepository:
|
||||
if auth_method:
|
||||
qry = qry.filter(User.auth_method == auth_method)
|
||||
|
||||
if limit is not None:
|
||||
qry = qry.limit(limit)
|
||||
if limit is not None and lte_display_name and not gte_display_name:
|
||||
# select top rows but return results in ascernding order
|
||||
sub_qry = qry.order_by(User.display_name.desc(), User.id.desc()).limit(limit).subquery("u")
|
||||
qry = self.db.query(User).select_entity_from(sub_qry).order_by(User.display_name, User.id)
|
||||
else:
|
||||
qry = qry.order_by(User.display_name, User.id)
|
||||
if limit is not None:
|
||||
qry = qry.limit(limit)
|
||||
|
||||
users = qry.all()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user