AIChat
TsgcHTMLComponent_AIChat — una chat con assistente IA con selettore di provider/modello, streaming dei token in tempo reale e citazioni delle fonti RAG, in Delphi, C++ Builder e .NET.
TsgcHTMLComponent_AIChat — una chat con assistente IA con selettore di provider/modello, streaming dei token in tempo reale e citazioni delle fonti RAG, in Delphi, C++ Builder e .NET.
Una superficie di assistente che estende TsgcHTMLComponent_ChatBox con un'intestazione di provider OpenAI / Anthropic / Gemini, risposte in streaming e fonti RAG comprimibili. Scegli un provider, gestisci OnChatSend, quindi leggi la proprietà HTML.
TsgcHTMLComponent_AIChat
card di Bootstrap 5 + CSS dedicato
Delphi, C++ Builder, .NET
Scegli AIProvider e ModelName, gestisci OnChatSend per produrre la risposta, quindi leggi HTML. L'evento è il modo in cui un messaggio del browser raggiunge il tuo codice Delphi, C++ Builder o .NET.
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
I membri che utilizzerai più spesso.
AIProvider seleziona apOpenAI, apAnthropic, apGemini o apCustom; ModelName etichetta l'intestazione; ShowModelSelector lo attiva/disattiva; AIName dà un nome all'assistente.
SystemPrompt e WelcomeMessage inizializzano la chat; UserColor e AIColor (entrambi TsgcHTMLColor) colorano le bolle; GetConversationHistoryJSON restituisce l'array role/content per la chiamata al tuo LLM.
OnChatSend si attiva con il messaggio dell'utente e la cronologia JSON quando il visitatore invia — il punto in cui chiami il tuo modello. ProcessUserMessage(aMessage) guida quel flusso da codice.
StreamingEnabled lo attiva; BeginStreaming, PushStreamChunk(aChunk) ed EndStreaming fanno crescere la risposta token per token; GetStreamFragmentHTML restituisce il frammento htmx da inviare.
RAGEnabled con OnRAGContext inietta il contesto recuperato; RAGDisplayMode (rdInline/rdCollapsible/rdFootnotes) e AddAIMessageWithSources(aText, aSourcesHTML) renderizzano le citazioni.
Da ChatBox: Messages, Title, Height, InputPlaceholder e ShowTypingIndicator. HTML restituisce l'intera card; GetLastMessageHTML restituisce solo la bolla più recente.