Archived
added phase 5 rfactor to yaml workflow definitions to include a component property for the frontend
This commit is contained in:
1 parent
2f4bca6e78
commit
59ff3365e9
1 file changed
+208
-14
@@ -337,18 +337,20 @@ Properties are sourced from three places:
|
||||
|
||||
### All Fields
|
||||
|
||||
| Property | Source | Description |
|
||||
| ------------- | ----------------- | --------------------------------------------------------------------- |
|
||||
| `name` | auto (code) | Field name from WorkflowParams |
|
||||
| `label` | auto (code) | Generated from field name, customizable |
|
||||
| `type` | auto (annotation) | UI type: text, int, float, bool, enum, model, model_with_params, seed |
|
||||
| `category` | auto (annotation) | UI grouping: prompts, models, parameters, composition, advanced |
|
||||
| `required` | auto (code) | True if field has no default value |
|
||||
| `default` | auto (code) | Default value from Python |
|
||||
| `description` | manual | Help text shown in UI |
|
||||
| `depends_on` | manual | Conditional visibility based on other fields |
|
||||
| Property | Source | Description |
|
||||
| ------------- | ----------------- | --------------------------------------------------------------- |
|
||||
| `name` | auto (code) | Field name from WorkflowParams |
|
||||
| `label` | auto (code) | Generated from field name, customizable |
|
||||
| `type` | auto (code) | **Data type:** int, float, str, bool, object |
|
||||
| `component` | auto (annotation) | **UI component:** seed, prompt, model, select, etc. (optional) |
|
||||
| `category` | auto (annotation) | UI grouping: prompts, models, parameters, composition, advanced |
|
||||
| `required` | auto (code) | True if field has no default value |
|
||||
| `default` | auto (code) | Default value from Python |
|
||||
| `multiple` | auto (code) | True if Python type is `List[*]` |
|
||||
| `description` | manual | Help text shown in UI |
|
||||
| `depends_on` | manual | Conditional visibility based on other fields |
|
||||
|
||||
### type: text
|
||||
### type: str (text fields)
|
||||
|
||||
| Property | Source | Description |
|
||||
| ------------- | ----------------- | ---------------------------------- |
|
||||
@@ -364,16 +366,15 @@ Properties are sourced from three places:
|
||||
| `max` | auto (annotation) | Maximum value (from `le`) |
|
||||
| `step` | auto (annotation) | Step increment (from `multiple_of`) |
|
||||
|
||||
### type: enum / model / model_with_params
|
||||
### component: select / model / model_with_params
|
||||
|
||||
| Property | Source | Description |
|
||||
| ---------------- | ----------------- | ------------------------------------------------------------ |
|
||||
| `options_source` | auto (annotation) | Resource key: samplers, schedulers, checkpoints, loras, etc. |
|
||||
| `searchable` | manual | Show search filter in dropdown |
|
||||
| `multiple` | auto (code) | True if Python type is `List[*]` |
|
||||
| `max_selections` | manual | Limit selections (omit for unlimited) |
|
||||
|
||||
### type: model_with_params
|
||||
### component: model_with_params
|
||||
|
||||
| Property | Source | Description |
|
||||
| -------- | ----------- | --------------------------------------- |
|
||||
@@ -506,3 +507,196 @@ def run_workflow(**kwargs):
|
||||
|
||||
10. **Future types**
|
||||
- Add `image`, `mask`, `color` types as needed
|
||||
|
||||
### Phase 5: Type/Component Separation
|
||||
|
||||
Separate data type (`type`) from UI component (`component`) for cleaner architecture.
|
||||
|
||||
**Problem:** Currently `type` conflates data structure with UI rendering:
|
||||
|
||||
- `type: seed` - Is it an int? How should it render?
|
||||
- `type: model` - Is it a string? A list?
|
||||
|
||||
**Solution:** Split into two properties:
|
||||
|
||||
- `type` - The semantic data type (int, float, str, bool, enum, object)
|
||||
- `component` - The frontend component to render (seed, model, prompt, select, etc.)
|
||||
|
||||
**Key Insight:** If a field has `options_source`, it's a selection from a list, not free text:
|
||||
|
||||
- `options_source` present → `type: enum` (even if Python type is `str`)
|
||||
- This tells frontend to render a select/dropdown, not a text input
|
||||
|
||||
11. **Update `parameters.py` annotations**
|
||||
- Change `ui_type` to `component` in `json_schema_extra`
|
||||
- Keep `options_source` for resource-based selections
|
||||
|
||||
```python
|
||||
# Seed - int with special UI
|
||||
Seed = Annotated[int, Field(
|
||||
json_schema_extra={"component": "seed", "category": "parameters"}
|
||||
)]
|
||||
# Generated: type: int, component: seed
|
||||
|
||||
# Sampler - selection from list (NOT free text)
|
||||
Sampler = Annotated[str, Field(
|
||||
json_schema_extra={"component": "sampler", "options_source": "samplers", "category": "parameters"}
|
||||
)]
|
||||
# Generated: type: enum, component: sampler, options_source: samplers
|
||||
|
||||
# Checkpoints - multiple selection from list
|
||||
Checkpoint = Annotated[List[str], Field(
|
||||
json_schema_extra={"component": "checkpoints", "options_source": "checkpoints", "category": "models"}
|
||||
)]
|
||||
# Generated: type: enum, multiple: true, component: checkpoints, options_source: checkpoints
|
||||
```
|
||||
|
||||
12. **Update `schema_generator.py` type inference**
|
||||
|
||||
```python
|
||||
def infer_type(python_type, field_info, json_extra) -> str:
|
||||
"""Infer YAML type from Python type and metadata."""
|
||||
|
||||
# If has options_source, it's a selection (enum), not free text
|
||||
if json_extra.get("options_source"):
|
||||
return "enum"
|
||||
|
||||
# If has params, it's a complex object
|
||||
if json_extra.get("params") or has_parameters_class(python_type):
|
||||
return "object"
|
||||
|
||||
# Otherwise, infer from Python type
|
||||
origin = get_origin(python_type)
|
||||
if origin is list:
|
||||
inner = get_args(python_type)[0]
|
||||
return infer_type(inner, field_info, json_extra)
|
||||
|
||||
type_map = {
|
||||
int: "int",
|
||||
float: "float",
|
||||
str: "str",
|
||||
bool: "bool",
|
||||
}
|
||||
return type_map.get(python_type, "str")
|
||||
```
|
||||
|
||||
13. **Update YAML generation**
|
||||
- `type` = semantic data type (enum for selections, int/float/str/bool for primitives, object for complex)
|
||||
- `component` = explicit UI component (optional)
|
||||
- `multiple` = true if Python type is `List[*]`
|
||||
|
||||
14. **Regenerate all YAML files**
|
||||
- Run `python -m external-api generate --all`
|
||||
|
||||
**Updated YAML Format:**
|
||||
|
||||
```yaml
|
||||
parameters:
|
||||
# Seed - int with custom component
|
||||
- name: seed
|
||||
type: int # Primitive data type
|
||||
component: seed # Custom UI component
|
||||
category: parameters
|
||||
required: true
|
||||
label: Seed
|
||||
|
||||
# Sampler - enum (selection from options_source)
|
||||
- name: sampler
|
||||
type: enum # Selection type (has options_source)
|
||||
component: sampler # Custom UI component (optional)
|
||||
options_source: samplers # Where to get options
|
||||
category: parameters
|
||||
default: euler
|
||||
searchable: true
|
||||
label: Sampler
|
||||
|
||||
# Scheduler - enum (selection from options_source)
|
||||
- name: scheduler
|
||||
type: enum # Selection type
|
||||
component: scheduler # Custom UI component (optional)
|
||||
options_source: schedulers
|
||||
category: parameters
|
||||
default: normal
|
||||
label: Scheduler
|
||||
|
||||
# Checkpoints - enum array (multiple selection)
|
||||
- name: checkpoints
|
||||
type: enum # Selection type
|
||||
multiple: true # List[str] → multiple selections
|
||||
component: checkpoints # Custom UI component
|
||||
options_source: checkpoints
|
||||
category: models
|
||||
required: true
|
||||
label: Checkpoints
|
||||
|
||||
# LoRAs - object array (complex with params)
|
||||
- name: loras
|
||||
type: object # Complex type (has params)
|
||||
multiple: true
|
||||
component: loras # Custom UI component
|
||||
options_source: loras
|
||||
category: models
|
||||
label: LoRAs
|
||||
params:
|
||||
- name: strength_model
|
||||
type: float
|
||||
default: 1.0
|
||||
- name: strength_clip
|
||||
type: float
|
||||
default: 1.0
|
||||
|
||||
# Prompt - str with custom component
|
||||
- name: prompt
|
||||
type: str # Free text (no options_source)
|
||||
component: prompt # Custom UI component
|
||||
category: prompts
|
||||
required: true
|
||||
multiline: true
|
||||
rows: 4
|
||||
label: Prompt
|
||||
|
||||
# Steps - int with constraints (NO custom component)
|
||||
- name: steps
|
||||
type: int
|
||||
category: parameters
|
||||
min: 1
|
||||
max: 150
|
||||
default: 20
|
||||
label: Steps
|
||||
# No component = frontend uses generic SliderField (int with min/max)
|
||||
|
||||
# Loopback - bool (NO custom component)
|
||||
- name: loopback
|
||||
type: bool
|
||||
category: advanced
|
||||
default: false
|
||||
label: Enable Loopback
|
||||
# No component = frontend uses generic ToggleField
|
||||
```
|
||||
|
||||
**Component Resolution (Frontend):**
|
||||
|
||||
| Priority | Check | Example |
|
||||
| -------- | ------------------------- | ------------------------------------------- |
|
||||
| 1 | `component` property | `component: "seed"` → SeedField |
|
||||
| 2 | `options_source` property | `options_source: "samplers"` → SamplerField |
|
||||
| 3 | `type` + constraints | `type: "int"` + min/max → SliderField |
|
||||
| 4 | `type` only | `type: "bool"` → ToggleField |
|
||||
|
||||
**Type Inference Rules (Backend):**
|
||||
|
||||
| Condition | Inferred `type` |
|
||||
| -------------------------------- | ---------------------------- |
|
||||
| Has `options_source` | `enum` |
|
||||
| Has `params` (model_with_params) | `object` |
|
||||
| Python `int` | `int` |
|
||||
| Python `float` | `float` |
|
||||
| Python `str` (no options_source) | `str` |
|
||||
| Python `bool` | `bool` |
|
||||
| Python `List[T]` | type of T + `multiple: true` |
|
||||
|
||||
**Files to modify:**
|
||||
|
||||
- `parameters.py` - Change `ui_type` → `component`
|
||||
- `schema_generator.py` - Update type inference (options_source → enum)
|
||||
- All workflow YAML files - Regenerate
|
||||
Reference in new issue
Block a user