From 64f7653d506db088f9acd41e556810faa42d758e Mon Sep 17 00:00:00 2001 From: 0xBitBuster Date: Fri, 27 Nov 2026 14:31:51 +0100 Subject: [PATCH] Add live outfits and prepare-garment overrides (2.2.0) - prepareLiveOutfit combines 2-3 prepared garments into one outfit whose id works wherever a garment id does. - prepareLiveGarment accepts detail images, a description, custom instructions and enhance_prompt. - LiveGarment gains prompt, enhancePrompt and items. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 14 +++ README.md | 36 +++++++ pyproject.toml | 2 +- tests/fixtures/sdk-cases.json | 183 +++++++++++++++++++++++++++++++++- tests/test_contract.py | 6 ++ tryiton/__init__.py | 2 +- tryiton/client.py | 49 ++++++++- tryiton/types.py | 7 +- 8 files changed, 288 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0481f5..04b754b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,20 @@ All notable changes to the `tryiton` Python SDK are documented here. The format ## [Unreleased] +## [2.2.0] - 2026-11-27 + +### Added + +- `prepare_live_garment()` takes four optional keyword overrides: `detail_images` (up to 3 extra views that only + sharpen the description), `description` (your own item description, max 200 chars, used inside the generated + prompt), `instructions` (your own prompt, max 1000 chars, used verbatim) and `enhance_prompt` (`False` turns off the + stream's prompt rewriting; the API defaults to `True`). +- `prepare_live_outfit(garment_ids, *, instructions=None, enhance_prompt=None)` combines 2-3 prepared garments into + one outfit (`POST /live/outfits`). Its `id` works wherever a garment id does: `start_live_session(garment_id=...)` + and the browser's `switchGarment`. +- `LiveGarment` gains `prompt`, `enhancePrompt` and `items` (an outfit's garment ids top to bottom, else `None`). + `category` can be `"outfit"`. + ### Deprecated - `try_on_fashion(mode=..., moderation_level=...)`: the API ignores `mode` and validates `moderation_level` without applying it. Passing either now emits a `DeprecationWarning`; both are removed in 3.0. diff --git a/README.md b/README.md index d68abf0..6e2e314 100644 --- a/README.md +++ b/README.md @@ -94,6 +94,42 @@ client.get_live_config() # {"enabled", "secondsPerCredi Billing is per `secondsPerCredit` seconds of streamed video, from the first try-on frame. Garment switches during a session are free. +`prepare_live_garment` also takes optional overrides: + +```python +client.prepare_live_garment( + product_image_url, + category="footwear", + detail_images=[side_view_url, back_view_url], # up to 3 extra views; they only sharpen the description + description="black leather knee-high boots", # your description (max 200), used in the generated prompt + instructions="Replace only the shoes with the boots.", # or your own prompt (max 1000), used verbatim + enhance_prompt=False, # keep the prompt as-is (default True) +) +``` + +### Outfits + +Combine 2-3 prepared garments into one outfit worn together. The outfit's `id` works wherever a garment id does +(`start_live_session`, the browser's `switchGarment`). To swap one item, prepare the new combination (cached) and +switch to it. + +```python +top = client.prepare_live_garment(shirt_url, category="clothing", subcategory="tops") +trousers = client.prepare_live_garment(trousers_url, category="clothing", subcategory="bottoms") +shoes = client.prepare_live_garment(shoes_url, category="footwear") + +outfit = client.prepare_live_outfit([top["id"], trousers["id"], shoes["id"]]) +# outfit["category"] == "outfit", outfit["items"] = the garment ids top to bottom +start = client.start_live_session(garment_id=outfit["id"], end_user_id=shopper_id) + +# Later the shopper picks another top: prepare that outfit and switch the running stream to it. +jacket = client.prepare_live_garment(jacket_url, category="clothing", subcategory="tops") +next_outfit = client.prepare_live_outfit([jacket["id"], trousers["id"], shoes["id"]]) +# Send next_outfit["id"] to the browser, which calls live.switchGarment(id) (tryiton-live). +``` + +`prepare_live_outfit` also takes `instructions` and `enhance_prompt`, as above. + ## Error handling All failures raise `TryItOnError`, which carries the HTTP status code and the API error name. diff --git a/pyproject.toml b/pyproject.toml index 25cc2fa..6e28dde 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "tryiton" -version = "2.1.0" +version = "2.2.0" description = "Official Python SDK for the TryItOn virtual try-on API." readme = "README.md" requires-python = ">=3.8" diff --git a/tests/fixtures/sdk-cases.json b/tests/fixtures/sdk-cases.json index 9aced2c..3a99d3d 100644 --- a/tests/fixtures/sdk-cases.json +++ b/tests/fixtures/sdk-cases.json @@ -157,13 +157,189 @@ "responses": [ { "status": 201, - "body": { "ok": true, "garment": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "createdAt": "2026-11-26T12:20:59.512Z" } } + "body": { "ok": true, "garment": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "prompt": "Substitute the current top with a navy polo shown in the reference image, matching its color, material, and fit.", "enhancePrompt": true, "items": null, "createdAt": "2026-11-26T12:20:59.512Z" } } } ], "expectRequests": [ { "method": "POST", "path": "/live/garments", "body": { "garment_image": "https://example.com/shirt.jpg", "category": "clothing", "subcategory": "tops" } } ], - "expectResult": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "createdAt": "2026-11-26T12:20:59.512Z" } + "expectResult": { "id": "g1", "category": "clothing", "subcategory": "tops", "description": "a navy polo", "prompt": "Substitute the current top with a navy polo shown in the reference image, matching its color, material, and fit.", "enhancePrompt": true, "items": null, "createdAt": "2026-11-26T12:20:59.512Z" } + }, + { + "name": "prepareLiveGarment with every override", + "method": "prepareLiveGarment", + "params": { + "garmentImage": "https://example.com/look.jpg", + "category": "footwear", + "detailImages": [ + "https://example.com/boots-side.jpg", + "data:image/png;base64,AAAA" + ], + "description": "black leather knee-high boots", + "instructions": "Replace only the shoes with the boots.", + "enhancePrompt": false + }, + "responses": [ + { + "status": 201, + "body": { + "ok": true, + "garment": { + "id": "g2", + "category": "footwear", + "subcategory": null, + "description": "black leather knee-high boots", + "prompt": "Replace only the shoes with the boots.", + "enhancePrompt": false, + "items": null, + "createdAt": "2026-11-26T12:20:59.512Z" + } + } + } + ], + "expectRequests": [ + { + "method": "POST", + "path": "/live/garments", + "body": { + "garment_image": "https://example.com/look.jpg", + "category": "footwear", + "detail_images": [ + "https://example.com/boots-side.jpg", + "data:image/png;base64,AAAA" + ], + "description": "black leather knee-high boots", + "instructions": "Replace only the shoes with the boots.", + "enhance_prompt": false + } + } + ], + "expectResult": { + "id": "g2", + "category": "footwear", + "subcategory": null, + "description": "black leather knee-high boots", + "prompt": "Replace only the shoes with the boots.", + "enhancePrompt": false, + "items": null, + "createdAt": "2026-11-26T12:20:59.512Z" + } + }, + { + "name": "prepareLiveOutfit returns the outfit", + "method": "prepareLiveOutfit", + "params": { + "garmentIds": [ + "g1", + "g3" + ] + }, + "responses": [ + { + "status": 201, + "body": { + "ok": true, + "outfit": { + "id": "o1", + "category": "outfit", + "subcategory": null, + "description": "a navy polo, black jeans", + "prompt": "Substitute the current top with a navy polo shown at the top and the current pants with black jeans shown at the bottom of the reference image, matching each item's color, material, and fit.", + "enhancePrompt": true, + "items": [ + "g1", + "g3" + ], + "createdAt": "2026-11-26T12:24:10.031Z" + } + } + } + ], + "expectRequests": [ + { + "method": "POST", + "path": "/live/outfits", + "body": { + "garment_ids": [ + "g1", + "g3" + ] + } + } + ], + "expectResult": { + "id": "o1", + "category": "outfit", + "subcategory": null, + "description": "a navy polo, black jeans", + "prompt": "Substitute the current top with a navy polo shown at the top and the current pants with black jeans shown at the bottom of the reference image, matching each item's color, material, and fit.", + "enhancePrompt": true, + "items": [ + "g1", + "g3" + ], + "createdAt": "2026-11-26T12:24:10.031Z" + } + }, + { + "name": "prepareLiveOutfit with overrides", + "method": "prepareLiveOutfit", + "params": { + "garmentIds": [ + "g1", + "g3" + ], + "instructions": "Dress them in the polo and jeans.", + "enhancePrompt": false + }, + "responses": [ + { + "status": 200, + "body": { + "ok": true, + "outfit": { + "id": "o1", + "category": "outfit", + "subcategory": null, + "description": "a navy polo, black jeans", + "prompt": "Dress them in the polo and jeans.", + "enhancePrompt": false, + "items": [ + "g1", + "g3" + ], + "createdAt": "2026-11-26T12:24:10.031Z" + } + } + } + ], + "expectRequests": [ + { + "method": "POST", + "path": "/live/outfits", + "body": { + "garment_ids": [ + "g1", + "g3" + ], + "instructions": "Dress them in the polo and jeans.", + "enhance_prompt": false + } + } + ], + "expectResult": { + "id": "o1", + "category": "outfit", + "subcategory": null, + "description": "a navy polo, black jeans", + "prompt": "Dress them in the polo and jeans.", + "enhancePrompt": false, + "items": [ + "g1", + "g3" + ], + "createdAt": "2026-11-26T12:24:10.031Z" + } }, { "name": "startLiveSession returns the whole response unchanged", @@ -194,6 +370,9 @@ "category": "clothing", "subcategory": "tops", "description": null, + "prompt": "p", + "enhancePrompt": true, + "items": null, "createdAt": "2026-11-26T12:20:59.512Z", "input": { "prompt": "p", "enhancePrompt": true, "referenceImage": "data:image/jpeg;base64,AA" } } diff --git a/tests/test_contract.py b/tests/test_contract.py index ebec380..7b9cbd3 100644 --- a/tests/test_contract.py +++ b/tests/test_contract.py @@ -28,6 +28,7 @@ "waitForResult": "wait_for_result", "getLiveConfig": "get_live_config", "prepareLiveGarment": "prepare_live_garment", + "prepareLiveOutfit": "prepare_live_outfit", "startLiveSession": "start_live_session", "getLiveSession": "get_live_session", "stopLiveSession": "stop_live_session", @@ -55,6 +56,11 @@ "maxSeconds": "max_seconds", "endUserId": "end_user_id", "allowedOrigin": "allowed_origin", + "detailImages": "detail_images", + "description": "description", + "instructions": "instructions", + "enhancePrompt": "enhance_prompt", + "garmentIds": "garment_ids", } # Extra kwargs per method, so polling cases run instantly. diff --git a/tryiton/__init__.py b/tryiton/__init__.py index cebe251..2e55d5f 100644 --- a/tryiton/__init__.py +++ b/tryiton/__init__.py @@ -35,4 +35,4 @@ "LiveSessionStart", ] # Single source of the SDK version (sent in the User-Agent); keep it equal to pyproject.toml. -__version__ = "2.1.0" +__version__ = "2.2.0" diff --git a/tryiton/client.py b/tryiton/client.py index a5188c8..cdccc96 100644 --- a/tryiton/client.py +++ b/tryiton/client.py @@ -202,25 +202,64 @@ def prepare_live_garment( *, category: Optional[str] = None, subcategory: Optional[str] = None, + detail_images: Optional[List[str]] = None, + description: Optional[str] = None, + instructions: Optional[str] = None, + enhance_prompt: Optional[bool] = None, ) -> LiveGarment: """Prepare a garment for live try-on. Returns the garment dict. Do it once per product ahead of time (e.g. at catalog sync): it's cached - per image and category, so starting a session or switching garments - later is instant. `garment_image` is a URL or base64 data URL. Passing - `category` (and `subcategory`, e.g. "tops") is recommended; omit it to - let it be detected. + per image, category and overrides, so starting a session or switching + garments later is instant. `garment_image` is a URL or base64 data URL. + Passing `category` (and `subcategory`, e.g. "tops") is recommended; omit + it to let it be detected. + + Optional overrides: `detail_images` is up to 3 extra views (URLs or data + URLs) that only sharpen the description. `description` (max 200 chars) + is your own item description, used inside the generated prompt. + `instructions` (max 1000 chars) is your own prompt, used verbatim + instead of the generated one. `enhance_prompt=False` stops the stream + from rewriting the prompt (the API defaults to True). The dict has ``id`` (pass it to start_live_session), ``category``, - ``subcategory``, ``description`` and ``createdAt``. + ``subcategory``, ``description``, ``prompt``, ``enhancePrompt``, + ``items`` (None for a single garment) and ``createdAt``. """ body = { "garment_image": garment_image, "category": category, "subcategory": subcategory, + "detail_images": detail_images, + "description": description, + "instructions": instructions, + "enhance_prompt": enhance_prompt, } return cast(LiveGarment, self._request("POST", "/live/garments", body)["garment"]) + def prepare_live_outfit( + self, + garment_ids: List[str], + *, + instructions: Optional[str] = None, + enhance_prompt: Optional[bool] = None, + ) -> LiveGarment: + """Combine 2-3 prepared garments into one outfit worn together. + + Returns the outfit as a garment dict with ``category`` "outfit" and + ``items`` = the garment ids top to bottom. Its ``id`` works wherever a + garment id does (start_live_session, the browser's switchGarment). + It's cached per set of garments and overrides, so swapping one item is + preparing the new set and switching to it. `instructions` and + `enhance_prompt` work as in prepare_live_garment. + """ + body = { + "garment_ids": list(garment_ids), + "instructions": instructions, + "enhance_prompt": enhance_prompt, + } + return cast(LiveGarment, self._request("POST", "/live/outfits", body)["outfit"]) + def start_live_session( self, *, diff --git a/tryiton/types.py b/tryiton/types.py index c0a86b4..c04f6f5 100644 --- a/tryiton/types.py +++ b/tryiton/types.py @@ -42,12 +42,15 @@ class LiveConfig(TypedDict): class LiveGarment(TypedDict): - """A garment prepared for live try-on.""" + """A garment (or outfit) prepared for live try-on.""" id: str - category: str + category: str # the item's category, or "outfit" for a prepare_live_outfit result subcategory: Optional[str] description: Optional[str] + prompt: str # the prompt the stream uses + enhancePrompt: bool # whether the stream rewrites `prompt` + items: Optional[List[str]] # an outfit's garment ids, top to bottom; None for a single garment createdAt: str # ISO 8601