mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-05-01 05:00:13 +00:00
enhance: grouped project History api PR644
This commit is contained in:
parent
53726f12fe
commit
4829445211
1 changed files with 7 additions and 5 deletions
|
|
@ -1,7 +1,7 @@
|
|||
from fastapi import APIRouter, Depends, HTTPException, Response, Query
|
||||
from fastapi_pagination import Page
|
||||
from fastapi_pagination.ext.sqlmodel import paginate
|
||||
from app.model.chat.chat_history import ChatHistoryOut, ChatHistoryIn, ChatHistory, ChatHistoryUpdate
|
||||
from app.model.chat.chat_history import ChatHistoryOut, ChatHistoryIn, ChatHistory, ChatHistoryUpdate, ChatStatus
|
||||
from app.model.chat.chat_history_grouped import ProjectGroup, GroupedHistoryResponse
|
||||
from fastapi_babel import _
|
||||
from sqlmodel import Session, select, desc, case
|
||||
|
|
@ -120,10 +120,12 @@ def list_grouped_chat_history(
|
|||
project_data['task_count'] += 1
|
||||
project_data['total_tokens'] += history.tokens or 0
|
||||
|
||||
# Count completed and failed tasks (assuming status 1 = completed, others = failed/ongoing)
|
||||
if history.status == 1: # ChatStatus.done
|
||||
# Count completed and failed tasks
|
||||
# ChatStatus.ongoing = 1, ChatStatus.done = 2
|
||||
if history.status == ChatStatus.done:
|
||||
project_data['total_completed_tasks'] += 1
|
||||
else: # Not ongoing, assume failed
|
||||
elif history.status != ChatStatus.ongoing:
|
||||
# Only count as failed if not ongoing and not done
|
||||
project_data['total_failed_tasks'] += 1
|
||||
|
||||
# Update latest task date and last prompt
|
||||
|
|
@ -138,7 +140,7 @@ def list_grouped_chat_history(
|
|||
for project_data in project_map.values():
|
||||
# Sort tasks within each project by creation date (oldest first)
|
||||
if include_tasks:
|
||||
project_data['tasks'].sort(key=lambda x: x.created_at or '', reverse=False)
|
||||
project_data['tasks'].sort(key=lambda x: (x.created_at is None, x.created_at or ''), reverse=False)
|
||||
|
||||
project_group = ProjectGroup(**project_data)
|
||||
projects.append(project_group)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue