AI prompt

AIPromptControl

Give users a prompt box with suggestions, commands and history; plug in any model.

Overview

AIPromptControl is a Blazor prompt panel: users type or pick a prompt, generate an answer, run commands such as Shorten, and reuse the result. Use it to draft replies or summaries inside your app: it calls no service itself, and your Generate delegate turns the prompt and command into text, so any model plugs in. The examples use a stub that returns canned text, so no model is called.

Examples

#Prompt, suggestions and commands

Click a suggestion, then Generate or one of the commands; Use in draft copies the response below, and the history buttons bring earlier ones back.

Ticket TKT-1042 Albus Door · Router keeps restarting · every evening since Monday · wants a technician visit on Saturday

Responses so far: 0

Draft for ticket TKT-1042

#Driving the prompt from the page

Use the page's own buttons: they call GenerateAsync and CancelAsync on the control. The stub takes two and a half seconds, so Stop has time to work; turn on Billing system is down and the next request fails with the message in the card; turn on Ticket solved and Enabled locks the prompt, Generate and the commands, and the card's Add to the ticket button then does nothing. The history buttons show each response's time and prompt, not its command, so a shortened note is captioned like the full one.

Keeps the last three responses. The answers are canned, so no model is called.

Note on Hermione Ranger's ticket TKT-1043: none yet

Documentation

ParameterTypeDefaultDescription
Promptstring""The prompt, in a multi-line TextBoxControl that updates on every keystroke; a suggestion click replaces it. The control writes its own copy, so bind it with @bind-Prompt; otherwise the parent's value can replace the typed text when the parent re-renders.
GenerateFunc<AIPromptRequest, CancellationToken, Task<string>>?nullYour provider. Called with an AIPromptRequest and a token that Cancel and disposal cancel; returns the response text. While it is null the Generate and command buttons stay disabled and a status line asks for a provider.
SuggestionsIReadOnlyList<string>Array.Empty<string>()One button per string under the prompt. A click replaces the prompt and raises PromptChanged; it does not generate.
CommandsIReadOnlyList<AIPromptCommand>Array.Empty<AIPromptCommand>()One button per command after Generate, captioned with its Text. A click generates with the command in the request, and the card's badge shows its Text.
MaxHistoryint10Most responses kept in History, newest first. Below 1 keeps one.
Rowsint4Height of the prompt box in lines.
AriaLabelstring"AI prompt"aria-label of the section and of the prompt box.
Placeholderstring"Enter a prompt…"Placeholder of the prompt box.
ApplyLabelstring"Use response"Caption of the card's apply button. The button is drawn whether or not Apply has a handler.
FooterContentRenderFragment?nullRendered last inside the section, after the history row, such as the second example's note.
Enabled (base)booltrueFalse disables the prompt box, the suggestions, Generate and the commands, and makes the apply button do nothing. The history buttons and Dismiss still work.
Visible (base)booltrueFalse adds display:none to the section.
Id / CssClass / Style (base)string?nullOn the section.fx-ai-prompt.
Title / Tag / Data / Parent (base)nullAccepted but not rendered. A written title binds to Title, so it does not reach the section.
(unmatched attributes)Dictionary<string,object>—Written on the section after its own attributes, so a class or aria-label given here replaces the control's own.
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.