AIChat
TsgcHTMLComponent_AIChat — un chat de asistente de IA con un selector de proveedor/modelo, streaming de tokens en vivo y citas de fuentes RAG, en Delphi, C++ Builder y .NET.
TsgcHTMLComponent_AIChat — un chat de asistente de IA con un selector de proveedor/modelo, streaming de tokens en vivo y citas de fuentes RAG, en Delphi, C++ Builder y .NET.
Una superficie de asistente que extiende TsgcHTMLComponent_ChatBox con una cabecera de proveedor OpenAI / Anthropic / Gemini, respuestas en streaming y fuentes RAG plegables. Elige un proveedor, gestiona OnChatSend y luego lee la propiedad HTML.
TsgcHTMLComponent_AIChat
card de Bootstrap 5 + CSS con ámbito
Delphi, C++ Builder, .NET
Elige AIProvider y ModelName, gestiona OnChatSend para producir la respuesta y luego lee HTML. El evento es cómo un mensaje del navegador llega a tu código 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
Los miembros que más vas a usar.
AIProvider selecciona apOpenAI, apAnthropic, apGemini o apCustom; ModelName etiqueta la cabecera; ShowModelSelector lo activa o desactiva; AIName nombra al asistente.
SystemPrompt y WelcomeMessage inician el chat; UserColor y AIColor (ambos TsgcHTMLColor) tiñen las burbujas; GetConversationHistoryJSON devuelve el array de rol/contenido para tu llamada al LLM.
OnChatSend se dispara con el mensaje del usuario y el historial JSON cuando el visitante envía — el punto donde llamas a tu modelo. ProcessUserMessage(aMessage) impulsa ese flujo desde el código.
StreamingEnabled lo activa; BeginStreaming, PushStreamChunk(aChunk) y EndStreaming hacen crecer la respuesta token a token; GetStreamFragmentHTML devuelve el fragmento htmx que enviar.
RAGEnabled con OnRAGContext inyecta el contexto recuperado; RAGDisplayMode (rdInline/rdCollapsible/rdFootnotes) y AddAIMessageWithSources(aText, aSourcesHTML) renderizan las citas.
De ChatBox: Messages, Title, Height, InputPlaceholder y ShowTypingIndicator. HTML devuelve la tarjeta completa; GetLastMessageHTML devuelve solo la burbuja más reciente.