Using OpenAI ChatGPT API Client in Lazarus lazarus / 21-General ---------------------------------------------------------------------- maurobio · 2025-04-02 11:34 Dear ALL, I would like to give a try to the OpenAI ChatGPT API Client for Delphi and Lazarus (available https://github.com/landgraf-dev/openai-delphi), but keep getting all sorts of compilation errors. I am running version 3.6 of Lazarus. Has anyone out there been able to compile the demo application of this ChatGPT client using Lazarus 3.6 or later? Thanks in advance for any assistance you can provide. Best regards, ---------------------------------------------------------------------- TRon · 2025-04-02 13:13 Code: [Select]OpenApiRest.pas(3,5) Error: Compile time expression: Wanted Boolean but got at IF or ELSEIF make it read: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$ifndef fpc}{$IF CompilerVersion < 29}  {$DEFINE USEINDY}{$IFEND}{$endif} in order to get rid of Delphism. Code: [Select]OpenApiUtils.pas(642,45) Error: identifier idents no member "Create" OpenApiUtils.pas(642,45) Fatal: Syntax error, ";" expected but "identifier CREATE" found make it read: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i initialization  InternalFormatSettings := default(TFormatSettings);  InternalFormatSettings.DecimalSeparator := '.';end.  compile with: fpc -Mdelphi -B -Fu ChatGPT.lpr Whether it actually works or not I dunno. I do not and will not ever use this api myself. ---------------------------------------------------------------------- dseligo · 2025-04-03 11:25 I tried it (just yesterday ) and it works. Similar changes as @TRon suggested were necessary. To use some models (like 'gpt-4' or 'gpt-3.5-turbo') you need to use CreateChatCompletion method (and appropriate classes) - this is 'Chat Completions' API. I would like to use newest 'Responses' API and I don't see it in this library, so I'll probably just compose JSON by myself and parse the received answers. ---------------------------------------------------------------------- maurobio · 2025-04-03 18:36 Hi, TRon, dseligo! Thanks for your insightful replies! After implementing the changes pointed out by TRon, I have been able to compile the demo for Lazarus of the ChatGPT API client, but attempts to executing it resulted in a Access Violation error (see attached screenshot). Am I missing something? With warmest regards, ---------------------------------------------------------------------- cdbc · 2025-04-03 18:53 Hi I'll bet, it has to do openssl, tsl or whatever it's all called, the stuff that ships with FPC 3.2.2 is too old... Regards Benny ---------------------------------------------------------------------- maurobio · 2025-04-03 18:56 Hi, cdbc! I just forgot to mention that I also upgraded my Lazarus installation to the latest version (3.. All my recent attempts at compiling and testing the ChatGPT client were already done using this version. But the runtime error persists. Best regards, ---------------------------------------------------------------------- TRon · 2025-04-03 19:23 Nah, seem to be my bad  For some reason default(TFormatSettings) seem to crash. I have no idea what the Delphi create function actually does (e.g. if it set some of the formatsettings values or not) so either remove the line or you could try: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   InternalFormatSettings := DefaultFormatSettings;  InternalFormatSettings.DecimalSeparator := '.';  at least for me that seem to get things going: Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i OpenAI ChatGPT Sample Application version 1.0Using OpenAI API Client for Delphi and Lazarus/FPChttps://github.com/landgraf.dev/openai- delphiCopyright (c) Landgraf.dev - all rights reserved. API key not found in system.It is strongly recommended that you set the API key using environvment variable OPENAI_API_KEY.Please enter your API key manually: ---------------------------------------------------------------------- maurobio · 2025-04-03 19:40 Hi, TRon! Yes, following your latest suggestion, the ChatGPT client demo program now compiles and runs fine. Thank you very much! Best regards, ---------------------------------------------------------------------- dseligo · 2025-04-03 23:46 Quote from: TRon on April 03, 2025, 09:23:31 pmFor some reason default(TFormatSettings) seem to crash. I have no idea what the Delphi create function actually does (e.g. if it set some of the formatsettings values or not) so either remove the line or you could try: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   InternalFormatSettings := DefaultFormatSettings;  InternalFormatSettings.DecimalSeparator := '.';  I did it like this, also works: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i   InternalFormatSettings := FormatSettings; // TFormatSettings.Create; ---------------------------------------------------------------------- Ericktux · 2025-04-07 16:31 Hello friends, when I try to run the program I get: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i You exceeded your current quota, please check your plan and billing details ---------------------------------------------------------------------- TRon · 2025-04-07 16:45 @Ericktux: And... the question is ...  ? Do you have enough credits and/or paid the bill that allows you to use chatGPT ? (note, there is no free tier anymore and people have reported that they lost their $5 free credits when the free tier was removed). ---------------------------------------------------------------------- Ericktux · 2025-04-07 17:31 I understood, I thought it was still free like the chat ---------------------------------------------------------------------- TRon · 2025-04-07 17:44 No problem. The chat-example code makes use of the OpenAI API and the use of API's generally costs money (one way or another). Some companies offer a free or developer tier (with restrictions) in order to let users test their applications but OpenAI's message here is that it is better to profit from developers and other content creators to keep their investors and their precious profit margins happy and be able to keep on venting hot air. Can't get any more lame than that ---------------------------------------------------------------------- maurobio · 2025-04-07 19:26 Dear ALL, In fact I have spent the last several days looking for a way of really using the program because even if it now compiles and runs fine, it never returns any results, but the dreaded error message saying that I have no quota for using the APi. I found this hard to accept because I did never used that API before and therefore could not have ran out of quota  Until now I did understood that there was a free quota (although small) which por developers could use for testing purposes. But, as pointed out by TRon, even small free quotas are now not allowed any more so that the capitalist bloodsuckers called 'investors' do not risk their precious profit margins (now, this is to be lame!).