AIChat
TsgcHTMLComponent_AIChat — プロバイダー/モデル選択、ライブなトークンストリーミング、RAG ソース引用を備えた AI アシスタントチャットを Delphi、C++ Builder、.NET で実現します。
TsgcHTMLComponent_AIChat — プロバイダー/モデル選択、ライブなトークンストリーミング、RAG ソース引用を備えた AI アシスタントチャットを Delphi、C++ Builder、.NET で実現します。
TsgcHTMLComponent_ChatBox を、OpenAI / Anthropic / Gemini のプロバイダーヘッダー、ストリーミング応答、折りたたみ可能な RAG ソースで拡張したアシスタント画面です。プロバイダーを選び、OnChatSend を処理したら、HTML プロパティを読み取ります。
TsgcHTMLComponent_AIChat
Bootstrap 5 の card + スコープ付き CSS
Delphi, C++ Builder, .NET
AIProvider と ModelName を選び、応答を生成するために 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
最もよく使うメンバー。
AIProvider は apOpenAI、apAnthropic、apGemini、apCustom を選択します。ModelName はヘッダーのラベルを設定し、ShowModelSelector でその表示を切り替え、AIName でアシスタントの名前を付けます。
SystemPrompt と WelcomeMessage がチャットの初期状態を設定します。UserColor と AIColor(いずれも TsgcHTMLColor)が吹き出しを色付けし、GetConversationHistoryJSON は LLM 呼び出し用のロール/コンテンツ配列を返します。
訪問者が送信すると、ユーザーメッセージと JSON 履歴とともに OnChatSend が発火します — ここがモデルを呼び出すフックです。ProcessUserMessage(aMessage) はそのフローをコードから駆動します。
StreamingEnabled でオンにします。BeginStreaming、PushStreamChunk(aChunk)、EndStreaming が応答をトークンごとに伸ばし、GetStreamFragmentHTML がプッシュする htmx フラグメントを返します。
OnRAGContext を備えた RAGEnabled が、取得したコンテキストを注入します。RAGDisplayMode(rdInline/rdCollapsible/rdFootnotes)と AddAIMessageWithSources(aText, aSourcesHTML) が引用をレンダリングします。
ChatBox から継承:Messages、Title、Height、InputPlaceholder、ShowTypingIndicator。HTML はカード全体を返し、GetLastMessageHTML は最新の吹き出しだけを返します。