TsgcAIOpenAIChatBotEvents › OnChatCompletion

OnChatCompletion Event

Fires when the OpenAI ChatCompletion API returns an assistant reply; exposes Role and Content.

Syntax

property OnChatCompletion: TsgcOpenAIChatCompletion;
// TsgcOpenAIChatCompletion = procedure(Sender: TObject; const Role, Content: string) of object

Default Value

Remarks

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.

Example

procedure TForm1.sgcChatBotChatCompletion(Sender: TObject; const Role, Content: string);
begin
  Memo1.Lines.Add(Role + ': ' + Content);
end;

Back to Events