AIChat

TsgcHTMLComponent_AIChat — プロバイダー/モデル選択、ライブなトークンストリーミング、RAG ソース引用を備えた AI アシスタントチャットを Delphi、C++ Builder、.NET で実現します。

TsgcHTMLComponent_AIChat

TsgcHTMLComponent_ChatBox を、OpenAI / Anthropic / Gemini のプロバイダーヘッダー、ストリーミング応答、折りたたみ可能な RAG ソースで拡張したアシスタント画面です。プロバイダーを選び、OnChatSend を処理したら、HTML プロパティを読み取ります。

コンポーネントクラス

TsgcHTMLComponent_AIChat

レンダリング結果

Bootstrap 5 の card + スコープ付き CSS

ファミリー

チャット & AI

言語

Delphi, C++ Builder, .NET

作成し、OnChatSend を接続し、レンダリングする

AIProviderModelName を選び、応答を生成するために OnChatSend を処理したら、HTML を読み取ります。このイベントを通じて、ブラウザーのメッセージが Delphi、C++ Builder、.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

主なプロパティ & メソッド

最もよく使うメンバー。

プロバイダー & モデル

AIProviderapOpenAIapAnthropicapGeminiapCustom を選択します。ModelName はヘッダーのラベルを設定し、ShowModelSelector でその表示を切り替え、AIName でアシスタントの名前を付けます。

会話

SystemPromptWelcomeMessage がチャットの初期状態を設定します。UserColorAIColor(いずれも TsgcHTMLColor)が吹き出しを色付けし、GetConversationHistoryJSON は LLM 呼び出し用のロール/コンテンツ配列を返します。

送信イベント

訪問者が送信すると、ユーザーメッセージと JSON 履歴とともに OnChatSend が発火します — ここがモデルを呼び出すフックです。ProcessUserMessage(aMessage) はそのフローをコードから駆動します。

ストリーミング

StreamingEnabled でオンにします。BeginStreamingPushStreamChunk(aChunk)EndStreaming が応答をトークンごとに伸ばし、GetStreamFragmentHTML がプッシュする htmx フラグメントを返します。

RAG ソース

OnRAGContext を備えた RAGEnabled が、取得したコンテキストを注入します。RAGDisplayModerdInline/rdCollapsible/rdFootnotes)と AddAIMessageWithSources(aText, aSourcesHTML) が引用をレンダリングします。

継承 & 出力

ChatBox から継承:MessagesTitleHeightInputPlaceholderShowTypingIndicatorHTML はカード全体を返し、GetLastMessageHTML は最新の吹き出しだけを返します。

さらに詳しく

すべての sgcHTML コンポーネント60 種類以上のコンポーネントの完全な機能マトリックスを見る。
無料体験版をダウンロード30 日間の体験版には 60.HTML デモプロジェクトが付属します。
価格完全なソースコード付きの Single、Team、Site ライセンス。

始める準備はできましたか?

無料体験版をダウンロードして、Delphi、C++ Builder、.NET で Web UI の構築を始めましょう。