Jump to content

Recommended Posts

logo256.png.913a963b047a94ecfea50aeb397bd79a.png

 

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

  • Like 4

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×