---
title: rewrite
---

<div class="python-reference">
<a id="fastvideo.entrypoints.streaming.prompt.rewrite-classes"></a>
<a id="fastvideo.entrypoints.streaming.prompt.rewrite-functions"></a>
<a id="fastvideo.entrypoints.streaming.prompt.rewrite.RewriteOptions-attributes"></a>
<a id="fastvideo.entrypoints.streaming.prompt.rewrite"></a>
<p>Rewrite payload builder.</p>
<p>The UI's "rewrite seed prompts" flow asks the enhancer to produce a
batch of alternative prompts given one seed. This module packages the
seed + options into the payload the enhancer expects and unpacks the
response back into a typed :class:<code>RewriteResult</code>.</p>
<p>Separating this from :mod:<code>enhancer</code> keeps the enhancer provider-
agnostic; anything UI-specific (how many alternatives to request, how
to split the response, temperature) lives here.</p>
<h2 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer</code></h2>
<pre class="doc-signature"><code>PromptEnhancer(*, providers: Sequence&#91;LLMProvider&#93;, model: str, timeout_ms: int = 20000, temperature: float = 0.7, max_tokens: int | None = 256, system_prompt_dir: str | None = None)</code></pre>
<p>Orchestrates prompt operations across a priority-ordered provider
list with structured fallback + hot-reloadable system prompts.</p>
<p>Usage::</p>
<pre><code>enhancer = PromptEnhancer(
    providers=[CerebrasProvider(), GroqProvider()],
    model="gpt-oss-120b",
    system_prompt_dir="/etc/fastvideo/prompts",
)
response = await enhancer.enhance("a fox running through snow")
</code></pre>

<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.register_provider"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.register_provider</code></h3>
<pre class="doc-signature"><code>register_provider(provider: LLMProvider, *, priority: int = -1) -&gt; None</code></pre>
<p>Insert an additional provider. <code>priority=0</code> makes it primary;
<code>priority=-1</code> (default) appends as a fallback.</p>
<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.reload_system_prompts"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.reload_system_prompts</code></h3>
<pre class="doc-signature"><code>reload_system_prompts() -&gt; None</code></pre>
<p>Re-read the system prompt files from <code>system_prompt_dir</code>.</p>
<p>The streaming server exposes this via a management endpoint so
operators can iterate on prompt templates without restarting
workers.</p>
<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.enhance"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.enhance</code></h3>
<pre class="doc-signature"><code>enhance(prompt: str) -&gt; LLMResponse</code></pre>

<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.auto_extend"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.auto_extend</code></h3>
<pre class="doc-signature"><code>auto_extend(prior_prompts: Sequence&#91;str&#93;) -&gt; LLMResponse</code></pre>

<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.rewrite"><code>fastvideo.entrypoints.streaming.prompt.rewrite.PromptEnhancer.rewrite</code></h3>
<pre class="doc-signature"><code>rewrite(seed_prompt: str) -&gt; LLMResponse</code></pre>

<h2 id="fastvideo.entrypoints.streaming.prompt.rewrite.RewriteOptions"><code>fastvideo.entrypoints.streaming.prompt.rewrite.RewriteOptions</code></h2>
<pre class="doc-signature"><code>RewriteOptions(count: int = 3, temperature: float | None = None)</code></pre>


<details><summary>Source</summary><pre><code>@dataclass
class RewriteOptions:
    count: int = 3
    &quot;&quot;&quot;Number of alternative prompts to request.&quot;&quot;&quot;
    temperature: float | None = None</code></pre></details>
<h3 id="fastvideo.entrypoints.streaming.prompt.rewrite.RewriteOptions.count"><code>fastvideo.entrypoints.streaming.prompt.rewrite.RewriteOptions.count</code></h3>
<pre class="doc-signature"><code>count: int = 3</code></pre>
<p>Number of alternative prompts to request.</p>
<details><summary>Source</summary><pre><code>count: int = 3</code></pre></details>
<h2 id="fastvideo.entrypoints.streaming.prompt.rewrite.RewriteResult"><code>fastvideo.entrypoints.streaming.prompt.rewrite.RewriteResult</code></h2>
<pre class="doc-signature"><code>RewriteResult(seed_prompt: str, alternatives: list&#91;str&#93;, provider: str, model: str, latency_ms: float, fallback_used: bool = False)</code></pre>


<details><summary>Source</summary><pre><code>@dataclass
class RewriteResult:
    seed_prompt: str
    alternatives: list&#91;str&#93;
    provider: str
    model: str
    latency_ms: float
    fallback_used: bool = False</code></pre></details>
<h2 id="fastvideo.entrypoints.streaming.prompt.rewrite.build_rewrite"><code>fastvideo.entrypoints.streaming.prompt.rewrite.build_rewrite</code></h2>
<pre class="doc-signature"><code>build_rewrite(enhancer: PromptEnhancer, seed_prompt: str, *, options: RewriteOptions | None = None) -&gt; RewriteResult</code></pre>
<p>Run a rewrite op through the enhancer and return a typed result.</p>
<details><summary>Source</summary><pre><code>async def build_rewrite(
    enhancer: PromptEnhancer,
    seed_prompt: str,
    *,
    options: RewriteOptions | None = None,
) -&gt; RewriteResult:
    &quot;&quot;&quot;Run a rewrite op through the enhancer and return a typed result.&quot;&quot;&quot;
    if not seed_prompt.strip():
        raise ValueError(&quot;rewrite seed prompt must be non-empty&quot;)
    options = options or RewriteOptions()
    response = await enhancer.rewrite(seed_prompt)
    alternatives = _split_response(response.content, limit=options.count)
    return RewriteResult(
        seed_prompt=seed_prompt,
        alternatives=alternatives,
        provider=response.provider,
        model=response.model,
        latency_ms=response.latency_ms,
        fallback_used=response.fallback_used,
    )</code></pre></details>
</div>
