prompt_enhance ¶
Local prompt enrichment for the MLX Wan runtime (H3 Context-IR-style).
Wan's training captions are long and cinematic; short user prompts leave quality on the table. This module expands a raw prompt into Wan-style shot language on device — no remote API, no training.
Backends (first match wins):
- mlx-lm — optional local LLM (
--enhance-prompt-model). - template — deterministic cinematic expansion (always available).
System-prompt contract matches the streaming server's enhancer defaults in fastvideo/entrypoints/streaming/prompt/enhancer.py so remote and local paths stay interchangeable.
Classes¶
fastvideo.mlx_runtime.prompt_enhance.EnhanceResult dataclass ¶
EnhanceResult(original: str, enhanced: str, backend: str, elapsed_s: float, model: str | None = None)
Outcome of a prompt enrichment call.
Functions:¶
fastvideo.mlx_runtime.prompt_enhance.enhance_cache_path ¶
enhance_cache_path(prompt: str, *, backend: str, model: str | None, cache_dir: Path | None = None) -> Path
Content-addressed cache file for an enhanced prompt string.
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.prompt_enhance.enhance_prompt ¶
enhance_prompt(prompt: str, *, backend: str = 'auto', model: str | None = None, system_prompt: str = DEFAULT_ENHANCE_SYSTEM_PROMPT, max_tokens: int = 128) -> EnhanceResult
Enhance a prompt using the selected backend, falling back to a deterministic template when configured for automatic selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The prompt to enhance. | required |
backend | str | The enhancement backend: | 'auto' |
model | str | None | The MLX language model to use. | None |
system_prompt | str | Instructions provided to the MLX language model. | DEFAULT_ENHANCE_SYSTEM_PROMPT |
max_tokens | int | Maximum number of tokens generated by the MLX language model. | 128 |
Returns:
| Name | Type | Description |
|---|---|---|
EnhanceResult | EnhanceResult | The original and enhanced prompts, selected backend, timing information, and model metadata. |
Raises:
| Type | Description |
|---|---|
ValueError | If the prompt is empty or the backend is unsupported. |
Exception | If the explicitly selected |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.prompt_enhance.enhance_prompt_mlx_lm ¶
enhance_prompt_mlx_lm(prompt: str, *, model: str = DEFAULT_MLX_LM_MODEL, system_prompt: str = DEFAULT_ENHANCE_SYSTEM_PROMPT, max_tokens: int = 128, temp: float = 0.6) -> str
Enhance a user prompt with a locally hosted mlx-lm instruction model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The prompt to enhance. | required |
model | str | The mlx-lm model identifier or path. | DEFAULT_MLX_LM_MODEL |
system_prompt | str | Instructions that guide prompt enhancement. | DEFAULT_ENHANCE_SYSTEM_PROMPT |
max_tokens | int | Maximum number of tokens to generate. | 128 |
temp | float | Sampling temperature for generation. | 0.6 |
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The enhanced prompt. |
Raises:
| Type | Description |
|---|---|
RuntimeError | If mlx-lm is unavailable or produces an empty result. |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.prompt_enhance.enhance_prompt_template ¶
Expand a prompt with cinematic camera, lighting, motion, and visual-quality details.
Rich prompts are preserved, while thinner prompts receive deterministic enhancements without changing their subject.
Returns:
| Name | Type | Description |
|---|---|---|
str | str | The original or expanded prompt with normalized whitespace and punctuation. |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.prompt_enhance.enhance_result_as_metrics ¶
enhance_result_as_metrics(result: EnhanceResult | None) -> dict[str, Any]
Convert prompt enhancement results into metrics fields.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result | EnhanceResult | None | The enhancement result, or | required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | dict[str, Any]: A metrics mapping containing enhancement status, backend metadata, timing, and original and enhanced prompts. |
Source code in fastvideo/mlx_runtime/prompt_enhance.py
fastvideo.mlx_runtime.prompt_enhance.load_or_enhance_prompt ¶
load_or_enhance_prompt(prompt: str, *, backend: str = 'auto', model: str | None = None, system_prompt: str = DEFAULT_ENHANCE_SYSTEM_PROMPT, max_tokens: int = 128, cache: bool = True, cache_dir: Path | None = None) -> EnhanceResult
Enhance a prompt, reusing a cached result when available.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt | str | The prompt to enhance. | required |
backend | str | Enhancement backend to use. | 'auto' |
model | str | None | Optional model identifier. | None |
system_prompt | str | System prompt for model-based enhancement. | DEFAULT_ENHANCE_SYSTEM_PROMPT |
max_tokens | int | Maximum number of tokens generated by the model. | 128 |
cache | bool | Whether to read and write the on-disk cache. | True |
cache_dir | Path | None | Optional directory for cached results. | None |
Returns:
| Name | Type | Description |
|---|---|---|
EnhanceResult | EnhanceResult | The enhanced prompt and backend metadata. Cached results are marked with the |