Metadata-Version: 2.4
Name: gigabrain-faas
Version: 0.1.0
Summary: Python client and command line for the GigaBrain FaaS training API
Author: GigaBrain
License-Expression: Apache-2.0
Keywords: faas,robot,training,dataset,fine-tuning
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: httpx>=0.27
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == "dev"
Dynamic: license-file

# gigabrain-faas

Python client and command line for the GigaBrain FaaS training API: upload a
LeRobot dataset, validate it, submit a fine-tuning job, wait for it, and
download the model artifact.

The package depends only on `httpx`; it does not install the FaaS server.

```bash
pip install gigabrain-faas
```

## Configure

Two environment variables, or the matching constructor arguments:

| Variable | Meaning | Example |
|---|---|---|
| `FAAS_URL` | FaaS base URL | `https://192.168.18.2:11074` |
| `FAAS_API_KEY` | API key (`faas_...`) | `faas_...` |

The CLI also accepts `--url` and `--api-key`.

**Getting an API key.** Sign in to the FaaS web console, open `/help/api`, and
use the key form on that page (the form posts to `/help/api/keys`). The key is
shown once. API-key management requires a login session; an API key cannot mint
another API key.

## Quick start

```python
from gigabrain_faas import FaasClient

with FaasClient() as client:  # reads FAAS_URL / FAAS_API_KEY
    profile = client.create_profile("h01-default", "h01_16dim")
    dataset = client.upload_dataset("./my_dataset", profile["id"])
    client.validate_dataset(dataset["id"])

    job = client.submit_job(dataset["id"], profile["id"], "v1", steps=20000)
    if job["status"] == "pending_approval":
        client.approve_job(job["id"])  # owners and admins only

    final = client.wait_for_job(job["id"], timeout=6 * 3600)
    if final["status"] != "succeeded":
        raise SystemExit(final["message"])

    client.download_artifact(final["artifact"]["id"], "./out")
```

## What each call maps to

| Client method | Endpoint |
|---|---|
| `list_layouts` | `GET /api/v1/layouts` |
| `create_profile` / `list_profiles` / `get_profile` | `/api/v1/profiles` |
| `create_dataset` / `upload_dataset` | `POST /api/v1/datasets` |
| `upload_dataset_chunked` | `/api/v1/datasets/multipart*` |
| `import_dataset` | `POST /api/v1/datasets/import` |
| `validate_dataset` | `POST /api/v1/datasets/{id}/validate` |
| `list_datasets` / `get_dataset` / `delete_dataset` / `erase_dataset` | `/api/v1/datasets*` |
| `submit_job` / `list_jobs` / `get_job` / `job_logs` | `/api/v1/jobs*` |
| `approve_job` / `reject_job` / `retry_job` / `cancel_job` | `/api/v1/jobs/{id}/*` |
| `list_artifacts` / `get_artifact` / `get_manifest` / `download_artifact` | `/api/v1/artifacts*` |
| `delete_artifact` / `erase_artifact` | `/api/v1/artifacts/{id}*` |

List calls accept `limit` (default 50, max 200) and `offset`.

### Large uploads

`upload_dataset` zips a local directory and sends it in one multipart request.
For large datasets use the chunked flow, which uploads 64 MiB parts directly to
object storage:

```python
client.upload_dataset_chunked(
    "dataset.zip",
    profile["id"],
    concurrency=4,
    on_progress=lambda done, total: print(f"{done / total:.0%}"),
)
```

This requires the server to be configured with the `tos` object store; a plain
server answers HTTP 503.

## Command line

```bash
export FAAS_URL=https://192.168.18.2:11074
export FAAS_API_KEY=faas_...

gb-faas layout-list
gb-faas profile-create h01-default --layout h01_16dim
gb-faas dataset-upload ./my_dataset --profile-id prf_...
gb-faas dataset-validate ds_...
gb-faas job-submit --dataset-id ds_... --profile-id prf_... --suffix v1
gb-faas job-wait job_... --timeout 21600
gb-faas artifact-download art_... -o ./out
```

`gigabrain-faas` is an alias for `gb-faas`. Run `gb-faas --help` for the full
command list.

## Errors

All errors derive from `FaasError`:

| Exception | Raised when |
|---|---|
| `FaasHTTPError` | the server answered non-2xx; see `.status_code`, `.detail`, `.retry_after` |
| `FaasConnectionError` | the host could not be reached |
| `FaasTimeoutError` | a request timed out, or `wait_for_job` exceeded `timeout` |

`FaasHTTPError.detail` keeps the raw FastAPI `detail`: a string in most cases,
a list for 422 validation errors, and a dict for erase conflicts.

## License

Apache-2.0. See `LICENSE`.
