Docs

React UI

Completion panel

Build a prompt-to-text completion panel with @anvia/react-ui.

Use completion primitives when the interface is one prompt and one generated text result rather than a multi-message chat thread.

import { useCompletion } from "@anvia/react";
import { Completion, CompletionProvider } from "@anvia/react-ui";

export function ReleaseNoteDraft() {
  const completion = useCompletion({ endpoint: "http://localhost:8787/api/completion" });

  return (
    <CompletionProvider controller={completion}>
      <Completion.Root className="completion-panel">
        <Completion.Output>
          {(text) => (
            <article className="completion-result" aria-live="polite">
              {text.length > 0 ? text : "Your draft will appear here."}
            </article>
          )}
        </Completion.Output>

        <Completion.Form className="completion-form">
          <Completion.Input rows={5} placeholder="Draft a release note for the latest changes..." />
          <Completion.Stop>Stop</Completion.Stop>
          <Completion.Submit>Generate</Completion.Submit>
        </Completion.Form>
      </Completion.Root>
    </CompletionProvider>
  );
}

The completion endpoint should accept the same UIStreamRequest shape as chat and return Anvia stream events. See Completion for the route example.