mirror of
https://github.com/VectifyAI/PageIndex.git
synced 2026-10-03 16:18:34 +08:00
fix: align local doc_id prefix and createdAt format with the cloud
Local doc ids now carry the cloud's pi- namespace prefix (random token stays uuid4 hex — nothing parses cuid internals, the prefix is the contract; chat ids already mirrored chatcmpl-). createdAt now matches the server byte for byte: the cloud emits the DB datetime's bare isoformat — naive UTC, second precision — while we emitted microseconds plus +00:00.
This commit is contained in:
@@ -58,7 +58,8 @@ CHAT_CONTEXT_TOKEN_LIMIT = 100_000
|
||||
|
||||
|
||||
def _now_iso() -> str:
|
||||
return datetime.now(timezone.utc).isoformat()
|
||||
# Mirror the cloud's createdAt format: naive UTC ISO, second precision.
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None).isoformat(timespec="seconds")
|
||||
|
||||
|
||||
class LocalAPI:
|
||||
@@ -117,7 +118,7 @@ class LocalAPI:
|
||||
except Exception as e:
|
||||
raise PageIndexAPIError(f"Failed to submit document: {e}") from e
|
||||
|
||||
doc_id = str(uuid.uuid4())
|
||||
doc_id = "pi-" + uuid.uuid4().hex
|
||||
meta = {
|
||||
"id": doc_id,
|
||||
"name": os.path.basename(file_path),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
"""SDK surface tests: PageIndexClient in local and cloud mode."""
|
||||
import json
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import types
|
||||
@@ -156,8 +157,10 @@ def test_get_ocr(local_client, indexed_doc):
|
||||
|
||||
|
||||
def test_document_management(local_client, indexed_doc):
|
||||
assert indexed_doc.startswith("pi-")
|
||||
doc = local_client.get_document(indexed_doc)
|
||||
assert doc["id"] == indexed_doc
|
||||
assert re.fullmatch(r"\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}", doc["createdAt"])
|
||||
assert doc["name"] == "sample.pdf"
|
||||
assert doc["description"] == "A test document."
|
||||
assert doc["status"] == "completed"
|
||||
|
||||
Reference in New Issue
Block a user