Fix linting
Browse files
lightrag/api/routers/document_routes.py
CHANGED
@@ -20,13 +20,14 @@ from lightrag.base import DocProcessingStatus, DocStatus
|
|
20 |
from lightrag.api.utils_api import get_combined_auth_dependency
|
21 |
from ..config import global_args
|
22 |
|
|
|
23 |
# Function to format datetime to ISO format string with timezone information
|
24 |
def format_datetime(dt: Any) -> Optional[str]:
|
25 |
"""Format datetime to ISO format string with timezone information
|
26 |
-
|
27 |
Args:
|
28 |
dt: Datetime object, string, or None
|
29 |
-
|
30 |
Returns:
|
31 |
ISO format string with timezone information, or None if input is None
|
32 |
"""
|
@@ -34,16 +35,17 @@ def format_datetime(dt: Any) -> Optional[str]:
|
|
34 |
return None
|
35 |
if isinstance(dt, str):
|
36 |
return dt
|
37 |
-
|
38 |
# Check if datetime object has timezone information
|
39 |
if isinstance(dt, datetime):
|
40 |
# If datetime object has no timezone info (naive datetime), add UTC timezone
|
41 |
if dt.tzinfo is None:
|
42 |
dt = dt.replace(tzinfo=timezone.utc)
|
43 |
-
|
44 |
# Return ISO format string with timezone information
|
45 |
return dt.isoformat()
|
46 |
|
|
|
47 |
router = APIRouter(
|
48 |
prefix="/documents",
|
49 |
tags=["documents"],
|
@@ -338,7 +340,7 @@ class PipelineStatusResponse(BaseModel):
|
|
338 |
history_messages: Optional[List[str]] = None
|
339 |
update_status: Optional[dict] = None
|
340 |
|
341 |
-
@field_validator(
|
342 |
@classmethod
|
343 |
def parse_job_start(cls, value):
|
344 |
"""Process datetime and return as ISO format string with timezone"""
|
@@ -1263,12 +1265,8 @@ def create_document_routes(
|
|
1263 |
content_summary=doc_status.content_summary,
|
1264 |
content_length=doc_status.content_length,
|
1265 |
status=doc_status.status,
|
1266 |
-
created_at=format_datetime(
|
1267 |
-
|
1268 |
-
),
|
1269 |
-
updated_at=format_datetime(
|
1270 |
-
doc_status.updated_at
|
1271 |
-
),
|
1272 |
chunks_count=doc_status.chunks_count,
|
1273 |
error=doc_status.error,
|
1274 |
metadata=doc_status.metadata,
|
|
|
20 |
from lightrag.api.utils_api import get_combined_auth_dependency
|
21 |
from ..config import global_args
|
22 |
|
23 |
+
|
24 |
# Function to format datetime to ISO format string with timezone information
|
25 |
def format_datetime(dt: Any) -> Optional[str]:
|
26 |
"""Format datetime to ISO format string with timezone information
|
27 |
+
|
28 |
Args:
|
29 |
dt: Datetime object, string, or None
|
30 |
+
|
31 |
Returns:
|
32 |
ISO format string with timezone information, or None if input is None
|
33 |
"""
|
|
|
35 |
return None
|
36 |
if isinstance(dt, str):
|
37 |
return dt
|
38 |
+
|
39 |
# Check if datetime object has timezone information
|
40 |
if isinstance(dt, datetime):
|
41 |
# If datetime object has no timezone info (naive datetime), add UTC timezone
|
42 |
if dt.tzinfo is None:
|
43 |
dt = dt.replace(tzinfo=timezone.utc)
|
44 |
+
|
45 |
# Return ISO format string with timezone information
|
46 |
return dt.isoformat()
|
47 |
|
48 |
+
|
49 |
router = APIRouter(
|
50 |
prefix="/documents",
|
51 |
tags=["documents"],
|
|
|
340 |
history_messages: Optional[List[str]] = None
|
341 |
update_status: Optional[dict] = None
|
342 |
|
343 |
+
@field_validator("job_start", mode="before")
|
344 |
@classmethod
|
345 |
def parse_job_start(cls, value):
|
346 |
"""Process datetime and return as ISO format string with timezone"""
|
|
|
1265 |
content_summary=doc_status.content_summary,
|
1266 |
content_length=doc_status.content_length,
|
1267 |
status=doc_status.status,
|
1268 |
+
created_at=format_datetime(doc_status.created_at),
|
1269 |
+
updated_at=format_datetime(doc_status.updated_at),
|
|
|
|
|
|
|
|
|
1270 |
chunks_count=doc_status.chunks_count,
|
1271 |
error=doc_status.error,
|
1272 |
metadata=doc_status.metadata,
|
lightrag/kg/postgres_impl.py
CHANGED
@@ -1028,7 +1028,7 @@ class PGDocStatusStorage(DocStatusStorage):
|
|
1028 |
# Remove timezone information, store utc time in db
|
1029 |
created_at = parse_datetime(v.get("created_at"))
|
1030 |
updated_at = parse_datetime(v.get("updated_at"))
|
1031 |
-
|
1032 |
# chunks_count is optional
|
1033 |
await self.db.execute(
|
1034 |
sql,
|
|
|
1028 |
# Remove timezone information, store utc time in db
|
1029 |
created_at = parse_datetime(v.get("created_at"))
|
1030 |
updated_at = parse_datetime(v.get("updated_at"))
|
1031 |
+
|
1032 |
# chunks_count is optional
|
1033 |
await self.db.execute(
|
1034 |
sql,
|
lightrag/lightrag.py
CHANGED
@@ -958,7 +958,9 @@ class LightRAG:
|
|
958 |
"content_summary": status_doc.content_summary,
|
959 |
"content_length": status_doc.content_length,
|
960 |
"created_at": status_doc.created_at,
|
961 |
-
"updated_at": datetime.now(
|
|
|
|
|
962 |
"file_path": file_path,
|
963 |
}
|
964 |
}
|
@@ -1018,7 +1020,9 @@ class LightRAG:
|
|
1018 |
"content_summary": status_doc.content_summary,
|
1019 |
"content_length": status_doc.content_length,
|
1020 |
"created_at": status_doc.created_at,
|
1021 |
-
"updated_at": datetime.now(
|
|
|
|
|
1022 |
"file_path": file_path,
|
1023 |
}
|
1024 |
}
|
@@ -1053,7 +1057,9 @@ class LightRAG:
|
|
1053 |
"content_summary": status_doc.content_summary,
|
1054 |
"content_length": status_doc.content_length,
|
1055 |
"created_at": status_doc.created_at,
|
1056 |
-
"updated_at": datetime.now(
|
|
|
|
|
1057 |
"file_path": file_path,
|
1058 |
}
|
1059 |
}
|
|
|
958 |
"content_summary": status_doc.content_summary,
|
959 |
"content_length": status_doc.content_length,
|
960 |
"created_at": status_doc.created_at,
|
961 |
+
"updated_at": datetime.now(
|
962 |
+
timezone.utc
|
963 |
+
).isoformat(),
|
964 |
"file_path": file_path,
|
965 |
}
|
966 |
}
|
|
|
1020 |
"content_summary": status_doc.content_summary,
|
1021 |
"content_length": status_doc.content_length,
|
1022 |
"created_at": status_doc.created_at,
|
1023 |
+
"updated_at": datetime.now(
|
1024 |
+
timezone.utc
|
1025 |
+
).isoformat(),
|
1026 |
"file_path": file_path,
|
1027 |
}
|
1028 |
}
|
|
|
1057 |
"content_summary": status_doc.content_summary,
|
1058 |
"content_length": status_doc.content_length,
|
1059 |
"created_at": status_doc.created_at,
|
1060 |
+
"updated_at": datetime.now(
|
1061 |
+
timezone.utc
|
1062 |
+
).isoformat(),
|
1063 |
"file_path": file_path,
|
1064 |
}
|
1065 |
}
|
lightrag_webui/src/components/documents/PipelineStatusDialog.tsx
CHANGED
@@ -158,7 +158,7 @@ export default function PipelineStatusDialog({
|
|
158 |
<div className="rounded-md border p-3 space-y-2">
|
159 |
<div>{t('documentPanel.pipelineStatus.jobName')}: {status?.job_name || '-'}</div>
|
160 |
<div className="flex justify-between">
|
161 |
-
<span>{t('documentPanel.pipelineStatus.startTime')}: {status?.job_start
|
162 |
? new Date(status.job_start).toLocaleString(undefined, {
|
163 |
year: 'numeric',
|
164 |
month: 'numeric',
|
@@ -166,7 +166,7 @@ export default function PipelineStatusDialog({
|
|
166 |
hour: 'numeric',
|
167 |
minute: 'numeric',
|
168 |
second: 'numeric'
|
169 |
-
})
|
170 |
: '-'}</span>
|
171 |
<span>{t('documentPanel.pipelineStatus.progress')}: {status ? `${status.cur_batch}/${status.batchs} ${t('documentPanel.pipelineStatus.unit')}` : '-'}</span>
|
172 |
</div>
|
|
|
158 |
<div className="rounded-md border p-3 space-y-2">
|
159 |
<div>{t('documentPanel.pipelineStatus.jobName')}: {status?.job_name || '-'}</div>
|
160 |
<div className="flex justify-between">
|
161 |
+
<span>{t('documentPanel.pipelineStatus.startTime')}: {status?.job_start
|
162 |
? new Date(status.job_start).toLocaleString(undefined, {
|
163 |
year: 'numeric',
|
164 |
month: 'numeric',
|
|
|
166 |
hour: 'numeric',
|
167 |
minute: 'numeric',
|
168 |
second: 'numeric'
|
169 |
+
})
|
170 |
: '-'}</span>
|
171 |
<span>{t('documentPanel.pipelineStatus.progress')}: {status ? `${status.cur_batch}/${status.batchs} ${t('documentPanel.pipelineStatus.unit')}` : '-'}</span>
|
172 |
</div>
|