Discovery and backend selection (imagewright.discovery)¶
imagewright.discovery
¶
Find an image server, and choose the backend a caller should use.
NoImageBackendError
¶
Bases: RuntimeError
No backend was named, no server answered, and in-process FLUX is not installed.
The message lists the ways to fix it.
discover_image_endpoint(candidates=None, timeout=1.5)
¶
Find an image server that is actually up.
Tries /health first and falls back to /v1/models: /health is
the newer route, and an older server or a third-party mflux-serve only
answers the model listing. A connection refused, a timeout, or any non-200
all mean "not this one".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
candidates
|
tuple[str, ...] | None
|
Base URLs to try, in order. |
None
|
timeout
|
float
|
Per-request timeout in seconds. |
1.5
|
Returns:
| Type | Description |
|---|---|
str | None
|
The first responding base URL, or None if none answered. |
Source code in src/imagewright/discovery.py
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | |
resolve_image_config(backend=None, endpoint=None, *, timeout=1.5)
¶
Choose the image backend, in a fixed order, and return its configuration.
- backend and endpoint as given. An endpoint with no backend means
mflux-serve, whateverIMAGE_BACKENDsays. IMAGE_BACKENDandIMAGE_ENDPOINT(GUTENKG_IMAGE_ENDPOINTas a fallback) from the environment, the same way. A configured endpoint is used without probing it.- A server that answers on :data:
DEFAULT_IMAGE_ENDPOINTS. - In-process FLUX (
mflux-local) if mflux is installed, after a warning that no server was found and the model is loading in process. - Otherwise :class:
NoImageBackendError, whose message lists the fixes.
Rungs 1-3 never load a model unless mflux-local is named. A named
mflux-serve with no endpoint uses a discovered server, else the default
http://localhost:8090; it never falls through to in-process FLUX.
Model, steps and API key always come from :func:image_config_from_env.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
ImageBackend | str | None
|
Backend to use, by enum or by value such as |
None
|
endpoint
|
str | None
|
Image server base URL for |
None
|
timeout
|
float
|
Per-request timeout for discovery probes, in seconds. |
1.5
|
Returns:
| Type | Description |
|---|---|
ImageConfig
|
The configuration to pass to |
Raises:
| Type | Description |
|---|---|
ValueError
|
When backend or |
NoImageBackendError
|
When nothing is named, found or installed. |
Source code in src/imagewright/discovery.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |