AIChat

TsgcHTMLComponent_AIChat — Delphi, C++ Builder ve .NET'te sağlayıcı/model seçici, canlı belirteç akışı ve RAG kaynak alıntıları içeren bir yapay zeka asistanı sohbeti.

TsgcHTMLComponent_AIChat

TsgcHTMLComponent_ChatBox'ı bir OpenAI / Anthropic / Gemini sağlayıcı üstbilgisi, akışlı yanıtlar ve daraltılabilir RAG kaynaklarıyla genişleten bir asistan yüzeyi. Bir sağlayıcı seçin, OnChatSend'i işleyin, ardından HTML özelliğini okuyun.

Bileşen sınıfı

TsgcHTMLComponent_AIChat

İşler

Bootstrap 5 card + kapsamlı CSS

Diller

Delphi, C++ Builder, .NET

Oluşturun, OnChatSend'i bağlayın, işleyin

AIProvider ve ModelName'i seçin, yanıtı üretmek için OnChatSend'i işleyin, ardından HTML'i okuyun. Bu olay, bir tarayıcı iletisinin Delphi, C++ Builder ya da .NET kodunuza ulaşma yoludur.

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

Temel özellikler & yöntemler

En sık başvurduğunuz üyeler.

Sağlayıcı & model

AIProvider apOpenAI, apAnthropic, apGemini ya da apCustom'ı seçer; ModelName üstbilgiyi etiketler; ShowModelSelector onu açıp kapatır; AIName asistanı adlandırır.

Konuşma

SystemPrompt ve WelcomeMessage sohbeti başlatır; UserColor ve AIColor (her ikisi de TsgcHTMLColor) balonları renklendirir; GetConversationHistoryJSON, LLM çağrınız için rol/içerik dizisini döndürür.

Gönderme olayı

Ziyaretçi gönderdiğinde OnChatSend, kullanıcı iletisi ve JSON geçmişiyle tetiklenir — modelinizi çağırdığınız bağlantı noktası. ProcessUserMessage(aMessage) bu akışı koddan yürütür.

Akış

StreamingEnabled onu açar; BeginStreaming, PushStreamChunk(aChunk) ve EndStreaming yanıtı belirteç belirteç büyütür; GetStreamFragmentHTML gönderilecek htmx parçasını döndürür.

RAG kaynakları

OnRAGContext ile birlikte RAGEnabled, alınan bağlamı ekler; RAGDisplayMode (rdInline/rdCollapsible/rdFootnotes) ve AddAIMessageWithSources(aText, aSourcesHTML) alıntıları işler.

Devralınanlar & çıktı

ChatBox'tan: Messages, Title, Height, InputPlaceholder ve ShowTypingIndicator. HTML tüm kartı döndürür; GetLastMessageHTML yalnızca en yeni balonu döndürür.

Keşfetmeye devam edin

Tüm sgcHTML Bileşenleri60'tan fazla bileşenin tam özellik matrisine göz atın.
Ücretsiz Deneme Sürümünü İndirin30 günlük deneme, 60.HTML demo projeleriyle birlikte gelir.
FiyatlandırmaTam kaynak kodlu Single, Team ve Site lisansları.

Başlamaya Hazır mısınız?

Ücretsiz deneme sürümünü indirin ve Delphi, C++ Builder ve .NET'te web arayüzleri oluşturmaya başlayın.