Fix linting

This commit is contained in:
yangdx
2025-05-01 10:04:31 +08:00
parent 950d42c527
commit 36f8787bc7
4 changed files with 21 additions and 17 deletions

View File

@@ -20,13 +20,14 @@ from lightrag.base import DocProcessingStatus, DocStatus
from lightrag.api.utils_api import get_combined_auth_dependency from lightrag.api.utils_api import get_combined_auth_dependency
from ..config import global_args from ..config import global_args
# Function to format datetime to ISO format string with timezone information # Function to format datetime to ISO format string with timezone information
def format_datetime(dt: Any) -> Optional[str]: def format_datetime(dt: Any) -> Optional[str]:
"""Format datetime to ISO format string with timezone information """Format datetime to ISO format string with timezone information
Args: Args:
dt: Datetime object, string, or None dt: Datetime object, string, or None
Returns: Returns:
ISO format string with timezone information, or None if input is None ISO format string with timezone information, or None if input is None
""" """
@@ -34,16 +35,17 @@ def format_datetime(dt: Any) -> Optional[str]:
return None return None
if isinstance(dt, str): if isinstance(dt, str):
return dt return dt
# Check if datetime object has timezone information # Check if datetime object has timezone information
if isinstance(dt, datetime): if isinstance(dt, datetime):
# If datetime object has no timezone info (naive datetime), add UTC timezone # If datetime object has no timezone info (naive datetime), add UTC timezone
if dt.tzinfo is None: if dt.tzinfo is None:
dt = dt.replace(tzinfo=timezone.utc) dt = dt.replace(tzinfo=timezone.utc)
# Return ISO format string with timezone information # Return ISO format string with timezone information
return dt.isoformat() return dt.isoformat()
router = APIRouter( router = APIRouter(
prefix="/documents", prefix="/documents",
tags=["documents"], tags=["documents"],
@@ -338,7 +340,7 @@ class PipelineStatusResponse(BaseModel):
history_messages: Optional[List[str]] = None history_messages: Optional[List[str]] = None
update_status: Optional[dict] = None update_status: Optional[dict] = None
@field_validator('job_start', mode='before') @field_validator("job_start", mode="before")
@classmethod @classmethod
def parse_job_start(cls, value): def parse_job_start(cls, value):
"""Process datetime and return as ISO format string with timezone""" """Process datetime and return as ISO format string with timezone"""
@@ -1263,12 +1265,8 @@ def create_document_routes(
content_summary=doc_status.content_summary, content_summary=doc_status.content_summary,
content_length=doc_status.content_length, content_length=doc_status.content_length,
status=doc_status.status, status=doc_status.status,
created_at=format_datetime( created_at=format_datetime(doc_status.created_at),
doc_status.created_at updated_at=format_datetime(doc_status.updated_at),
),
updated_at=format_datetime(
doc_status.updated_at
),
chunks_count=doc_status.chunks_count, chunks_count=doc_status.chunks_count,
error=doc_status.error, error=doc_status.error,
metadata=doc_status.metadata, metadata=doc_status.metadata,

View File

@@ -1028,7 +1028,7 @@ class PGDocStatusStorage(DocStatusStorage):
# Remove timezone information, store utc time in db # Remove timezone information, store utc time in db
created_at = parse_datetime(v.get("created_at")) created_at = parse_datetime(v.get("created_at"))
updated_at = parse_datetime(v.get("updated_at")) updated_at = parse_datetime(v.get("updated_at"))
# chunks_count is optional # chunks_count is optional
await self.db.execute( await self.db.execute(
sql, sql,

View File

@@ -958,7 +958,9 @@ class LightRAG:
"content_summary": status_doc.content_summary, "content_summary": status_doc.content_summary,
"content_length": status_doc.content_length, "content_length": status_doc.content_length,
"created_at": status_doc.created_at, "created_at": status_doc.created_at,
"updated_at": datetime.now(timezone.utc).isoformat(), "updated_at": datetime.now(
timezone.utc
).isoformat(),
"file_path": file_path, "file_path": file_path,
} }
} }
@@ -1018,7 +1020,9 @@ class LightRAG:
"content_summary": status_doc.content_summary, "content_summary": status_doc.content_summary,
"content_length": status_doc.content_length, "content_length": status_doc.content_length,
"created_at": status_doc.created_at, "created_at": status_doc.created_at,
"updated_at": datetime.now(timezone.utc).isoformat(), "updated_at": datetime.now(
timezone.utc
).isoformat(),
"file_path": file_path, "file_path": file_path,
} }
} }
@@ -1053,7 +1057,9 @@ class LightRAG:
"content_summary": status_doc.content_summary, "content_summary": status_doc.content_summary,
"content_length": status_doc.content_length, "content_length": status_doc.content_length,
"created_at": status_doc.created_at, "created_at": status_doc.created_at,
"updated_at": datetime.now(timezone.utc).isoformat(), "updated_at": datetime.now(
timezone.utc
).isoformat(),
"file_path": file_path, "file_path": file_path,
} }
} }

View File

@@ -158,7 +158,7 @@ export default function PipelineStatusDialog({
<div className="rounded-md border p-3 space-y-2"> <div className="rounded-md border p-3 space-y-2">
<div>{t('documentPanel.pipelineStatus.jobName')}: {status?.job_name || '-'}</div> <div>{t('documentPanel.pipelineStatus.jobName')}: {status?.job_name || '-'}</div>
<div className="flex justify-between"> <div className="flex justify-between">
<span>{t('documentPanel.pipelineStatus.startTime')}: {status?.job_start <span>{t('documentPanel.pipelineStatus.startTime')}: {status?.job_start
? new Date(status.job_start).toLocaleString(undefined, { ? new Date(status.job_start).toLocaleString(undefined, {
year: 'numeric', year: 'numeric',
month: 'numeric', month: 'numeric',
@@ -166,7 +166,7 @@ export default function PipelineStatusDialog({
hour: 'numeric', hour: 'numeric',
minute: 'numeric', minute: 'numeric',
second: 'numeric' second: 'numeric'
}) })
: '-'}</span> : '-'}</span>
<span>{t('documentPanel.pipelineStatus.progress')}: {status ? `${status.cur_batch}/${status.batchs} ${t('documentPanel.pipelineStatus.unit')}` : '-'}</span> <span>{t('documentPanel.pipelineStatus.progress')}: {status ? `${status.cur_batch}/${status.batchs} ${t('documentPanel.pipelineStatus.unit')}` : '-'}</span>
</div> </div>