TFmxHelpChatAI reference
Unit FMX.HelpChatAI · package HelpChatAIFmx · palette group Ethea HelpChat · Delphi 12 and later.
The FireMonkey twin of TVclHelpChatAI: same engine, same page, same events. Only what FireMonkey does differently is different.
Published properties
| Property | Type | Default | Description |
|---|---|---|---|
Settings | THelpChatSettings | See the Settings reference | |
Active | Boolean | False | Acquires the engine of the profile and starts it, starts the transport and the hooks. Raises, and stays False, when the configuration cannot be read or the server cannot start |
RegisterHelpViewer | Boolean | True | Register with System.HelpIntfs, for code that calls the help system |
HandleF1 | Boolean | True | F1 on the host form opens the chat (its OnKeyDown is chained) |
Caption | string | (empty) | Title of the window the chat opens in when it is not embedded. Empty = the localized "Help" / "Aiuto" |
Profile | string | (empty) | Which assistant this is: its section under "Profiles" in the configuration and the suffix of its files. Never shown. Empty = the default assistant |
AssistantName | string | (empty) | What the assistant is called, written in the header of the panel next to its icon. Empty = the localized "Assistant" / "Assistente". "AssistantName" in the configuration prevails |
ShowBubble | Boolean | True | The round button with the assistant icon, in the bottom-right corner of the host form |
BubbleDraggable | Boolean | True | The user may drag the bubble to another place of its form: it keeps its distance from the nearest corner, and is found there again (The bubble) |
BubbleStayOnTop | Boolean | False | Main form only, on Windows: the bubble stays in front of every form of the application, modal ones included, and may be dragged anywhere on the monitor (Keeping the bubble in front) |
Images | TCustomImageList | nil | Image list holding the bubble icon; nil uses the icons compiled into the component. The same icon is drawn in the header of the chat panel |
ImageIndex | TImageIndex | -1 | The icon by position. With no image list of your own it picks among the built-in ones |
ImageName | string | (empty) | The icon by name: with no Images, one of AIAssistant_Male, AIAssistant_Female, Assistant_Male, Assistant_Female, Businessman, Businesswoman, CustomerSupport, Manager, VoicePresentation, PortraitMode (HELPCHAT_ICON_NAMES). The Object Inspector drops them down |
ConfigFileName | TFileName | (empty) | The configuration file. Empty = merge the three standard helpchatai.json on activation; named = that one and nothing else, raising EHelpChatConfigError if it is not there |
PanelStyleSheet | TFileName | (empty) | A CSS file of the application, added to the page of the chat after its own (a radius, a spacing, a hidden button: Inside the panel); it reaches OnGetTheme as ATheme.StyleSheet. Read at activation; a named file that is not there raises EHelpChatConfigError |
PdfStyleSheet | TFileName | (empty) | The stylesheet a saved PDF is laid out with; empty = the one built into the library. A named file that is not there raises EHelpChatConfigError |
PdfHeaderFile | TFileName | (empty) | The template of the band at the top of every sheet, with its placeholders |
PdfFooterFile | TFileName | (empty) | The template of the band at the foot |
ActionsEnabled | Boolean | True | Offer the registered actions to the model |
UseSharedActions | Boolean | True | Offer also the actions every assistant shares (HelpChatSharedActions); Settings.AllowedActions narrows both |
EnabledCommands | THelpChatCommands | everything but prompt and run | The slash commands the user may type. From code any command runs |
RememberPanelPosition | Boolean | True | Reopen the own window where the user left it, and show the bubble where it was dragged to |
ThemeMode | TFmxHelpChatThemeMode | tmAuto | tmAuto (page defaults, following the system), tmLight, tmDark |
Container | TFmxObject | nil | Where the chat is embedded; nil = the component's own window |
PanelWidth | Integer | 400 | Size of the own window |
PanelHeight | Integer | 600 |
Published events
Identical to the VCL ones, except that OnBeforeShowHelp carries a TFmxObject and that the two voice events (OnVoiceText, OnVoiceConsentNeeded) do not exist: dictation is VCL only.
| Event | Signature |
|---|---|
OnGetContext | (Sender; var AContext: THelpChatContext) |
OnGetTheme | (Sender; var ATheme: THelpChatTheme) |
OnBeforeShowHelp | (Sender; var AContainer: TFmxObject) |
OnAfterShowHelp / OnBeforeHideHelp / OnAfterHideHelp | (Sender) |
OnModelChanged | (Sender) |
OnActionConfirm | (Sender; const AName; const AArgs; var AAllow) |
OnActionExecuted | (Sender; const AName; const AOutcome; const AResult) |
OnPdfInfo | (Sender; var AInfo: THelpChatPdfInfo) |
OnDecryptSecret | (Sender; const AName, AValue; var AResult; var AHandled) |
OnBuildSystemPrompt | (Sender; const AContext: THelpChatContext; const ALanguage: THelpChatLanguage; var APrompt: string) |
OnLogEvent | (Sender; const AEntry: THelpChatLogEntry) - see Logging |
OnOpenLink | (Sender; const AUrl; var AHandled) |
Confirmation on a mobile platform
With no OnActionConfirm, on Windows and macOS the confirmation dialog of the library asks. On a mobile platform a modal form answers later, in a callback, while a worker thread is waiting for the answer now: there an action marked Confirm is refused unless OnActionConfirm is assigned.
Methods
Same as the VCL — Open, OpenForCurrentScreen, OpenForHelp, OpenWithQuestion, Close, Toggle, Assign, ResetBubblePosition, IsPanelVisible, OpenDocPage, BuildContext, BuildTheme, ApplyTheme, ResolvedCaption, ResolvedAssistantName, AssistantIconDataUri, ApplyAssistant, IsHelpViewerActive, ResolvedHostForm (a TCommonCustomForm), and what the panel does from code: ExecuteCommand, ExplainCommand, ClearConversation, Models, SelectModel, Languages, ActiveLanguage, SelectLanguage (see Languages), RetryLastQuestion, SaveConversationPdf, CopyLastAnswer, AttachFile (see Slash commands). There is no ActiveControlHasHelp: FireMonkey routes no F1 to a help system. What is its own:
| Method | Description |
|---|---|
HandleKeyDown(var AKey: Word; const AShift: TShiftState): Boolean | Call it from the OnKeyDown of a form that has no assistant of its own, on any assistant: a plain F1 goes to the current assistant - the one of the active form, else the one whose form was active last. Returns True, with AKey set to 0, when it consumed the key. The host form of a component needs no call: its OnKeyDown is chained at activation |
CurrentAssistant: TFmxHelpChatAI (class) | The assistant F1 goes to now, nil when none takes it |
ResolvedImageName: string | The name of the icon actually used: ImageName, or - with no image list of yours - the built-in one ImageIndex points at, or the default |
AssistantIconPng: TBytes | The icon of the bubble as a PNG; empty when there is none |
RunSettings: THelpChatSettings | The settings in force: the engine's while active - with the model and the language the user picked in the panel applied - else Settings. Read RunSettings.ActiveModelName, RunSettings.Provider and the key of that model here, not on Settings |
Public properties
Actions, Engine and Transport as in the VCL; ActiveContainer is a TFmxObject, View a TFmxHelpChatAIPanel and OwnForm a TFmxHelpChatAIForm. HostForm (TCommonCustomForm) is public and not published, as in the VCL: set it in code, because at design time there would be nothing to choose from. When that form is destroyed the assistant has no form until another one - or nil - is assigned.
Minimal example
uses
System.IOUtils, HelpChatAI.Types, FMX.HelpChatAI,
HelpChatAI.Provider.DocSearch; // a provider exists only if its unit is linked
procedure TMainForm.FormCreate(Sender: TObject);
begin
HelpChatAI.Settings.Provider := 'docsearch';
HelpChatAI.Settings.DocIndexFile := TPath.Combine(
TPath.GetDirectoryName(ParamStr(0)), 'help-index.json');
HelpChatAI.ThemeMode := tmAuto;
HelpChatAI.Active := True;
end;
// a form with no assistant of its own (the host form needs no call)
procedure TOrdersForm.FormKeyDown(Sender: TObject; var Key: Word;
var KeyChar: WideChar; Shift: TShiftState);
begin
MainForm.HelpChatAI.HandleKeyDown(Key, Shift);
end;Platform notes
- Windows: WebView2 (
WindowsEngine = EdgeOnly), verified. - macOS, iOS, Android: the native web view; the code compiles but has not been tested yet.
- Delphi 12: a navigation outside the panel cannot be cancelled (
OnShouldLoadURLarrived in Delphi 13), so an external link opens in the system browser (or reachesOnOpenLink) and the panel returns to its own page. - On mobile, use a remote server: no local HTTP server, no key in the package.