Archived
102 lines
1.9 KiB
Markdown
102 lines
1.9 KiB
Markdown
# External API Custom Node
|
|
|
|
REST API endpoints for executing ComfyScript workflows.
|
|
|
|
## Structure
|
|
|
|
```
|
|
external-api/
|
|
├── __init__.py # Main entry point, registers routes
|
|
├── progress.py # Progress hook utilities
|
|
├── routes.py # API endpoint definitions
|
|
├── workflows.py # Workflow registry
|
|
└── workflows/ # Individual workflow scripts
|
|
├── test.py
|
|
└── example_image_gen.py
|
|
```
|
|
|
|
## Adding New Workflows
|
|
|
|
1. Create a new file in `workflows/` folder (e.g., `my_workflow.py`)
|
|
2. Define a `run_workflow(**kwargs)` function
|
|
3. Import and register it in `workflows.py`:
|
|
|
|
```python
|
|
# In workflows.py
|
|
my_workflow = load_workflow_module("my_workflow")
|
|
|
|
WORKFLOWS = {
|
|
"my_workflow": my_workflow.run_workflow,
|
|
# ... other workflows
|
|
}
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### List Available Workflows
|
|
|
|
```
|
|
GET /external-api/workflows
|
|
```
|
|
|
|
### Execute Workflow
|
|
|
|
```
|
|
POST /external-api/workflow/{workflow_name}
|
|
Content-Type: application/json
|
|
|
|
{
|
|
"prompt": "a beautiful landscape",
|
|
"steps": 20,
|
|
"seed": 12345
|
|
}
|
|
```
|
|
|
|
### Test Endpoint
|
|
|
|
```
|
|
GET /external-api/hello
|
|
```
|
|
|
|
## Example Usage
|
|
|
|
```bash
|
|
# List workflows
|
|
curl http://localhost:8188/external-api/workflows
|
|
|
|
# Execute test workflow
|
|
curl -X POST http://localhost:8188/external-api/workflow/test_workflow \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"prompt": "test", "steps": 10}'
|
|
```
|
|
|
|
## Workflow Template
|
|
|
|
Each workflow file should follow this pattern:
|
|
|
|
```python
|
|
def run_workflow(**kwargs):
|
|
"""
|
|
Your workflow description.
|
|
|
|
Args:
|
|
**kwargs: Workflow parameters
|
|
|
|
Returns:
|
|
dict: Result with status and output
|
|
"""
|
|
from comfy_script.runtime import *
|
|
load('http://127.0.0.1:8188/')
|
|
from comfy_script.runtime.nodes import *
|
|
|
|
# Your workflow logic here
|
|
with Workflow(wait=True) as wf:
|
|
# ... nodes ...
|
|
pass
|
|
|
|
return {
|
|
'status': 'completed',
|
|
'output': result
|
|
}
|
|
```
|