datalab-python-sdk 0.14.0__py3-none-any.whl → 0.15.0__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.
- {datalab_python_sdk-0.14.0.dist-info → datalab_python_sdk-0.15.0.dist-info}/METADATA +2 -6
- datalab_python_sdk-0.15.0.dist-info/RECORD +15 -0
- datalab_sdk/__init__.py +2 -10
- datalab_sdk/_output_layout.py +4 -2
- datalab_sdk/_output_names.py +31 -0
- datalab_sdk/cli.py +18 -458
- datalab_sdk/client.py +133 -485
- datalab_sdk/models.py +26 -145
- datalab_python_sdk-0.14.0.dist-info/RECORD +0 -14
- {datalab_python_sdk-0.14.0.dist-info → datalab_python_sdk-0.15.0.dist-info}/WHEEL +0 -0
- {datalab_python_sdk-0.14.0.dist-info → datalab_python_sdk-0.15.0.dist-info}/entry_points.txt +0 -0
- {datalab_python_sdk-0.14.0.dist-info → datalab_python_sdk-0.15.0.dist-info}/licenses/LICENSE +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: datalab-python-sdk
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.15.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
|
|
@@ -35,7 +35,7 @@ pip install datalab-python-sdk
|
|
|
35
35
|
|
|
36
36
|
### Authentication
|
|
37
37
|
|
|
38
|
-
[Sign up](https://www.datalab.to
|
|
38
|
+
[Sign up](https://www.datalab.to/auth/sign_up?utm_source=gh-sdk), then get your API key from [https://www.datalab.to/app/keys](https://www.datalab.to/app/keys):
|
|
39
39
|
|
|
40
40
|
```bash
|
|
41
41
|
export DATALAB_API_KEY="your_api_key_here"
|
|
@@ -201,10 +201,6 @@ With SDK 0.9.0, `upload_files(paths, max_concurrency=5)` streams
|
|
|
201
201
|
files from disk and limits the number of active uploads. Results retain the
|
|
202
202
|
input order. Use `AsyncDatalabClient` inside an existing async event loop.
|
|
203
203
|
|
|
204
|
-
## Workflows
|
|
205
|
-
|
|
206
|
-
The Datalab API removed the Workflows API. The workflow methods and CLI commands in this SDK are deprecated, and the API does not answer them. Use pipelines instead.
|
|
207
|
-
|
|
208
204
|
## CLI Usage
|
|
209
205
|
|
|
210
206
|
The SDK includes a command-line interface:
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
datalab_sdk/__init__.py,sha256=EDF3pT5_7FuDmYdo9TilNg2lzLDmKnCpzAaTSc2FoEs,3303
|
|
2
|
+
datalab_sdk/_output_layout.py,sha256=mDtg2hZQkMw_LTsrfslxwJ4BOZ2H8wKpR9w9CaT8mBs,7989
|
|
3
|
+
datalab_sdk/_output_names.py,sha256=CVbXjF--VoX61ZSOB2eUmeg0jbq4g5EMLzWcLy1a9Gw,1001
|
|
4
|
+
datalab_sdk/auth.py,sha256=i7LzAMM5wjY5-J6BUf69do6g7zuKenQZQwueqbLJSNU,7704
|
|
5
|
+
datalab_sdk/cli.py,sha256=YZObu6fihyQ3TLvFaWurpWYZGHYTzTx3m1r6mOpHOsE,47696
|
|
6
|
+
datalab_sdk/client.py,sha256=xDhNsNkUPE4ZsOlVdcnDysT4IwlFivZGb7X1q7dJxxg,161003
|
|
7
|
+
datalab_sdk/exceptions.py,sha256=GFRAZQoxP2cHYJ3Q-OBjU_3I34Om3avcz11vczc_GNs,4420
|
|
8
|
+
datalab_sdk/mimetypes.py,sha256=a4ULJmHxoR_RMsD0j51hx0t2Q7In_PzNm7UlWX07eEE,932
|
|
9
|
+
datalab_sdk/models.py,sha256=L13qApU-VISHdAHQ2dWBLBZwGNSAxktdy92djpQXUxk,39890
|
|
10
|
+
datalab_sdk/settings.py,sha256=B_B42QQADAz6ePXQTOqENZllcppFR4JpwonEk2vlzhw,693
|
|
11
|
+
datalab_python_sdk-0.15.0.dist-info/METADATA,sha256=60Z-brfZerWCYF_YPwTK5vj0VlV5qiIssGLYnCVmPvc,11344
|
|
12
|
+
datalab_python_sdk-0.15.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
13
|
+
datalab_python_sdk-0.15.0.dist-info/entry_points.txt,sha256=rqWxO21UV57JxxyeF20iBTxHpzBYOA69hCHIqwdn-Ok,48
|
|
14
|
+
datalab_python_sdk-0.15.0.dist-info/licenses/LICENSE,sha256=XGjT-Uz6t7UZzr3JCZfilsGcZEgMm_1aONcRunohxWg,1064
|
|
15
|
+
datalab_python_sdk-0.15.0.dist-info/RECORD,,
|
datalab_sdk/__init__.py
CHANGED
|
@@ -40,13 +40,9 @@ from .models import (
|
|
|
40
40
|
FormFieldsResult,
|
|
41
41
|
AgentOptions,
|
|
42
42
|
AgentResult,
|
|
43
|
-
ExtractionSchemaSuggestions,
|
|
44
|
-
Workflow,
|
|
45
|
-
WorkflowStep,
|
|
46
|
-
WorkflowExecution,
|
|
47
|
-
InputConfig,
|
|
48
43
|
UploadedFileMetadata,
|
|
49
44
|
ExtractionSchema,
|
|
45
|
+
ExtractionSchemaSuggestions,
|
|
50
46
|
PipelineProcessor,
|
|
51
47
|
PipelineConfig,
|
|
52
48
|
PipelineVersion,
|
|
@@ -111,13 +107,9 @@ __all__ = [
|
|
|
111
107
|
"FormFieldsResult",
|
|
112
108
|
"AgentOptions",
|
|
113
109
|
"AgentResult",
|
|
114
|
-
"ExtractionSchemaSuggestions",
|
|
115
|
-
"Workflow",
|
|
116
|
-
"WorkflowStep",
|
|
117
|
-
"WorkflowExecution",
|
|
118
|
-
"InputConfig",
|
|
119
110
|
"UploadedFileMetadata",
|
|
120
111
|
"ExtractionSchema",
|
|
112
|
+
"ExtractionSchemaSuggestions",
|
|
121
113
|
"PipelineProcessor",
|
|
122
114
|
"PipelineConfig",
|
|
123
115
|
"PipelineVersion",
|
datalab_sdk/_output_layout.py
CHANGED
|
@@ -13,6 +13,7 @@ import tempfile
|
|
|
13
13
|
from pathlib import Path
|
|
14
14
|
from typing import Dict, List, Optional
|
|
15
15
|
|
|
16
|
+
from datalab_sdk._output_names import exact_output_base
|
|
16
17
|
from datalab_sdk.exceptions import DatalabError
|
|
17
18
|
|
|
18
19
|
OUTPUT_MARKER = ".datalab-output"
|
|
@@ -137,8 +138,9 @@ class OutputLayout:
|
|
|
137
138
|
return list(self._folders.values())
|
|
138
139
|
|
|
139
140
|
def output_path(self, file_path: Path) -> Path:
|
|
140
|
-
"""The save_output path of an input: its folder plus its stem
|
|
141
|
-
|
|
141
|
+
"""The save_output path of an input: its folder plus its whole stem
|
|
142
|
+
(report.json.tif saves report.json.md, report.json.html and so on)."""
|
|
143
|
+
return exact_output_base(self._folders[file_path] / file_path.stem)
|
|
142
144
|
|
|
143
145
|
def __enter__(self) -> "OutputLayout":
|
|
144
146
|
# A with statement doesn't call __exit__ when __enter__ raises, so any
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""How save_output names the files it writes from the path it's given."""
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
from datalab_sdk.mimetypes import SUPPORTED_EXTENSIONS
|
|
6
|
+
|
|
7
|
+
# The extensions save_output replaces: the ones it writes, and the input types the
|
|
8
|
+
# API reads, so save_output("out/scan.jpg") writes out/scan.md. Any other dot belongs
|
|
9
|
+
# to the name (a stem such as "v1.2.report").
|
|
10
|
+
_REPLACED_EXTENSIONS = {
|
|
11
|
+
".md",
|
|
12
|
+
".txt",
|
|
13
|
+
".json",
|
|
14
|
+
".xml",
|
|
15
|
+
".tif",
|
|
16
|
+
".htm",
|
|
17
|
+
*SUPPORTED_EXTENSIONS,
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def output_file(path: Path, suffix: str) -> Path:
|
|
22
|
+
"""`path` with `suffix` added, keeping every dot in the name except one known extension."""
|
|
23
|
+
if path.suffix.lower() in _REPLACED_EXTENSIONS:
|
|
24
|
+
path = path.with_suffix("")
|
|
25
|
+
return path.with_name(path.name + suffix)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def exact_output_base(base: Path) -> Path:
|
|
29
|
+
"""A path that save_output uses whole as the base name, dots and all
|
|
30
|
+
(report.json gives report.json.md, not report.md)."""
|
|
31
|
+
return base.with_name(base.name + ".md")
|
datalab_sdk/cli.py
CHANGED
|
@@ -12,6 +12,7 @@ import click
|
|
|
12
12
|
from tqdm import tqdm
|
|
13
13
|
|
|
14
14
|
from datalab_sdk.client import AsyncDatalabClient, DatalabClient
|
|
15
|
+
from datalab_sdk._output_names import output_file
|
|
15
16
|
from datalab_sdk.mimetypes import SUPPORTED_EXTENSIONS
|
|
16
17
|
from datalab_sdk.models import (
|
|
17
18
|
OCROptions,
|
|
@@ -24,8 +25,7 @@ from datalab_sdk.models import (
|
|
|
24
25
|
FormFieldsOptions,
|
|
25
26
|
AgentOptions,
|
|
26
27
|
ProcessingOptions,
|
|
27
|
-
|
|
28
|
-
InputConfig,
|
|
28
|
+
Comparison,
|
|
29
29
|
ComparisonVariant,
|
|
30
30
|
)
|
|
31
31
|
from datalab_sdk._output_layout import OUTPUT_MARKER, OutputLayout
|
|
@@ -862,9 +862,10 @@ def custom_pipeline(
|
|
|
862
862
|
max_polls: int,
|
|
863
863
|
poll_interval: int,
|
|
864
864
|
):
|
|
865
|
-
"""[Deprecated] Run a custom pipeline. Use datalab agent --processor cp_XXXXX instead."""
|
|
865
|
+
"""[Deprecated; sunset 2026-10-31 passed] Run a custom pipeline. Use datalab agent --processor cp_XXXXX instead."""
|
|
866
866
|
click.echo(
|
|
867
|
-
"Warning: custom-pipeline is deprecated
|
|
867
|
+
"Warning: custom-pipeline is deprecated, and its sunset date (2026-10-31) "
|
|
868
|
+
"has passed, so it can stop working without further notice. "
|
|
868
869
|
"Use datalab agent --processor cp_XXXXX instead.",
|
|
869
870
|
err=True,
|
|
870
871
|
)
|
|
@@ -1166,7 +1167,7 @@ def create_document(
|
|
|
1166
1167
|
|
|
1167
1168
|
if result.success:
|
|
1168
1169
|
click.echo(
|
|
1169
|
-
f"Document created successfully: {Path(output_path)
|
|
1170
|
+
f"Document created successfully: {output_file(Path(output_path), '.docx')}"
|
|
1170
1171
|
)
|
|
1171
1172
|
else:
|
|
1172
1173
|
click.echo(f"Document creation failed: {result.error}", err=True)
|
|
@@ -1202,7 +1203,7 @@ def _echo_json(result) -> None:
|
|
|
1202
1203
|
click.echo(json.dumps(data, indent=2))
|
|
1203
1204
|
|
|
1204
1205
|
|
|
1205
|
-
def _print_comparison_summary(comparison) -> None:
|
|
1206
|
+
def _print_comparison_summary(comparison: Comparison) -> None:
|
|
1206
1207
|
click.echo(
|
|
1207
1208
|
f"Comparison {comparison.comparison_id}: {comparison.status} "
|
|
1208
1209
|
f"(pipeline {comparison.pipeline_id}, compares {comparison.compared_step})"
|
|
@@ -1223,9 +1224,17 @@ def _print_comparison_summary(comparison) -> None:
|
|
|
1223
1224
|
f" {variant.name}: share={share} decided={variant.decided} won={variant.won} "
|
|
1224
1225
|
f"rate={rate} speed={speed}"
|
|
1225
1226
|
)
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1227
|
+
files = comparison.files or []
|
|
1228
|
+
for file in files:
|
|
1229
|
+
detail = f": {file.comparison_error}" if file.comparison_error else ""
|
|
1230
|
+
click.echo(
|
|
1231
|
+
f" File {file.file_id}: {file.file_name} ({file.comparison}){detail}"
|
|
1232
|
+
)
|
|
1233
|
+
if any(file.comparison == "completed" for file in files):
|
|
1234
|
+
click.echo(
|
|
1235
|
+
"See where the variants differ on a completed file: "
|
|
1236
|
+
f"datalab compare differences {comparison.comparison_id} FILE_ID"
|
|
1237
|
+
)
|
|
1229
1238
|
|
|
1230
1239
|
|
|
1231
1240
|
compare_option_api_key = click.option(
|
|
@@ -1466,448 +1475,6 @@ for _command in (compare_run, compare_get, compare_list, compare_differences):
|
|
|
1466
1475
|
eval_group.add_command(_command)
|
|
1467
1476
|
|
|
1468
1477
|
|
|
1469
|
-
# Workflow commands
|
|
1470
|
-
def _echo_workflows_removed():
|
|
1471
|
-
click.echo(
|
|
1472
|
-
"Warning: the Datalab API removed the Workflows API, so workflow "
|
|
1473
|
-
"commands fail. Use pipelines instead (see the SDK README).",
|
|
1474
|
-
err=True,
|
|
1475
|
-
)
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
@click.command()
|
|
1479
|
-
@click.option("--name", required=True, help="Name of the workflow")
|
|
1480
|
-
@click.option("--team_id", required=True, type=int, help="Team ID for the workflow")
|
|
1481
|
-
@click.option(
|
|
1482
|
-
"--steps",
|
|
1483
|
-
required=True,
|
|
1484
|
-
help="JSON string or path to JSON file with workflow steps",
|
|
1485
|
-
)
|
|
1486
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1487
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1488
|
-
def create_workflow(
|
|
1489
|
-
name: str,
|
|
1490
|
-
team_id: int,
|
|
1491
|
-
steps: str,
|
|
1492
|
-
api_key: Optional[str],
|
|
1493
|
-
base_url: str,
|
|
1494
|
-
):
|
|
1495
|
-
"""[Deprecated: the API removed workflows] Create a new workflow"""
|
|
1496
|
-
_echo_workflows_removed()
|
|
1497
|
-
try:
|
|
1498
|
-
# Parse steps from JSON string or file
|
|
1499
|
-
steps_path = Path(steps)
|
|
1500
|
-
if steps_path.exists():
|
|
1501
|
-
with open(steps_path, "r") as f:
|
|
1502
|
-
steps_data = json.load(f)
|
|
1503
|
-
else:
|
|
1504
|
-
steps_data = json.loads(steps)
|
|
1505
|
-
|
|
1506
|
-
# Create WorkflowStep objects
|
|
1507
|
-
workflow_steps = [
|
|
1508
|
-
WorkflowStep(
|
|
1509
|
-
step_key=step["step_key"],
|
|
1510
|
-
unique_name=step["unique_name"],
|
|
1511
|
-
settings=step["settings"],
|
|
1512
|
-
depends_on=step.get("depends_on", []),
|
|
1513
|
-
)
|
|
1514
|
-
for step in steps_data
|
|
1515
|
-
]
|
|
1516
|
-
|
|
1517
|
-
# Create workflow
|
|
1518
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1519
|
-
workflow = client.create_workflow(name=name, steps=workflow_steps)
|
|
1520
|
-
|
|
1521
|
-
click.echo("Workflow created successfully!")
|
|
1522
|
-
click.echo(f" ID: {workflow.id}")
|
|
1523
|
-
click.echo(f" Name: {workflow.name}")
|
|
1524
|
-
click.echo(f" Team ID: {workflow.team_id}")
|
|
1525
|
-
click.echo(f" Steps: {len(workflow.steps)}")
|
|
1526
|
-
|
|
1527
|
-
except DatalabError as e:
|
|
1528
|
-
click.echo(f"Error: {e}", err=True)
|
|
1529
|
-
sys.exit(1)
|
|
1530
|
-
except Exception as e:
|
|
1531
|
-
click.echo(f"Error: {e}", err=True)
|
|
1532
|
-
sys.exit(1)
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
@click.command()
|
|
1536
|
-
@click.option("--workflow_id", required=True, type=int, help="ID of the workflow")
|
|
1537
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1538
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1539
|
-
def get_workflow(workflow_id: int, api_key: Optional[str], base_url: str):
|
|
1540
|
-
"""[Deprecated: the API removed workflows] Get a workflow by ID"""
|
|
1541
|
-
_echo_workflows_removed()
|
|
1542
|
-
try:
|
|
1543
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1544
|
-
workflow = client.get_workflow(workflow_id)
|
|
1545
|
-
|
|
1546
|
-
click.echo("Workflow Details:")
|
|
1547
|
-
click.echo(f" ID: {workflow.id}")
|
|
1548
|
-
click.echo(f" Name: {workflow.name}")
|
|
1549
|
-
click.echo(f" Team ID: {workflow.team_id}")
|
|
1550
|
-
click.echo(f" Steps: {len(workflow.steps)}")
|
|
1551
|
-
click.echo(f" Created: {workflow.created}")
|
|
1552
|
-
|
|
1553
|
-
for i, step in enumerate(workflow.steps, 1):
|
|
1554
|
-
click.echo(f"\n Step {i}: {step.unique_name}")
|
|
1555
|
-
click.echo(f" Type: {step.step_key}")
|
|
1556
|
-
click.echo(f" Settings: {json.dumps(step.settings, indent=8)}")
|
|
1557
|
-
if step.depends_on:
|
|
1558
|
-
click.echo(f" Depends on: {', '.join(step.depends_on)}")
|
|
1559
|
-
|
|
1560
|
-
except DatalabError as e:
|
|
1561
|
-
click.echo(f"Error: {e}", err=True)
|
|
1562
|
-
sys.exit(1)
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
@click.command()
|
|
1566
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1567
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1568
|
-
def get_step_types(api_key: Optional[str], base_url: str):
|
|
1569
|
-
"""[Deprecated: the API removed workflows] Get all available workflow step types"""
|
|
1570
|
-
_echo_workflows_removed()
|
|
1571
|
-
try:
|
|
1572
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1573
|
-
response = client.get_step_types()
|
|
1574
|
-
|
|
1575
|
-
step_types = response.get("step_types", [])
|
|
1576
|
-
if not step_types:
|
|
1577
|
-
click.echo("No step types found.")
|
|
1578
|
-
return
|
|
1579
|
-
|
|
1580
|
-
click.echo(f"Found {len(step_types)} step type(s):\n")
|
|
1581
|
-
for step_type in step_types:
|
|
1582
|
-
click.echo("━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━")
|
|
1583
|
-
click.echo(f"Key: {step_type.get('type')}")
|
|
1584
|
-
click.echo(f"Version: {step_type.get('version')}")
|
|
1585
|
-
click.echo(f"Name: {step_type.get('name')}")
|
|
1586
|
-
if step_type.get("description"):
|
|
1587
|
-
click.echo(f"Description: {step_type['description']}")
|
|
1588
|
-
|
|
1589
|
-
if step_type.get("settings_schema"):
|
|
1590
|
-
click.echo("\nSettings Schema:")
|
|
1591
|
-
click.echo(json.dumps(step_type["settings_schema"], indent=2))
|
|
1592
|
-
click.echo("")
|
|
1593
|
-
|
|
1594
|
-
except DatalabError as e:
|
|
1595
|
-
click.echo(f"Error: {e}", err=True)
|
|
1596
|
-
sys.exit(1)
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
@click.command()
|
|
1600
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1601
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1602
|
-
def list_workflows(api_key: Optional[str], base_url: str):
|
|
1603
|
-
"""[Deprecated: the API removed workflows] List all workflows for your team"""
|
|
1604
|
-
_echo_workflows_removed()
|
|
1605
|
-
try:
|
|
1606
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1607
|
-
workflows = client.list_workflows()
|
|
1608
|
-
|
|
1609
|
-
if not workflows:
|
|
1610
|
-
click.echo("No workflows found.")
|
|
1611
|
-
return
|
|
1612
|
-
|
|
1613
|
-
click.echo(f"Found {len(workflows)} workflow(s):\n")
|
|
1614
|
-
for workflow in workflows:
|
|
1615
|
-
click.echo(f" ID: {workflow.id}")
|
|
1616
|
-
click.echo(f" Name: {workflow.name}")
|
|
1617
|
-
click.echo(f" Team ID: {workflow.team_id}")
|
|
1618
|
-
click.echo(f" Steps: {len(workflow.steps)}")
|
|
1619
|
-
click.echo(f" Created: {workflow.created}")
|
|
1620
|
-
click.echo("")
|
|
1621
|
-
|
|
1622
|
-
except DatalabError as e:
|
|
1623
|
-
click.echo(f"Error: {e}", err=True)
|
|
1624
|
-
sys.exit(1)
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
@click.command()
|
|
1628
|
-
@click.option("--workflow_id", required=True, type=int, help="ID of the workflow")
|
|
1629
|
-
@click.option(
|
|
1630
|
-
"--input_config",
|
|
1631
|
-
required=True,
|
|
1632
|
-
help="JSON string or path to JSON file with input configuration",
|
|
1633
|
-
)
|
|
1634
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1635
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1636
|
-
def execute_workflow(
|
|
1637
|
-
workflow_id: int,
|
|
1638
|
-
input_config: str,
|
|
1639
|
-
api_key: Optional[str],
|
|
1640
|
-
base_url: str,
|
|
1641
|
-
):
|
|
1642
|
-
"""[Deprecated: the API removed workflows] Trigger a workflow execution"""
|
|
1643
|
-
_echo_workflows_removed()
|
|
1644
|
-
try:
|
|
1645
|
-
# Parse input_config from JSON string or file
|
|
1646
|
-
input_path = Path(input_config)
|
|
1647
|
-
if input_path.exists():
|
|
1648
|
-
with open(input_path, "r") as f:
|
|
1649
|
-
config_data = json.load(f)
|
|
1650
|
-
else:
|
|
1651
|
-
config_data = json.loads(input_config)
|
|
1652
|
-
|
|
1653
|
-
# Create InputConfig object
|
|
1654
|
-
input_cfg = InputConfig(
|
|
1655
|
-
file_urls=config_data.get("file_urls"),
|
|
1656
|
-
bucket=config_data.get("bucket"),
|
|
1657
|
-
prefix=config_data.get("prefix"),
|
|
1658
|
-
pattern=config_data.get("pattern"),
|
|
1659
|
-
storage_type=config_data.get("storage_type"),
|
|
1660
|
-
)
|
|
1661
|
-
|
|
1662
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1663
|
-
|
|
1664
|
-
click.echo(f"Triggering workflow execution for workflow {workflow_id}...")
|
|
1665
|
-
execution = client.execute_workflow(
|
|
1666
|
-
workflow_id=workflow_id,
|
|
1667
|
-
input_config=input_cfg,
|
|
1668
|
-
)
|
|
1669
|
-
|
|
1670
|
-
click.echo("\nSuccessfully triggered workflow execution!")
|
|
1671
|
-
click.echo(f" Execution ID: {execution.id}")
|
|
1672
|
-
click.echo(f" Status: {execution.status}")
|
|
1673
|
-
click.echo("\nTo check the status, run:")
|
|
1674
|
-
click.echo(f" datalab get-execution-status --execution_id {execution.id}")
|
|
1675
|
-
click.echo("\n Or poll until complete:")
|
|
1676
|
-
click.echo(
|
|
1677
|
-
f" datalab get-execution-status --execution_id {execution.id} --max_polls 300 --poll_interval 2"
|
|
1678
|
-
)
|
|
1679
|
-
|
|
1680
|
-
except DatalabError as e:
|
|
1681
|
-
click.echo(f"Error: {e}", err=True)
|
|
1682
|
-
sys.exit(1)
|
|
1683
|
-
except Exception as e:
|
|
1684
|
-
click.echo(f"Error: {e}", err=True)
|
|
1685
|
-
sys.exit(1)
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
@click.command()
|
|
1689
|
-
@click.option("--execution_id", required=True, type=int, help="ID of the execution")
|
|
1690
|
-
@click.option(
|
|
1691
|
-
"--output",
|
|
1692
|
-
"-o",
|
|
1693
|
-
type=click.Path(),
|
|
1694
|
-
help="Output file path to save execution results",
|
|
1695
|
-
)
|
|
1696
|
-
@click.option(
|
|
1697
|
-
"--max_polls",
|
|
1698
|
-
default=1,
|
|
1699
|
-
type=int,
|
|
1700
|
-
help="Maximum number of polling attempts (1 for single check)",
|
|
1701
|
-
)
|
|
1702
|
-
@click.option(
|
|
1703
|
-
"--poll_interval", default=1, type=int, help="Polling interval in seconds"
|
|
1704
|
-
)
|
|
1705
|
-
@click.option(
|
|
1706
|
-
"--download",
|
|
1707
|
-
is_flag=True,
|
|
1708
|
-
help="Download actual results from presigned URLs (default: just show URLs)",
|
|
1709
|
-
)
|
|
1710
|
-
@click.option("--api_key", required=False, help="Datalab API key")
|
|
1711
|
-
@click.option("--base_url", default=settings.DATALAB_HOST, help="API base URL")
|
|
1712
|
-
def get_execution_status(
|
|
1713
|
-
execution_id: int,
|
|
1714
|
-
output: Optional[str],
|
|
1715
|
-
max_polls: int,
|
|
1716
|
-
poll_interval: int,
|
|
1717
|
-
download: bool,
|
|
1718
|
-
api_key: Optional[str],
|
|
1719
|
-
base_url: str,
|
|
1720
|
-
):
|
|
1721
|
-
"""[Deprecated: the API removed workflows] Get the status of a workflow execution"""
|
|
1722
|
-
_echo_workflows_removed()
|
|
1723
|
-
try:
|
|
1724
|
-
client = DatalabClient(api_key=api_key, base_url=base_url)
|
|
1725
|
-
execution = client.get_execution_status(
|
|
1726
|
-
execution_id=execution_id,
|
|
1727
|
-
max_polls=max_polls,
|
|
1728
|
-
poll_interval=poll_interval,
|
|
1729
|
-
download_results=download,
|
|
1730
|
-
)
|
|
1731
|
-
|
|
1732
|
-
click.echo("Execution Status:")
|
|
1733
|
-
click.echo(f" Execution ID: {execution.id}")
|
|
1734
|
-
click.echo(f" Workflow ID: {execution.workflow_id}")
|
|
1735
|
-
click.echo(f" Status: {execution.status}")
|
|
1736
|
-
click.echo(f" Success: {execution.success}")
|
|
1737
|
-
click.echo(f" Created: {execution.created}")
|
|
1738
|
-
|
|
1739
|
-
if execution.steps:
|
|
1740
|
-
click.echo("\n Step Results:")
|
|
1741
|
-
for step_name, step_data in execution.steps.items():
|
|
1742
|
-
click.echo(f"\n [{step_name}]")
|
|
1743
|
-
|
|
1744
|
-
# Iterate through file_ids/aggregated keys
|
|
1745
|
-
for file_key, file_step_data in step_data.items():
|
|
1746
|
-
if isinstance(file_step_data, dict):
|
|
1747
|
-
click.echo(f"\n File/Group: {file_key}")
|
|
1748
|
-
click.echo(
|
|
1749
|
-
f" Step ID: {file_step_data.get('id', 'N/A')}"
|
|
1750
|
-
)
|
|
1751
|
-
click.echo(
|
|
1752
|
-
f" Status: {file_step_data.get('status', 'N/A')}"
|
|
1753
|
-
)
|
|
1754
|
-
|
|
1755
|
-
if file_step_data.get("started_at"):
|
|
1756
|
-
click.echo(
|
|
1757
|
-
f" Started: {file_step_data.get('started_at')}"
|
|
1758
|
-
)
|
|
1759
|
-
if file_step_data.get("finished_at"):
|
|
1760
|
-
click.echo(
|
|
1761
|
-
f" Finished: {file_step_data.get('finished_at')}"
|
|
1762
|
-
)
|
|
1763
|
-
if file_step_data.get("file_ids"):
|
|
1764
|
-
click.echo(
|
|
1765
|
-
f" Files: {', '.join(file_step_data.get('file_ids'))}"
|
|
1766
|
-
)
|
|
1767
|
-
|
|
1768
|
-
if "output_url" in file_step_data and not download:
|
|
1769
|
-
click.echo(
|
|
1770
|
-
f" Output URL: {file_step_data.get('output_url')}"
|
|
1771
|
-
)
|
|
1772
|
-
elif download and "downloaded_data" in file_step_data:
|
|
1773
|
-
click.echo(
|
|
1774
|
-
f" Results: {json.dumps(file_step_data['downloaded_data'], indent=12)}"
|
|
1775
|
-
)
|
|
1776
|
-
else:
|
|
1777
|
-
click.echo(f" {file_step_data}")
|
|
1778
|
-
|
|
1779
|
-
# Save output if requested
|
|
1780
|
-
if output:
|
|
1781
|
-
output_path = Path(output)
|
|
1782
|
-
output_path.parent.mkdir(parents=True, exist_ok=True)
|
|
1783
|
-
execution.save_output(output_path)
|
|
1784
|
-
click.echo(f"\nResults saved to: {output_path}")
|
|
1785
|
-
|
|
1786
|
-
except DatalabError as e:
|
|
1787
|
-
click.echo(f"Error: {e}", err=True)
|
|
1788
|
-
sys.exit(1)
|
|
1789
|
-
|
|
1790
|
-
|
|
1791
|
-
@click.command()
|
|
1792
|
-
@click.option(
|
|
1793
|
-
"--definition", required=True, help="Path to workflow definition JSON file"
|
|
1794
|
-
)
|
|
1795
|
-
def visualize_workflow(definition: str):
|
|
1796
|
-
"""Visualize workflow DAG from a JSON definition file"""
|
|
1797
|
-
try:
|
|
1798
|
-
import json
|
|
1799
|
-
from pathlib import Path
|
|
1800
|
-
from collections import defaultdict, deque
|
|
1801
|
-
|
|
1802
|
-
# Load workflow definition
|
|
1803
|
-
definition_path = Path(definition)
|
|
1804
|
-
if not definition_path.exists():
|
|
1805
|
-
raise DatalabError(f"Definition file not found: {definition}")
|
|
1806
|
-
|
|
1807
|
-
with open(definition_path, "r") as f:
|
|
1808
|
-
workflow_def = json.load(f)
|
|
1809
|
-
|
|
1810
|
-
name = workflow_def.get("name", "Unnamed Workflow")
|
|
1811
|
-
steps = workflow_def.get("steps", [])
|
|
1812
|
-
|
|
1813
|
-
if not steps:
|
|
1814
|
-
click.echo("No steps found in workflow definition")
|
|
1815
|
-
return
|
|
1816
|
-
|
|
1817
|
-
# Build dependency graph
|
|
1818
|
-
step_map = {step["unique_name"]: step for step in steps}
|
|
1819
|
-
|
|
1820
|
-
click.echo(f"\n{'=' * 70}")
|
|
1821
|
-
click.echo(f"Workflow: {name}")
|
|
1822
|
-
click.echo(f"{'=' * 70}\n")
|
|
1823
|
-
|
|
1824
|
-
# Build parent/child maps
|
|
1825
|
-
children = defaultdict(list)
|
|
1826
|
-
for step in steps:
|
|
1827
|
-
step_name = step["unique_name"]
|
|
1828
|
-
for dep in step.get("depends_on", []):
|
|
1829
|
-
children[dep].append(step_name)
|
|
1830
|
-
|
|
1831
|
-
# Topological sort to determine layers
|
|
1832
|
-
in_degree = {
|
|
1833
|
-
step["unique_name"]: len(step.get("depends_on", [])) for step in steps
|
|
1834
|
-
}
|
|
1835
|
-
layers = []
|
|
1836
|
-
queue = deque(
|
|
1837
|
-
[s["unique_name"] for s in steps if in_degree[s["unique_name"]] == 0]
|
|
1838
|
-
)
|
|
1839
|
-
|
|
1840
|
-
while queue:
|
|
1841
|
-
layer = []
|
|
1842
|
-
for _ in range(len(queue)):
|
|
1843
|
-
node = queue.popleft()
|
|
1844
|
-
layer.append(node)
|
|
1845
|
-
for child in children[node]:
|
|
1846
|
-
in_degree[child] -= 1
|
|
1847
|
-
if in_degree[child] == 0:
|
|
1848
|
-
queue.append(child)
|
|
1849
|
-
layers.append(layer)
|
|
1850
|
-
|
|
1851
|
-
# Render DAG as simple tree
|
|
1852
|
-
_render_dag_simple(layers, children, step_map)
|
|
1853
|
-
|
|
1854
|
-
click.echo(f"\nTotal steps: {len(steps)}")
|
|
1855
|
-
|
|
1856
|
-
except json.JSONDecodeError as e:
|
|
1857
|
-
click.echo(f"Invalid JSON: {e}", err=True)
|
|
1858
|
-
sys.exit(1)
|
|
1859
|
-
except KeyError as e:
|
|
1860
|
-
click.echo(f"Missing required field in workflow definition: {e}", err=True)
|
|
1861
|
-
sys.exit(1)
|
|
1862
|
-
except Exception as e:
|
|
1863
|
-
click.echo(f"Error: {e}", err=True)
|
|
1864
|
-
sys.exit(1)
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
def _render_dag_simple(layers, children, step_map):
|
|
1868
|
-
"""Simple DAG rendering with topological sort"""
|
|
1869
|
-
for layer_idx, layer in enumerate(layers):
|
|
1870
|
-
# Show layer info with color
|
|
1871
|
-
layer_info = f"Layer {layer_idx}"
|
|
1872
|
-
if layer_idx == 0:
|
|
1873
|
-
layer_info += " (start)"
|
|
1874
|
-
color = "green"
|
|
1875
|
-
elif layer_idx == len(layers) - 1:
|
|
1876
|
-
layer_info += " (end)"
|
|
1877
|
-
color = "red"
|
|
1878
|
-
elif len(layer) > 1:
|
|
1879
|
-
color = "yellow"
|
|
1880
|
-
else:
|
|
1881
|
-
color = "cyan"
|
|
1882
|
-
|
|
1883
|
-
click.echo(click.style(f"{layer_info}:", fg=color, bold=True))
|
|
1884
|
-
|
|
1885
|
-
for step_name in layer:
|
|
1886
|
-
step = step_map[step_name]
|
|
1887
|
-
step_key = step.get("step_key", "unknown")
|
|
1888
|
-
depends = step.get("depends_on", [])
|
|
1889
|
-
|
|
1890
|
-
# Show the step - color code by step type
|
|
1891
|
-
step_color = "blue" if "marker" in step_key else "magenta"
|
|
1892
|
-
click.echo(
|
|
1893
|
-
f" • {click.style(step_name, fg=step_color)} ({click.style(step_key, fg='white', dim=True)})"
|
|
1894
|
-
)
|
|
1895
|
-
|
|
1896
|
-
# Show dependencies if any
|
|
1897
|
-
if depends:
|
|
1898
|
-
click.echo(
|
|
1899
|
-
click.style(
|
|
1900
|
-
f" ← depends on: {', '.join(depends)}", fg="white", dim=True
|
|
1901
|
-
)
|
|
1902
|
-
)
|
|
1903
|
-
|
|
1904
|
-
# Show what comes next
|
|
1905
|
-
if layer_idx < len(layers) - 1:
|
|
1906
|
-
click.echo(click.style(" |", fg="white", dim=True))
|
|
1907
|
-
click.echo(click.style(" v", fg="white", dim=True))
|
|
1908
|
-
click.echo()
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
1478
|
# Add commands to CLI group
|
|
1912
1479
|
cli.add_command(login)
|
|
1913
1480
|
cli.add_command(logout)
|
|
@@ -1922,13 +1489,6 @@ cli.add_command(agent)
|
|
|
1922
1489
|
cli.add_command(create_document)
|
|
1923
1490
|
cli.add_command(compare_group)
|
|
1924
1491
|
cli.add_command(eval_group)
|
|
1925
|
-
cli.add_command(create_workflow)
|
|
1926
|
-
cli.add_command(get_workflow)
|
|
1927
|
-
cli.add_command(get_step_types)
|
|
1928
|
-
cli.add_command(list_workflows)
|
|
1929
|
-
cli.add_command(execute_workflow)
|
|
1930
|
-
cli.add_command(get_execution_status)
|
|
1931
|
-
cli.add_command(visualize_workflow)
|
|
1932
1492
|
|
|
1933
1493
|
if __name__ == "__main__":
|
|
1934
1494
|
cli()
|