refac
Some checks are pending
Create and publish Docker images with specific build args / build-main-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-main-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda126-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-cuda126-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / build-slim-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-slim-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / merge-main-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-cuda-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-ollama-images (push) Blocked by required conditions
Create and publish Docker images with specific build args / merge-slim-images (push) Blocked by required conditions
Python CI / Format Backend (push) Waiting to run
Deploy to HuggingFace Spaces / check-secret (push) Waiting to run
Deploy to HuggingFace Spaces / deploy (push) Blocked by required conditions
Create and publish Docker images with specific build args / build-ollama-image (linux/amd64, ubuntu-latest) (push) Waiting to run
Create and publish Docker images with specific build args / build-ollama-image (linux/arm64, ubuntu-24.04-arm) (push) Waiting to run
Create and publish Docker images with specific build args / merge-cuda126-images (push) Blocked by required conditions

This commit is contained in:
Timothy Jaeryang Baek 2025-12-27 01:41:06 +04:00
parent ac0ae2ae20
commit a9609585af

View file

@ -222,6 +222,18 @@ def calculate_chat_stats(user_id, skip=0, limit=10, filter=None):
chat_stats_export_list = [] chat_stats_export_list = []
def get_message_content_length(message):
content = message.get("content", "")
if isinstance(content, str):
return len(content)
elif isinstance(content, list):
return sum(
len(item.get("text", ""))
for item in content
if item.get("type") == "text"
)
return 0
for chat in result.items: for chat in result.items:
try: try:
messages_map = chat.chat.get("history", {}).get("messages", {}) messages_map = chat.chat.get("history", {}).get("messages", {})
@ -235,13 +247,7 @@ def calculate_chat_stats(user_id, skip=0, limit=10, filter=None):
export_messages = {} export_messages = {}
for key, message in messages_map.items(): for key, message in messages_map.items():
try: try:
content = message.get("content", "") content_length = get_message_content_length(message)
if isinstance(content, str):
content_length = len(content)
else:
content_length = (
0 # Handle cases where content might be None or not string
)
# Extract rating safely # Extract rating safely
rating = message.get("annotation", {}).get("rating") rating = message.get("annotation", {}).get("rating")
@ -277,22 +283,14 @@ def calculate_chat_stats(user_id, skip=0, limit=10, filter=None):
# Calculate Averages # Calculate Averages
average_user_message_content_length = ( average_user_message_content_length = (
sum( sum(get_message_content_length(m) for m in history_user_messages)
len(m.get("content", ""))
for m in history_user_messages
if isinstance(m.get("content"), str)
)
/ len(history_user_messages) / len(history_user_messages)
if history_user_messages if history_user_messages
else 0 else 0
) )
average_assistant_message_content_length = ( average_assistant_message_content_length = (
sum( sum(get_message_content_length(m) for m in history_assistant_messages)
len(m.get("content", ""))
for m in history_assistant_messages
if isinstance(m.get("content"), str)
)
/ len(history_assistant_messages) / len(history_assistant_messages)
if history_assistant_messages if history_assistant_messages
else 0 else 0