AIChat
TsgcHTMLComponent_AIChat — an AI assistant chat with a provider/model selector, live token streaming and RAG source citations, in Delphi, C++ Builder and .NET.
TsgcHTMLComponent_AIChat — an AI assistant chat with a provider/model selector, live token streaming and RAG source citations, in Delphi, C++ Builder and .NET.
An assistant surface that extends TsgcHTMLComponent_ChatBox with an OpenAI / Anthropic / Gemini provider header, streamed replies and collapsible RAG sources. Pick a provider, handle OnChatSend, then read the HTML property.
TsgcHTMLComponent_AIChat
Bootstrap 5 card + scoped CSS
Delphi, C++ Builder, .NET
Choose AIProvider and ModelName, handle OnChatSend to produce the reply, then read HTML. The event is how a browser message reaches your Delphi, C++ Builder or .NET code.
uses
sgcHTML_Enums, sgcHTML_Component_AIChat;
var
oAI: TsgcHTMLComponent_AIChat;
begin
oAI := TsgcHTMLComponent_AIChat.Create(nil);
try
oAI.AIProvider := apOpenAI;
oAI.ModelName := 'gpt-4o';
oAI.AIName := 'Support Bot';
oAI.SystemPrompt := 'You are a helpful assistant.';
oAI.WelcomeMessage := 'Hi! Ask me anything.';
oAI.StreamingEnabled := True;
oAI.OnChatSend := DoChatSend; // browser message -> your code
WebModule.Response := oAI.HTML; // Bootstrap card + AI header
finally
oAI.Free;
end;
end;
// OnChatSend hands you the user message + the JSON history,
// you call your LLM and stream the answer back:
procedure TForm1.DoChatSend(Sender: TObject; const aUserMessage,
aConversationHistory: string);
begin
oAI.BeginStreaming;
oAI.PushStreamChunk('Sure, ');
oAI.PushStreamChunk('here is the answer...');
oAI.EndStreaming;
WebSocket.WriteData(oAI.GetStreamFragmentHTML);
end;
// includes: sgcHTML_Enums.hpp, sgcHTML_Component_AIChat.hpp
TsgcHTMLComponent_AIChat *oAI = new TsgcHTMLComponent_AIChat(NULL);
try
{
oAI->AIProvider = apOpenAI;
oAI->ModelName = "gpt-4o";
oAI->AIName = "Support Bot";
oAI->SystemPrompt = "You are a helpful assistant.";
oAI->WelcomeMessage = "Hi! Ask me anything.";
oAI->StreamingEnabled = true;
oAI->OnChatSend = DoChatSend; // browser message -> your code
String html = oAI->HTML; // Bootstrap card + AI header
}
__finally
{
delete oAI;
}
// OnChatSend handler: call your LLM, then stream the reply:
void __fastcall TForm1::DoChatSend(TObject *Sender,
const String aUserMessage, const String aConversationHistory)
{
oAI->BeginStreaming();
oAI->PushStreamChunk("Sure, ");
oAI->PushStreamChunk("here is the answer...");
oAI->EndStreaming();
}
using esegece.sgcWebSockets;
var ai = new TsgcHTMLComponent_AIChat();
ai.AIProvider = TsgcHTMLAIProvider.apOpenAI;
ai.ModelName = "gpt-4o";
ai.AIName = "Support Bot";
ai.SystemPrompt = "You are a helpful assistant.";
ai.WelcomeMessage = "Hi! Ask me anything.";
ai.StreamingEnabled = true;
// OnChatSend: browser message -> your code -> stream the reply
ai.OnChatSend += (sender, userMessage, conversationHistory) =>
{
ai.BeginStreaming();
ai.PushStreamChunk("Sure, ");
ai.PushStreamChunk("here is the answer...");
ai.EndStreaming();
};
string html = ai.HTML; // Bootstrap card + AI header
The members you reach for most often.
AIProvider selects apOpenAI, apAnthropic, apGemini or apCustom; ModelName labels the header; ShowModelSelector toggles it; AIName names the assistant.
SystemPrompt and WelcomeMessage seed the chat; UserColor and AIColor (both TsgcHTMLColor) tint the bubbles; GetConversationHistoryJSON returns the role/content array for your LLM call.
OnChatSend fires with the user message and JSON history when the visitor submits — the hook where you call your model. ProcessUserMessage(aMessage) drives that flow from code.
StreamingEnabled turns it on; BeginStreaming, PushStreamChunk(aChunk) and EndStreaming grow the reply token by token; GetStreamFragmentHTML returns the htmx fragment to push.
RAGEnabled with OnRAGContext injects retrieved context; RAGDisplayMode (rdInline/rdCollapsible/rdFootnotes) and AddAIMessageWithSources(aText, aSourcesHTML) render the citations.
From ChatBox: Messages, Title, Height, InputPlaceholder and ShowTypingIndicator. HTML returns the whole card; GetLastMessageHTML returns just the newest bubble.