Add Dataset Library backend: curate, upload, train custom AI art models - #5
Merged
Merged
Conversation
Item 1 of the platform build backlog (design spec: Step 8 of the published design brief). Creators can now upload or import their own images/video, curate them into a named dataset with a rights declaration, and train a custom AI art model against the existing fal_custom render-model lane — closing the gap between "the model registry supports creator-trained models" and "a creator can actually produce one here." - migrations/0020_dataset_library.sql: datasets, dataset_items (content-hash deduped, exact-match only — perceptual near-dup detection is an explicit v2 cut, not a silent gap), training_jobs (queued -> training -> succeeded/failed, mirroring the render_jobs lifecycle already in the token ledger). - src/db/datasets.ts: CRUD + the item_count denormalisation kept in sync via the same D1 batch as each insert/delete, not a trigger. - src/ai/training.ts: fal.ai queue-API dispatch/poll for real training (submit -> request_id -> status -> result), wired into the existing per-minute cron tick. Only ONE base model is verified end-to-end today (FLUX.1 [dev] via flux-lora-fast-training / flux-lora) — requesting any other base_model is rejected at the handler with a clear error rather than silently hitting a guessed endpoint slug. TRAINING_MOCK (opt-in, same convention as RENDER_MOCK/PINNING_MOCK/ GITHUB_MOCK; production must never set it) completes a job synchronously in-request instead of simulating cron timing. - src/datasets/handlers.ts: dataset CRUD, item upload (data URL, R2-backed, exact-dedup) and URL-list import (per-item success/fail reporting, never all-or-nothing), and the train endpoint (debit-before-enqueue, insufficient-balance guard, an eager private render_models shell so the job has somewhere to publish a version onto the moment training succeeds). - LoRA training is priced at 150 tokens — deliberately inside the 200-token signup grant, so a new creator's free grant covers one training run, not just renders of others' models. - 6 new unit tests (rights/visibility/kind validators, the trainable- base-model allowlist, tiered pricing) — 33/33 pass. 24 new smoke checks (create/list/patch, upload + exact-dedup, unsupported-mime rejection, import-urls validation, item delete + count integrity, the full train-to-published-model path under TRAINING_MOCK, private- dataset isolation) — 136/136 pass. Typecheck clean; wrangler deploy --dry-run clean on both environments. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QuSa99HABSrWRarT9BQ5Tz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Item 1 of the platform build backlog (spec: Step 8 of the published design brief). Creators can now upload or import their own images/video, curate them into a named dataset with a rights declaration, and train a custom AI art model against the existing
fal_customrender-model lane — closing the gap between "the model registry supports creator-trained models" and "a creator can actually produce one here."Changes
migrations/0020_dataset_library.sql:datasets,dataset_items(content-hash deduped — exact-match only; perceptual near-dup detection is an explicit v2 cut, not a silent gap),training_jobs(queued→training→succeeded/failed, mirroring therender_jobslifecycle already in the token ledger).src/db/datasets.ts: CRUD + theitem_countdenormalisation kept in sync via the same D1 batch as each insert/delete, not a trigger.src/ai/training.ts: fal.ai queue-API dispatch/poll for real training (submit → request_id → status → result), wired into the existing per-minute cron tick. Only one base model is verified end-to-end today (FLUX.1 [dev] viaflux-lora-fast-training/flux-lora) — requesting any otherbase_modelis rejected at the handler with a clear error rather than silently hitting a guessed endpoint slug.TRAINING_MOCK(opt-in, same convention asRENDER_MOCK/PINNING_MOCK/GITHUB_MOCK; production must never set it) completes a job synchronously in-request instead of simulating cron timing.src/datasets/handlers.ts: dataset CRUD, item upload (data URL, R2-backed, exact-dedup) and URL-list import (per-item success/fail reporting, never all-or-nothing), and the train endpoint (debit-before-enqueue, insufficient-balance guard, an eager privaterender_modelsshell so the job has somewhere to publish a version onto the moment training succeeds).Testing
TRAINING_MOCK, private-dataset isolation) — 136/136 pass.wrangler deploy --dry-runclean on both environments.Known scope cuts (deliberate, called out in code comments)
private/public) is stored but there's no cross-owner public dataset browsing surface yet —GET /v1/datasets/:slugis owner-only for now (slugs are unique per-owner, not globally).🤖 Generated with Claude Code
https://claude.ai/code/session_01QuSa99HABSrWRarT9BQ5Tz
Generated by Claude Code