TsgcAIChat › Methods › Chat
Sends a user message and returns the full assistant response.
function Chat(const aMessage: string): string;
| Name | Type | Description |
|---|---|---|
aMessage | const string | User message to append to the conversation history and send to the selected provider. |
Complete assistant reply, or an empty string when the request fails (the error is reported through OnChatError). (string)
Appends aMessage to the internal history as a user turn, dispatches a non-streaming request to the underlying provider using the current ChatOptions and SystemMessage, parses the response, stores the assistant reply in history, raises OnChatMessage with role assistant, and returns the assistant text. Exceptions raised during the request are caught and forwarded to OnChatError; in that case the function returns an empty string. Use ChatStream when you need incremental chunks instead of a single blocking call.
oChat.Provider := aicpOpenAI;
oChat.ChatOptions.ApiKey := 'API_KEY';
oChat.ChatOptions.Model := 'gpt-4o-mini';
WriteLn(oChat.Chat('Hello!'));