TsgcAIOpenAIChatBot › Events › OnChatCompletion
Fires when the OpenAI ChatCompletion API returns an assistant reply; exposes Role and Content.
property OnChatCompletion: TsgcOpenAIChatCompletion;
// TsgcOpenAIChatCompletion = procedure(Sender: TObject; const Role, Content: string) of object
—
Raised once per choice returned by the ChatCompletion API. Role is typically assistant, and Content is the reply text. The event fires before the text is handed to TextToSpeech, so you can log, persist to chat history, or update the UI from this handler. Keep the handler short — it runs in the context of the HTTP callback.
procedure TForm1.sgcChatBotChatCompletion(Sender: TObject; const Role, Content: string);
begin
Memo1.Lines.Add(Role + ': ' + Content);
end;