TsgcAIChat › Methods › ChatStream
Sends a user message and receives the response incrementally.
function ChatStream(const aMessage: string): string;
| Name | Type | Description |
|---|---|---|
aMessage | const string | User message appended to the history and streamed to the provider. |
Accumulated assistant reply after the stream ends, equivalent to concatenating every aChunk delivered through OnChatStream. Empty when the call fails. (string)
Same semantics as Chat but sets the provider stream flag so partial tokens are delivered through OnChatStream as they arrive. Set the Cancel parameter of that event to True to stop reading further chunks. Once the stream terminates the accumulated text is stored in history and emitted as a single OnChatMessage with role assistant. If the provider ignores streaming and returns a full response the component falls back to parsing it as a non-streaming payload. Errors are forwarded to OnChatError.
oChat.OnChatStream := OnStream;
oChat.ChatStream('Tell me a story.');
procedure TForm1.OnStream(Sender: TObject; const aChunk: string;
var Cancel: Boolean);
begin
Memo1.Text := Memo1.Text + aChunk;
end;