mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-08-20 12:00:32 +08:00
Add leaderboard stats, periodic updates via fastapi-utils (#724)
* add leaderboard stats, periodic update via fastapi-utils * count label tasks for assistant and prompter replies * Daily stats update every 15 mins, simplify leaderboard endpoint * add indices for some created_date columns * make user stats update intervals configurable * make sure intervals are positive
This commit is contained in:
@@ -169,6 +169,8 @@ class RankConversationRepliesTask(Task):
|
||||
conversation: Conversation # the conversation so far
|
||||
replies: list[str] # deprecated, use reply_messages
|
||||
reply_messages: list[ConversationMessage]
|
||||
message_tree_id: UUID
|
||||
ranking_parent_id: UUID
|
||||
|
||||
|
||||
class RankPrompterRepliesTask(RankConversationRepliesTask):
|
||||
@@ -356,14 +358,40 @@ class SystemStats(BaseModel):
|
||||
|
||||
|
||||
class UserScore(BaseModel):
|
||||
ranking: int
|
||||
user_rank: int
|
||||
user_id: UUID
|
||||
username: str
|
||||
auth_method: str
|
||||
display_name: str
|
||||
score: int
|
||||
|
||||
leader_score: int
|
||||
|
||||
base_date: Optional[datetime]
|
||||
modified_date: datetime
|
||||
|
||||
prompts: int
|
||||
replies_assistant: int
|
||||
replies_prompter: int
|
||||
labels_simple: int
|
||||
labels_full: int
|
||||
rankings_total: int
|
||||
rankings_good: int
|
||||
|
||||
accepted_prompts: int
|
||||
accepted_replies_assistant: int
|
||||
accepted_replies_prompter: int
|
||||
|
||||
reply_ranked_1: int
|
||||
reply_ranked_2: int
|
||||
reply_ranked_3: int
|
||||
|
||||
# only used for time frame "total"
|
||||
streak_last_day_date: Optional[datetime]
|
||||
streak_days: Optional[int]
|
||||
|
||||
|
||||
class LeaderboardStats(BaseModel):
|
||||
time_frame: str
|
||||
leaderboard: List[UserScore]
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,32 @@
|
||||
import time
|
||||
from datetime import datetime, timezone
|
||||
from functools import wraps
|
||||
|
||||
from loguru import logger
|
||||
|
||||
|
||||
def utcnow() -> datetime:
|
||||
"""Return the current utc date and time with tzinfo set to UTC."""
|
||||
return datetime.now(timezone.utc)
|
||||
|
||||
|
||||
def log_timing(func=None, *, log_kwargs: bool = False, level: int | str = "DEBUG") -> None:
|
||||
def decorator(func):
|
||||
@wraps(func)
|
||||
def wrapped(*args, **kwargs):
|
||||
start = time.time()
|
||||
result = func(*args, **kwargs)
|
||||
end = time.time()
|
||||
elapsed = end - start
|
||||
if log_kwargs:
|
||||
kwargs = ", ".join([f"{k}={v}" for k, v in kwargs.items()])
|
||||
logger.log(level, f"Function '{func.__name__}({kwargs})' executed in {elapsed:f} s")
|
||||
else:
|
||||
logger.log(level, f"Function '{func.__name__}' executed in {elapsed:f} s")
|
||||
return result
|
||||
|
||||
return wrapped
|
||||
|
||||
if func and callable(func):
|
||||
return decorator(func)
|
||||
return decorator
|
||||
|
||||
Reference in New Issue
Block a user