Integrate with OpenAI's ChatGPT API seamlessly from Delphi.
Features
Easily access the GPT API from a single class
Supports both GPT3 and GPT4 models
API key can be read from ChatGPTApiKey environment variable if defined
Automatically sanitizes input to minimize errors
Ability to define proxy settings
Adjust personality response with a precision range of 0-1, from precise to creative
Stream responses just like in the ChatGPT web interface
Usage
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.
// Basic example showing how to query ChatGPT
uses
AskChatGPT;
var
LChat: TAskChatGPT;
begin
LChat := TAskChatGPT.Create;
try
// set chat params
LChat.Model := GPT3; // use the GPT3 model, or GPT4 for the GPT4 model
LChat.Creative := 1; // 0-1, 0 being most percise and 1 being most creative
// ask question
LChat.Question := 'What is Delphi?'
// print question
PrintLn('Q: %s', [LChat.Question]);
// process and print response
if LChat.Process then
PrintLn('A: %s', [LChat.Response]);
finally
LChat.Free;
end;
end;
Media
Download
https://github.com/tinyBigGAMES/AskChatGPT