Access OpenAI's ChatGPT API from Delphi.
- Access GPT API from a single class, simple and easily
- Supports GPT3 and GPT4 models
- Can read API key from
ChatGPTApiKey
environment variable if defined - Will attempt to sanitize input to minimize errors
- Proxy support
- Non-blocking support
- Windows 10
- Delphi Community Edition
-
Get your API Key: https://platform.openai.com/account/api-keys
-
Define environment variable
ChatGPTApiKey
and assigned your API key. You may have to reboot your machine for it to take effect.
uses
AskChatGPT;
var
LChat: TAskChatGPT;
begin
LChat := TAskChatGPT.Create;
try
// process and print response using defaults:
// apikey - will try to read from environment variable `ChatGPTApiKey`
// question - What is the Delphi language?
// print question
PrintLn('Q: %s', [LChat.Question]);
if LChat.Process then
PrintLn('A: %s', [LChat.Response]);
finally
LChat.Free;
end;
end.