datalab-python-sdk 0.9.2__tar.gz → 0.11.0__tar.gz
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.
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/CHANGELOG.md +44 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/PKG-INFO +13 -2
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/README.md +12 -1
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/__init__.py +37 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/cli.py +295 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/client.py +475 -11
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/models.py +204 -3
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/pyproject.toml +1 -1
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_api_consistency.py +1 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_cli_simple.py +16 -4
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_client_methods.py +7 -3
- datalab_python_sdk-0.11.0/tests/test_comparisons.py +568 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_new_endpoints.py +30 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_progress.py +24 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/uv.lock +1 -1
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/.github/workflows/ci.yml +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/.gitignore +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/.pre-commit-config.yaml +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/.python-version +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/LICENSE +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/08-Lambda-Calculus.pptx +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/adversarial.pdf +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/bid_evaluation.docx +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/book_review.ppt +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/book_store.xls +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/chi_hind.png +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/how_to_read.doc +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/normandy.epub +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/sample-1-sheet.xlsx +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/thinkpython.pdf +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/data/vibe.html +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/auth.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/exceptions.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/mimetypes.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/datalab_sdk/settings.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/integration/README.md +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/integration/__init__.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/integration/test_live_api.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/integration/test_readme_examples.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/pytest.ini +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/README.md +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/end_to_end_workflow.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/1_get_step_types.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/2_get_workflows.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/3_create_workflow.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/4_execute_workflow.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/5_poll_workflow.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_api_tutorial/README.md +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_definitions/README.md +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_definitions/eval_segmentation.json +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_definitions/parse_segment.json +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_definitions/segment_parallel_extract.json +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/recipes/workflows/workflow_definitions/slack_alert.json +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/__init__.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/conftest.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_cli_options.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_device_login.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_errors.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_results.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_transport_audit.py +0 -0
- {datalab_python_sdk-0.9.2 → datalab_python_sdk-0.11.0}/tests/test_workflows.py +0 -0
|
@@ -3,6 +3,46 @@
|
|
|
3
3
|
The newest release is at the top. Each export to this repository uses the
|
|
4
4
|
top section as its commit message.
|
|
5
5
|
|
|
6
|
+
## 0.11.0
|
|
7
|
+
|
|
8
|
+
Comparisons (open beta):
|
|
9
|
+
|
|
10
|
+
- Evals are now Comparisons. Use `create_comparison()`, `get_comparison()`,
|
|
11
|
+
`list_comparisons()`, `get_comparison_differences()`, and
|
|
12
|
+
`wait_for_comparison()` on both clients. They call the new
|
|
13
|
+
`/api/v1/comparisons` routes. The comparison API may change.
|
|
14
|
+
- New models: `Comparison`, `ComparisonVariant`, `ComparisonVariantResult`,
|
|
15
|
+
`ComparisonDocumentResult`, `ComparisonFile`, `ComparisonList`,
|
|
16
|
+
`ComparisonDifference`, `ComparisonDifferences`, and `ComparisonField`.
|
|
17
|
+
`Comparison.comparison_id` replaces `eval_id`, and
|
|
18
|
+
`ComparisonList.comparisons` replaces `evals`.
|
|
19
|
+
- New CLI commands: `datalab compare run`, `datalab compare get`,
|
|
20
|
+
`datalab compare list`, and `datalab compare differences`.
|
|
21
|
+
|
|
22
|
+
Deprecated:
|
|
23
|
+
|
|
24
|
+
- The 0.10.0 names still work. `create_eval()`, `get_eval()`, `list_evals()`,
|
|
25
|
+
`get_eval_differences()`, and `wait_for_eval()` call the comparison methods
|
|
26
|
+
and raise a `DeprecationWarning`. The `Eval*` model names are aliases of the
|
|
27
|
+
`Comparison*` models. `Comparison.eval_id` and `ComparisonList.evals` are
|
|
28
|
+
read-only aliases. `datalab eval` runs the `datalab compare` commands, prints
|
|
29
|
+
a note, and keeps the 0.10.0 keys in its `--json` output. A future version
|
|
30
|
+
will remove these names.
|
|
31
|
+
|
|
32
|
+
## 0.10.0
|
|
33
|
+
|
|
34
|
+
New:
|
|
35
|
+
|
|
36
|
+
- **Open beta:** Evals on both clients and the CLI. `create_eval()` runs 2 to
|
|
37
|
+
4 variants of a pipeline on the same files or collection and compares them;
|
|
38
|
+
`get_eval()`, `list_evals()`, and `get_eval_differences()` read the status,
|
|
39
|
+
results, and per-document differences; `wait_for_eval()` polls until the
|
|
40
|
+
Eval completes or fails. New models: `Eval`, `EvalVariant`,
|
|
41
|
+
`EvalVariantResult`, `EvalDocumentResult`, `EvalFile`, `EvalDifference`, and
|
|
42
|
+
`EvalDifferences`. New CLI commands: `datalab eval run`, `datalab eval get`,
|
|
43
|
+
`datalab eval list`, and `datalab eval differences`. The Eval API may
|
|
44
|
+
change.
|
|
45
|
+
|
|
6
46
|
## 0.9.2
|
|
7
47
|
|
|
8
48
|
New:
|
|
@@ -39,6 +79,10 @@ New:
|
|
|
39
79
|
|
|
40
80
|
Fixed:
|
|
41
81
|
|
|
82
|
+
- `run_pipeline()` and `get_pipeline_execution()` stop polling when an
|
|
83
|
+
execution ends as `needs_review` (its output is ready, but a blocking Check
|
|
84
|
+
failed or it reached its cost limit) and report it to `on_progress` as
|
|
85
|
+
complete. Before, they polled until `max_polls` ran out.
|
|
42
86
|
- Synchronous calls propagate an operation's `RuntimeError` without attempting
|
|
43
87
|
to rerun its coroutine. Calling the synchronous client inside an active event
|
|
44
88
|
loop now directs callers to `AsyncDatalabClient`.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datalab-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.11.0
|
|
4
4
|
Summary: SDK for the Datalab document intelligence API
|
|
5
5
|
Project-URL: Homepage, https://www.datalab.to
|
|
6
6
|
Project-URL: Documentation, https://documentation.datalab.to
|
|
@@ -125,6 +125,12 @@ print(result.extraction_schema_json, result.extraction_score_average)
|
|
|
125
125
|
|
|
126
126
|
When you do not set the parse `mode`, the API picks the parse mode that matches `extraction_mode`.
|
|
127
127
|
|
|
128
|
+
**Open beta (SDK 0.9.2):** set `citation_granularity="phrase"` in
|
|
129
|
+
`ExtractOptions` for matching words, offsets and match scores. A citation includes
|
|
130
|
+
a box only when the phrase can be located; some citations keep only block/page
|
|
131
|
+
references. Phrase citations cost nothing extra. Turbo returns no citations. See the
|
|
132
|
+
[phrase citation guide](https://documentation.datalab.to/docs/recipes/structured-extraction/api-overview#phrase-level-citations).
|
|
133
|
+
|
|
128
134
|
## Redaction
|
|
129
135
|
|
|
130
136
|
**Open beta (SDK 0.9.0):** the redaction API may change.
|
|
@@ -153,7 +159,7 @@ PDF, including one with failed verification. Redaction returns a typed result;
|
|
|
153
159
|
|
|
154
160
|
| Method | Endpoint |
|
|
155
161
|
| --- | --- |
|
|
156
|
-
| `run_agent()` | **Beta:** run an existing published processor (`AgentOptions(processor="cp_...")`) |
|
|
162
|
+
| `run_agent()` | **Beta:** run an existing published processor (`AgentOptions(processor="cp_...")`, or built-in `jats` / `wcag`) |
|
|
157
163
|
| `segment()` | Split a document into sections (`SegmentOptions`) |
|
|
158
164
|
| `fill()` | Fill a PDF or image form (`FormFillingOptions`) |
|
|
159
165
|
| `form_fields()` | Find the fillable fields in a PDF or image |
|
|
@@ -166,6 +172,11 @@ PDF, including one with failed verification. Redaction returns a typed result;
|
|
|
166
172
|
|
|
167
173
|
`run_custom_processor()` and `ocr()` call deprecated API endpoints. Use `run_agent()` and `convert()` instead.
|
|
168
174
|
|
|
175
|
+
The published `jats` processor returns JATS XML; `wcag` returns an Accessible PDF.
|
|
176
|
+
Inspect `finished`, `verdict` and `verifier_metrics` before using either artifact.
|
|
177
|
+
[Fixed processor examples](https://documentation.datalab.to/docs/recipes/document-agent/jats-and-accessible-pdf)
|
|
178
|
+
show the result fields and version pinning.
|
|
179
|
+
|
|
169
180
|
Published-agent execution is in open beta; the API may change. Processor design and raw-prompt execution are not included.
|
|
170
181
|
|
|
171
182
|
## Inputs, polling and errors
|
|
@@ -104,6 +104,12 @@ print(result.extraction_schema_json, result.extraction_score_average)
|
|
|
104
104
|
|
|
105
105
|
When you do not set the parse `mode`, the API picks the parse mode that matches `extraction_mode`.
|
|
106
106
|
|
|
107
|
+
**Open beta (SDK 0.9.2):** set `citation_granularity="phrase"` in
|
|
108
|
+
`ExtractOptions` for matching words, offsets and match scores. A citation includes
|
|
109
|
+
a box only when the phrase can be located; some citations keep only block/page
|
|
110
|
+
references. Phrase citations cost nothing extra. Turbo returns no citations. See the
|
|
111
|
+
[phrase citation guide](https://documentation.datalab.to/docs/recipes/structured-extraction/api-overview#phrase-level-citations).
|
|
112
|
+
|
|
107
113
|
## Redaction
|
|
108
114
|
|
|
109
115
|
**Open beta (SDK 0.9.0):** the redaction API may change.
|
|
@@ -132,7 +138,7 @@ PDF, including one with failed verification. Redaction returns a typed result;
|
|
|
132
138
|
|
|
133
139
|
| Method | Endpoint |
|
|
134
140
|
| --- | --- |
|
|
135
|
-
| `run_agent()` | **Beta:** run an existing published processor (`AgentOptions(processor="cp_...")`) |
|
|
141
|
+
| `run_agent()` | **Beta:** run an existing published processor (`AgentOptions(processor="cp_...")`, or built-in `jats` / `wcag`) |
|
|
136
142
|
| `segment()` | Split a document into sections (`SegmentOptions`) |
|
|
137
143
|
| `fill()` | Fill a PDF or image form (`FormFillingOptions`) |
|
|
138
144
|
| `form_fields()` | Find the fillable fields in a PDF or image |
|
|
@@ -145,6 +151,11 @@ PDF, including one with failed verification. Redaction returns a typed result;
|
|
|
145
151
|
|
|
146
152
|
`run_custom_processor()` and `ocr()` call deprecated API endpoints. Use `run_agent()` and `convert()` instead.
|
|
147
153
|
|
|
154
|
+
The published `jats` processor returns JATS XML; `wcag` returns an Accessible PDF.
|
|
155
|
+
Inspect `finished`, `verdict` and `verifier_metrics` before using either artifact.
|
|
156
|
+
[Fixed processor examples](https://documentation.datalab.to/docs/recipes/document-agent/jats-and-accessible-pdf)
|
|
157
|
+
show the result fields and version pinning.
|
|
158
|
+
|
|
148
159
|
Published-agent execution is in open beta; the API may change. Processor design and raw-prompt execution are not included.
|
|
149
160
|
|
|
150
161
|
## Inputs, polling and errors
|
|
@@ -52,6 +52,25 @@ from .models import (
|
|
|
52
52
|
PipelineExecutionStepResult,
|
|
53
53
|
CustomProcessor,
|
|
54
54
|
CustomProcessorVersion,
|
|
55
|
+
Comparison,
|
|
56
|
+
ComparisonDifference,
|
|
57
|
+
ComparisonDifferences,
|
|
58
|
+
ComparisonField,
|
|
59
|
+
ComparisonDocumentResult,
|
|
60
|
+
ComparisonFile,
|
|
61
|
+
ComparisonList,
|
|
62
|
+
ComparisonVariant,
|
|
63
|
+
ComparisonVariantResult,
|
|
64
|
+
# Deprecated aliases of the Comparison models (SDK 0.10.0 names).
|
|
65
|
+
Eval,
|
|
66
|
+
EvalDifference,
|
|
67
|
+
EvalDifferences,
|
|
68
|
+
EvalField,
|
|
69
|
+
EvalDocumentResult,
|
|
70
|
+
EvalFile,
|
|
71
|
+
EvalList,
|
|
72
|
+
EvalVariant,
|
|
73
|
+
EvalVariantResult,
|
|
55
74
|
)
|
|
56
75
|
from .settings import settings
|
|
57
76
|
|
|
@@ -102,4 +121,22 @@ __all__ = [
|
|
|
102
121
|
"PipelineExecutionStepResult",
|
|
103
122
|
"CustomProcessor",
|
|
104
123
|
"CustomProcessorVersion",
|
|
124
|
+
"Comparison",
|
|
125
|
+
"ComparisonDifference",
|
|
126
|
+
"ComparisonDifferences",
|
|
127
|
+
"ComparisonField",
|
|
128
|
+
"ComparisonDocumentResult",
|
|
129
|
+
"ComparisonFile",
|
|
130
|
+
"ComparisonList",
|
|
131
|
+
"ComparisonVariant",
|
|
132
|
+
"ComparisonVariantResult",
|
|
133
|
+
"Eval",
|
|
134
|
+
"EvalDifference",
|
|
135
|
+
"EvalDifferences",
|
|
136
|
+
"EvalField",
|
|
137
|
+
"EvalDocumentResult",
|
|
138
|
+
"EvalFile",
|
|
139
|
+
"EvalList",
|
|
140
|
+
"EvalVariant",
|
|
141
|
+
"EvalVariantResult",
|
|
105
142
|
]
|
|
@@ -26,9 +26,11 @@ from datalab_sdk.models import (
|
|
|
26
26
|
ProcessingOptions,
|
|
27
27
|
WorkflowStep,
|
|
28
28
|
InputConfig,
|
|
29
|
+
ComparisonVariant,
|
|
29
30
|
)
|
|
30
31
|
from datalab_sdk.exceptions import DatalabError
|
|
31
32
|
from datalab_sdk.settings import settings
|
|
33
|
+
import dataclasses
|
|
32
34
|
import json
|
|
33
35
|
|
|
34
36
|
|
|
@@ -963,10 +965,16 @@ def fill(
|
|
|
963
965
|
|
|
964
966
|
@click.command("form-fields")
|
|
965
967
|
@click.argument("path", type=click.Path(exists=True))
|
|
968
|
+
@click.option(
|
|
969
|
+
"--include_text",
|
|
970
|
+
is_flag=True,
|
|
971
|
+
help="Also read the page text and mark each field in it (slower)",
|
|
972
|
+
)
|
|
966
973
|
@webhook_option
|
|
967
974
|
@common_options
|
|
968
975
|
def form_fields(
|
|
969
976
|
path: str,
|
|
977
|
+
include_text: bool,
|
|
970
978
|
webhook_url: Optional[str],
|
|
971
979
|
api_key: str,
|
|
972
980
|
output_dir: str,
|
|
@@ -985,6 +993,7 @@ def form_fields(
|
|
|
985
993
|
max_pages=max_pages,
|
|
986
994
|
page_range=page_range,
|
|
987
995
|
skip_cache=skip_cache,
|
|
996
|
+
include_text=include_text,
|
|
988
997
|
)
|
|
989
998
|
process_documents(
|
|
990
999
|
path=path,
|
|
@@ -1144,6 +1153,290 @@ def create_document(
|
|
|
1144
1153
|
sys.exit(1)
|
|
1145
1154
|
|
|
1146
1155
|
|
|
1156
|
+
# Compare commands (open beta; the API may change). `datalab eval` is the
|
|
1157
|
+
# deprecated 0.10.0 name of the same commands.
|
|
1158
|
+
|
|
1159
|
+
_LEGACY_EVAL_META = "datalab_legacy_eval"
|
|
1160
|
+
|
|
1161
|
+
|
|
1162
|
+
def _compare_client(api_key: Optional[str], base_url: str) -> DatalabClient:
|
|
1163
|
+
if api_key is None:
|
|
1164
|
+
api_key = settings.DATALAB_API_KEY
|
|
1165
|
+
if api_key is None:
|
|
1166
|
+
raise DatalabError(
|
|
1167
|
+
"You must either pass in an api key via --api_key or set the DATALAB_API_KEY env variable. "
|
|
1168
|
+
"Get a free API key at https://www.datalab.to/app/keys"
|
|
1169
|
+
)
|
|
1170
|
+
return DatalabClient(api_key=api_key, base_url=base_url)
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
def _legacy_eval() -> bool:
|
|
1174
|
+
"""True when the command runs as the deprecated `datalab eval`."""
|
|
1175
|
+
return bool(click.get_current_context().meta.get(_LEGACY_EVAL_META))
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
def _echo_json(result) -> None:
|
|
1179
|
+
"""Print a result as JSON. Under `datalab eval`, use the 0.10.0 keys."""
|
|
1180
|
+
data = dataclasses.asdict(result)
|
|
1181
|
+
if _legacy_eval():
|
|
1182
|
+
if "comparison_id" in data:
|
|
1183
|
+
data = {"eval_id": data.pop("comparison_id"), **data}
|
|
1184
|
+
if "comparisons" in data:
|
|
1185
|
+
data["evals"] = [
|
|
1186
|
+
{"eval_id": c.pop("comparison_id"), **c}
|
|
1187
|
+
for c in data.pop("comparisons")
|
|
1188
|
+
]
|
|
1189
|
+
click.echo(json.dumps(data, indent=2))
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
def _print_comparison_summary(comparison) -> None:
|
|
1193
|
+
click.echo(
|
|
1194
|
+
f"Comparison {comparison.comparison_id}: {comparison.status} "
|
|
1195
|
+
f"(pipeline {comparison.pipeline_id}, compares {comparison.compared_step})"
|
|
1196
|
+
)
|
|
1197
|
+
for variant in comparison.variants:
|
|
1198
|
+
share = f"{variant.share * 100:.0f}%" if variant.share is not None else "n/a"
|
|
1199
|
+
rate = (
|
|
1200
|
+
f"${variant.rate_per_1000_pages_cents / 100:.2f}/1000 pages"
|
|
1201
|
+
if variant.rate_per_1000_pages_cents is not None
|
|
1202
|
+
else "n/a"
|
|
1203
|
+
)
|
|
1204
|
+
speed = (
|
|
1205
|
+
f"{variant.seconds_per_page:.2f}s/page"
|
|
1206
|
+
if variant.seconds_per_page is not None
|
|
1207
|
+
else "n/a"
|
|
1208
|
+
)
|
|
1209
|
+
click.echo(
|
|
1210
|
+
f" {variant.name}: share={share} decided={variant.decided} won={variant.won} "
|
|
1211
|
+
f"rate={rate} speed={speed}"
|
|
1212
|
+
)
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
compare_option_api_key = click.option(
|
|
1216
|
+
"--api_key", required=False, help="Datalab API key"
|
|
1217
|
+
)
|
|
1218
|
+
compare_option_base_url = click.option(
|
|
1219
|
+
"--base_url", default=settings.DATALAB_HOST, help="API base URL"
|
|
1220
|
+
)
|
|
1221
|
+
compare_option_json = click.option(
|
|
1222
|
+
"--json", "json_output", is_flag=True, help="Print the raw result as JSON"
|
|
1223
|
+
)
|
|
1224
|
+
|
|
1225
|
+
|
|
1226
|
+
@click.group("compare")
|
|
1227
|
+
def compare_group():
|
|
1228
|
+
"""[Open beta] Compare pipeline variants, head to head."""
|
|
1229
|
+
pass
|
|
1230
|
+
|
|
1231
|
+
|
|
1232
|
+
@click.group("eval", hidden=True)
|
|
1233
|
+
@click.pass_context
|
|
1234
|
+
def eval_group(ctx):
|
|
1235
|
+
"""Deprecated: use `datalab compare`."""
|
|
1236
|
+
ctx.meta[_LEGACY_EVAL_META] = True
|
|
1237
|
+
click.echo(
|
|
1238
|
+
"Note: `datalab eval` is deprecated. Use `datalab compare` instead.",
|
|
1239
|
+
err=True,
|
|
1240
|
+
)
|
|
1241
|
+
|
|
1242
|
+
|
|
1243
|
+
@click.command("run")
|
|
1244
|
+
@click.argument("paths", nargs=-1, type=click.Path(exists=True))
|
|
1245
|
+
@click.option(
|
|
1246
|
+
"--pipeline",
|
|
1247
|
+
"pipeline_id",
|
|
1248
|
+
required=True,
|
|
1249
|
+
help="Pipeline ID to compare (pl_XXXXX)",
|
|
1250
|
+
)
|
|
1251
|
+
@click.option(
|
|
1252
|
+
"--collection_id",
|
|
1253
|
+
type=int,
|
|
1254
|
+
help="Collection ID to compare, instead of FILE paths",
|
|
1255
|
+
)
|
|
1256
|
+
@click.option(
|
|
1257
|
+
"--variant-json",
|
|
1258
|
+
"variants_json",
|
|
1259
|
+
help='Variants as JSON or a path to a JSON file: [{"name": "Accurate", '
|
|
1260
|
+
'"steps": {"convert": {"output_mode": "accurate"}}}, ...]. Omit to '
|
|
1261
|
+
"compare the default Fast/Balanced/Accurate modes.",
|
|
1262
|
+
)
|
|
1263
|
+
@click.option(
|
|
1264
|
+
"--version", type=int, help="Pipeline version to run (0=draft, omit=active)"
|
|
1265
|
+
)
|
|
1266
|
+
@click.option(
|
|
1267
|
+
"--wait",
|
|
1268
|
+
is_flag=True,
|
|
1269
|
+
help="Poll until the comparison finishes and print a summary",
|
|
1270
|
+
)
|
|
1271
|
+
@click.option(
|
|
1272
|
+
"--poll_interval", default=10, type=int, help="Seconds between polls with --wait"
|
|
1273
|
+
)
|
|
1274
|
+
@click.option(
|
|
1275
|
+
"--timeout", default=7200, type=int, help="Maximum seconds to wait with --wait"
|
|
1276
|
+
)
|
|
1277
|
+
@compare_option_json
|
|
1278
|
+
@compare_option_api_key
|
|
1279
|
+
@compare_option_base_url
|
|
1280
|
+
def compare_run(
|
|
1281
|
+
paths,
|
|
1282
|
+
pipeline_id: str,
|
|
1283
|
+
collection_id: Optional[int],
|
|
1284
|
+
variants_json: Optional[str],
|
|
1285
|
+
version: Optional[int],
|
|
1286
|
+
wait: bool,
|
|
1287
|
+
poll_interval: int,
|
|
1288
|
+
timeout: int,
|
|
1289
|
+
json_output: bool,
|
|
1290
|
+
api_key: Optional[str],
|
|
1291
|
+
base_url: str,
|
|
1292
|
+
):
|
|
1293
|
+
"""[Open beta] Compare pipeline variants on FILE paths or a collection."""
|
|
1294
|
+
try:
|
|
1295
|
+
if bool(paths) == bool(collection_id):
|
|
1296
|
+
raise click.UsageError(
|
|
1297
|
+
"Give either FILE paths or --collection_id, not both."
|
|
1298
|
+
)
|
|
1299
|
+
variants = None
|
|
1300
|
+
if variants_json is not None:
|
|
1301
|
+
data = _load_json_option(variants_json, "--variant-json")
|
|
1302
|
+
variants = [
|
|
1303
|
+
ComparisonVariant(name=v["name"], steps=v.get("steps", {}))
|
|
1304
|
+
for v in data
|
|
1305
|
+
]
|
|
1306
|
+
|
|
1307
|
+
client = _compare_client(api_key, base_url)
|
|
1308
|
+
file_ids = None
|
|
1309
|
+
if paths:
|
|
1310
|
+
uploaded = client.upload_files(list(paths))
|
|
1311
|
+
if not isinstance(uploaded, list):
|
|
1312
|
+
uploaded = [uploaded]
|
|
1313
|
+
file_ids = [u.file_id for u in uploaded]
|
|
1314
|
+
|
|
1315
|
+
comparison = client.create_comparison(
|
|
1316
|
+
pipeline_id,
|
|
1317
|
+
file_ids=file_ids,
|
|
1318
|
+
collection_id=collection_id,
|
|
1319
|
+
variants=variants,
|
|
1320
|
+
version=version,
|
|
1321
|
+
)
|
|
1322
|
+
if wait:
|
|
1323
|
+
comparison = client.wait_for_comparison(
|
|
1324
|
+
comparison.comparison_id, poll_interval=poll_interval, timeout=timeout
|
|
1325
|
+
)
|
|
1326
|
+
if json_output:
|
|
1327
|
+
_echo_json(comparison)
|
|
1328
|
+
else:
|
|
1329
|
+
_print_comparison_summary(comparison)
|
|
1330
|
+
elif json_output:
|
|
1331
|
+
_echo_json(comparison)
|
|
1332
|
+
else:
|
|
1333
|
+
click.echo(
|
|
1334
|
+
f"Comparison {comparison.comparison_id} started ({comparison.status})."
|
|
1335
|
+
)
|
|
1336
|
+
click.echo(f"Check it with: datalab compare get {comparison.comparison_id}")
|
|
1337
|
+
except DatalabError as e:
|
|
1338
|
+
click.echo(f"Error: {e}", err=True)
|
|
1339
|
+
sys.exit(1)
|
|
1340
|
+
|
|
1341
|
+
|
|
1342
|
+
@click.command("get")
|
|
1343
|
+
@click.argument("comparison_id", type=int)
|
|
1344
|
+
@compare_option_json
|
|
1345
|
+
@compare_option_api_key
|
|
1346
|
+
@compare_option_base_url
|
|
1347
|
+
def compare_get(
|
|
1348
|
+
comparison_id: int, json_output: bool, api_key: Optional[str], base_url: str
|
|
1349
|
+
):
|
|
1350
|
+
"""[Open beta] Get a comparison's status and each variant's result."""
|
|
1351
|
+
try:
|
|
1352
|
+
client = _compare_client(api_key, base_url)
|
|
1353
|
+
comparison = client.get_comparison(comparison_id)
|
|
1354
|
+
if json_output:
|
|
1355
|
+
_echo_json(comparison)
|
|
1356
|
+
else:
|
|
1357
|
+
_print_comparison_summary(comparison)
|
|
1358
|
+
except DatalabError as e:
|
|
1359
|
+
click.echo(f"Error: {e}", err=True)
|
|
1360
|
+
sys.exit(1)
|
|
1361
|
+
|
|
1362
|
+
|
|
1363
|
+
@click.command("list")
|
|
1364
|
+
@click.option("--pipeline_id", help="Only comparisons of this pipeline")
|
|
1365
|
+
@click.option("--collection_id", type=int, help="Only comparisons of this collection")
|
|
1366
|
+
@click.option("--limit", default=20, type=int, help="Maximum number to return")
|
|
1367
|
+
@click.option("--offset", default=0, type=int, help="Offset for pagination")
|
|
1368
|
+
@compare_option_json
|
|
1369
|
+
@compare_option_api_key
|
|
1370
|
+
@compare_option_base_url
|
|
1371
|
+
def compare_list(
|
|
1372
|
+
pipeline_id: Optional[str],
|
|
1373
|
+
collection_id: Optional[int],
|
|
1374
|
+
limit: int,
|
|
1375
|
+
offset: int,
|
|
1376
|
+
json_output: bool,
|
|
1377
|
+
api_key: Optional[str],
|
|
1378
|
+
base_url: str,
|
|
1379
|
+
):
|
|
1380
|
+
"""[Open beta] List the team's comparisons, newest first."""
|
|
1381
|
+
try:
|
|
1382
|
+
client = _compare_client(api_key, base_url)
|
|
1383
|
+
result = client.list_comparisons(
|
|
1384
|
+
pipeline_id=pipeline_id,
|
|
1385
|
+
collection_id=collection_id,
|
|
1386
|
+
limit=limit,
|
|
1387
|
+
offset=offset,
|
|
1388
|
+
)
|
|
1389
|
+
if json_output:
|
|
1390
|
+
_echo_json(result)
|
|
1391
|
+
else:
|
|
1392
|
+
click.echo(f"{result.total} comparison(s):")
|
|
1393
|
+
for comparison in result.comparisons:
|
|
1394
|
+
click.echo(
|
|
1395
|
+
f" {comparison.comparison_id}: {comparison.status} (pipeline {comparison.pipeline_id})"
|
|
1396
|
+
)
|
|
1397
|
+
except DatalabError as e:
|
|
1398
|
+
click.echo(f"Error: {e}", err=True)
|
|
1399
|
+
sys.exit(1)
|
|
1400
|
+
|
|
1401
|
+
|
|
1402
|
+
@click.command("differences")
|
|
1403
|
+
@click.argument("comparison_id", type=int)
|
|
1404
|
+
@click.argument("file_id", type=int)
|
|
1405
|
+
@compare_option_json
|
|
1406
|
+
@compare_option_api_key
|
|
1407
|
+
@compare_option_base_url
|
|
1408
|
+
def compare_differences(
|
|
1409
|
+
comparison_id: int,
|
|
1410
|
+
file_id: int,
|
|
1411
|
+
json_output: bool,
|
|
1412
|
+
api_key: Optional[str],
|
|
1413
|
+
base_url: str,
|
|
1414
|
+
):
|
|
1415
|
+
"""[Open beta] Show where a comparison's variants read one document differently."""
|
|
1416
|
+
try:
|
|
1417
|
+
client = _compare_client(api_key, base_url)
|
|
1418
|
+
result = client.get_comparison_differences(comparison_id, file_id)
|
|
1419
|
+
if json_output:
|
|
1420
|
+
_echo_json(result)
|
|
1421
|
+
else:
|
|
1422
|
+
click.echo(
|
|
1423
|
+
f"File {result.file_id}: variants {', '.join(result.variant_names)}"
|
|
1424
|
+
)
|
|
1425
|
+
for d in result.differences:
|
|
1426
|
+
label = d.question or d.before[:40]
|
|
1427
|
+
click.echo(
|
|
1428
|
+
f" page {d.page} [{d.verdict}] {label!r} -> winners {d.winners}"
|
|
1429
|
+
)
|
|
1430
|
+
except DatalabError as e:
|
|
1431
|
+
click.echo(f"Error: {e}", err=True)
|
|
1432
|
+
sys.exit(1)
|
|
1433
|
+
|
|
1434
|
+
|
|
1435
|
+
for _command in (compare_run, compare_get, compare_list, compare_differences):
|
|
1436
|
+
compare_group.add_command(_command)
|
|
1437
|
+
eval_group.add_command(_command)
|
|
1438
|
+
|
|
1439
|
+
|
|
1147
1440
|
# Workflow commands
|
|
1148
1441
|
def _echo_workflows_removed():
|
|
1149
1442
|
click.echo(
|
|
@@ -1652,6 +1945,8 @@ cli.add_command(fill)
|
|
|
1652
1945
|
cli.add_command(form_fields)
|
|
1653
1946
|
cli.add_command(agent)
|
|
1654
1947
|
cli.add_command(create_document)
|
|
1948
|
+
cli.add_command(compare_group)
|
|
1949
|
+
cli.add_command(eval_group)
|
|
1655
1950
|
cli.add_command(create_workflow)
|
|
1656
1951
|
cli.add_command(get_workflow)
|
|
1657
1952
|
cli.add_command(get_step_types)
|