lightrag-cli 1.5.9rc1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- lightrag_cli/__init__.py +39 -0
- lightrag_cli/__main__.py +6 -0
- lightrag_cli/_version.py +7 -0
- lightrag_cli/cli.py +763 -0
- lightrag_cli/client.py +585 -0
- lightrag_cli/views.py +165 -0
- lightrag_cli-1.5.9rc1.dist-info/METADATA +36 -0
- lightrag_cli-1.5.9rc1.dist-info/RECORD +11 -0
- lightrag_cli-1.5.9rc1.dist-info/WHEEL +5 -0
- lightrag_cli-1.5.9rc1.dist-info/entry_points.txt +2 -0
- lightrag_cli-1.5.9rc1.dist-info/top_level.txt +1 -0
lightrag_cli/views.py
ADDED
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Compact views of ``lightrag-server`` status responses.
|
|
2
|
+
|
|
3
|
+
Pure functions over the server's JSON: no I/O, no defaults the server does not
|
|
4
|
+
send. A field the server omits (an older server, or ``/health`` answering an
|
|
5
|
+
unauthenticated caller with liveness signals only) comes out as ``None``
|
|
6
|
+
rather than raising, so a view never hides the rest of the answer.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import Any, Mapping
|
|
12
|
+
|
|
13
|
+
# Document statuses that are still moving. A track whose documents are all
|
|
14
|
+
# outside this set is finished (``processed`` / ``failed``, or ``deleting``,
|
|
15
|
+
# which no ingestion wait can outlast).
|
|
16
|
+
ACTIVE_DOC_STATUSES: tuple[str, ...] = ("pending", "parsing", "analyzing", "processing")
|
|
17
|
+
|
|
18
|
+
# Pipeline fields that refuse or delay an enqueue, besides ``busy``.
|
|
19
|
+
_PIPELINE_GATE_FIELDS: tuple[str, ...] = (
|
|
20
|
+
"scanning",
|
|
21
|
+
"scanning_exclusive",
|
|
22
|
+
"destructive_busy",
|
|
23
|
+
"pending_enqueues",
|
|
24
|
+
"cancellation_requested",
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def _mapping(value: Any) -> Mapping[str, Any]:
|
|
29
|
+
return value if isinstance(value, Mapping) else {}
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def pipeline_view(raw: Mapping[str, Any], *, history: int | None = None) -> dict:
|
|
33
|
+
"""Compact ``/documents/pipeline_status``; ``history`` keeps the last N messages."""
|
|
34
|
+
view: dict[str, Any] = {
|
|
35
|
+
"busy": raw.get("busy"),
|
|
36
|
+
"job_name": raw.get("job_name"),
|
|
37
|
+
"job_start": raw.get("job_start"),
|
|
38
|
+
"progress": {
|
|
39
|
+
"cur_batch": raw.get("cur_batch"),
|
|
40
|
+
"batchs": raw.get("batchs"),
|
|
41
|
+
"docs": raw.get("docs"),
|
|
42
|
+
},
|
|
43
|
+
"latest_message": raw.get("latest_message"),
|
|
44
|
+
}
|
|
45
|
+
for key in _PIPELINE_GATE_FIELDS:
|
|
46
|
+
view[key] = raw.get(key)
|
|
47
|
+
view["recovery"] = {
|
|
48
|
+
"required": raw.get("recovery_required"),
|
|
49
|
+
"kind": raw.get("recovery_kind"),
|
|
50
|
+
"message": raw.get("recovery_message"),
|
|
51
|
+
}
|
|
52
|
+
if history:
|
|
53
|
+
messages = raw.get("history_messages") or []
|
|
54
|
+
view["history_messages"] = list(messages)[-history:]
|
|
55
|
+
return view
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
def pipeline_is_idle(raw: Mapping[str, Any]) -> bool:
|
|
59
|
+
"""True when nothing runs and nothing waits to be enqueued."""
|
|
60
|
+
return not (
|
|
61
|
+
raw.get("busy")
|
|
62
|
+
or raw.get("scanning")
|
|
63
|
+
or raw.get("destructive_busy")
|
|
64
|
+
or (raw.get("pending_enqueues") or 0) > 0
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def pipeline_is_fenced(raw: Mapping[str, Any]) -> bool:
|
|
69
|
+
return bool(raw.get("recovery_required"))
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def status_view(
|
|
73
|
+
health: Mapping[str, Any],
|
|
74
|
+
status_counts: Mapping[str, Any],
|
|
75
|
+
pipeline: Mapping[str, Any],
|
|
76
|
+
*,
|
|
77
|
+
client_version: str,
|
|
78
|
+
) -> dict:
|
|
79
|
+
"""Compact server summary from ``/health``, status counts and the pipeline."""
|
|
80
|
+
config = _mapping(health.get("configuration"))
|
|
81
|
+
return {
|
|
82
|
+
"server": {
|
|
83
|
+
"status": health.get("status"),
|
|
84
|
+
"core_version": health.get("core_version"),
|
|
85
|
+
"api_version": health.get("api_version"),
|
|
86
|
+
"client_version": client_version,
|
|
87
|
+
"auth_mode": health.get("auth_mode"),
|
|
88
|
+
# /health returns its configuration to authenticated callers only.
|
|
89
|
+
"authenticated": "configuration" in health,
|
|
90
|
+
"workspace": config.get("workspace"),
|
|
91
|
+
},
|
|
92
|
+
"models": {
|
|
93
|
+
"llm": _binding_model(config, "llm"),
|
|
94
|
+
"embedding": _binding_model(config, "embedding"),
|
|
95
|
+
"rerank": (
|
|
96
|
+
_binding_model(config, "rerank")
|
|
97
|
+
if config.get("enable_rerank")
|
|
98
|
+
else None
|
|
99
|
+
),
|
|
100
|
+
},
|
|
101
|
+
"storage": {
|
|
102
|
+
"kv": config.get("kv_storage"),
|
|
103
|
+
"doc_status": config.get("doc_status_storage"),
|
|
104
|
+
"graph": config.get("graph_storage"),
|
|
105
|
+
"vector": config.get("vector_storage"),
|
|
106
|
+
},
|
|
107
|
+
"documents": dict(_mapping(status_counts.get("status_counts", status_counts))),
|
|
108
|
+
"pipeline": pipeline_view(pipeline),
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _binding_model(config: Mapping[str, Any], prefix: str) -> str | None:
|
|
113
|
+
binding = config.get(f"{prefix}_binding")
|
|
114
|
+
model = config.get(f"{prefix}_model")
|
|
115
|
+
if binding is None and model is None:
|
|
116
|
+
return None
|
|
117
|
+
return f"{binding}/{model}" if binding else str(model)
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _failed_row(doc: Mapping[str, Any]) -> dict:
|
|
121
|
+
return {
|
|
122
|
+
"id": doc.get("id"),
|
|
123
|
+
"file_path": doc.get("file_path"),
|
|
124
|
+
"error_msg": doc.get("error_msg"),
|
|
125
|
+
"updated_at": doc.get("updated_at"),
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def track_view(raw: Mapping[str, Any]) -> dict:
|
|
130
|
+
"""Compact ``/documents/track_status/{track_id}``."""
|
|
131
|
+
documents = [d for d in raw.get("documents") or [] if isinstance(d, Mapping)]
|
|
132
|
+
return {
|
|
133
|
+
"track_id": raw.get("track_id"),
|
|
134
|
+
"total": raw.get("total_count", len(documents)),
|
|
135
|
+
"status_summary": dict(_mapping(raw.get("status_summary"))),
|
|
136
|
+
"finished": track_is_finished(raw),
|
|
137
|
+
"failed": [_failed_row(d) for d in documents if d.get("status") == "failed"],
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
def track_is_finished(raw: Mapping[str, Any]) -> bool:
|
|
142
|
+
"""True once the track has documents and none of them is still moving.
|
|
143
|
+
|
|
144
|
+
A track with no documents is not finished: an upload is enqueued in the
|
|
145
|
+
background, so right after it returns its track can still be empty.
|
|
146
|
+
"""
|
|
147
|
+
summary = _mapping(raw.get("status_summary"))
|
|
148
|
+
if not any((count or 0) > 0 for count in summary.values()):
|
|
149
|
+
return False
|
|
150
|
+
return not any((summary.get(s) or 0) > 0 for s in ACTIVE_DOC_STATUSES)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def track_has_failures(raw: Mapping[str, Any]) -> bool:
|
|
154
|
+
return (_mapping(raw.get("status_summary")).get("failed") or 0) > 0
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def failed_view(raw: Mapping[str, Any]) -> dict:
|
|
158
|
+
"""Compact ``/documents/paginated`` filtered to ``failed``."""
|
|
159
|
+
documents = [d for d in raw.get("documents") or [] if isinstance(d, Mapping)]
|
|
160
|
+
pagination = _mapping(raw.get("pagination"))
|
|
161
|
+
return {
|
|
162
|
+
"total": pagination.get("total_count", len(documents)),
|
|
163
|
+
"shown": len(documents),
|
|
164
|
+
"documents": [_failed_row(d) for d in documents],
|
|
165
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lightrag-cli
|
|
3
|
+
Version: 1.5.9rc1
|
|
4
|
+
Summary: REST client and `lightrag` command-line tool for a running LightRAG server
|
|
5
|
+
Author: Zirui Guo
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/HKUDS/LightRAG
|
|
8
|
+
Project-URL: Documentation, https://github.com/HKUDS/LightRAG/blob/main/docs/ClientCLI.md
|
|
9
|
+
Project-URL: Repository, https://github.com/HKUDS/LightRAG
|
|
10
|
+
Project-URL: Bug Tracker, https://github.com/HKUDS/LightRAG/issues
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Intended Audience :: Developers
|
|
16
|
+
Classifier: Environment :: Console
|
|
17
|
+
Requires-Python: >=3.11
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
Requires-Dist: aiohttp
|
|
20
|
+
|
|
21
|
+
# lightrag-cli
|
|
22
|
+
|
|
23
|
+
`lightrag-cli` is the REST client (`lightrag_cli`) and the `lightrag` command for a running [LightRAG](https://github.com/HKUDS/LightRAG) server. It depends only on `aiohttp`, so it installs without the LightRAG server stack:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install lightrag-cli
|
|
27
|
+
|
|
28
|
+
export LIGHTRAG_URL="http://127.0.0.1:9621"
|
|
29
|
+
export LIGHTRAG_API_KEY="your-api-key"
|
|
30
|
+
lightrag status
|
|
31
|
+
lightrag query "How does LightRAG build the knowledge graph?" --mode mix
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Every command prints one JSON document on stdout. `lightrag-hku` depends on this package, so a server installation already has the `lightrag` command. Both are released together with the same version number.
|
|
35
|
+
|
|
36
|
+
Full documentation: [docs/ClientCLI.md](https://github.com/HKUDS/LightRAG/blob/main/docs/ClientCLI.md).
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
lightrag_cli/__init__.py,sha256=QmjqRpeqCv8Xib_KtkE374Rtjo7EBzkdLn8-1LR6CcY,967
|
|
2
|
+
lightrag_cli/__main__.py,sha256=RBHxZKhKqQoSJ57wBAVqZD8UOY6N1OFyw1uYwsNhc6c,154
|
|
3
|
+
lightrag_cli/_version.py,sha256=yD-5Ufbh6mMs0_ojKnKX5S4wZxOqR9YUbVMSurhaAzU,223
|
|
4
|
+
lightrag_cli/cli.py,sha256=VoFmBn4Ha07vIFW2k1LTvIp9PzmgXl1kICQclEgGVSw,26956
|
|
5
|
+
lightrag_cli/client.py,sha256=AVzmHW9yd8fBMPJ5Ii1zONlUwe2_vCS3i1BxYikbKLU,21822
|
|
6
|
+
lightrag_cli/views.py,sha256=dzIO_OY_t4eAK7DzhjyIqZO88uEeEwZ-RGvVogY11RE,5898
|
|
7
|
+
lightrag_cli-1.5.9rc1.dist-info/METADATA,sha256=Gq8OklLY1U0w1c9P446TF9s1wL8otE9Km1l1h2hu_VU,1570
|
|
8
|
+
lightrag_cli-1.5.9rc1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
lightrag_cli-1.5.9rc1.dist-info/entry_points.txt,sha256=RU8t4PI2eHmGu-WdX5cDSQN0-QLSyE5NyXL0sqmjxWI,51
|
|
10
|
+
lightrag_cli-1.5.9rc1.dist-info/top_level.txt,sha256=c_UJ3uEk_JiBHt9s3r4Z9J-1q33fk8EDKwCDSAzBLeo,13
|
|
11
|
+
lightrag_cli-1.5.9rc1.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lightrag_cli
|