Recent

Author Topic: Has anyone used Free Pascal to connect with chatGPT (OpenAI)?  (Read 12490 times)

440bx

  • Hero Member
  • *****
  • Posts: 4747
Re: Has anyone used Free Pascal to connect with chatGPT (OpenAI)?
« Reply #75 on: April 03, 2023, 11:58:27 pm »
Just in case... this post is tongue in cheek...

I'm very pleased there is a great deal of effort going on in the field of Artificial Intelligence.  Maybe someday we'll have enough AI to compensate for the increasing scarcity of the natural one.

Some say SETI was created to increase the sources of intelligence because little, if any, could be found locally (see the movie I.Q)

if you have any doubts about the above, consider that Einstein found the source of infinite stupidity (and nobody gave him a Nobel prize for figuring out the obvious) but the source of infinite intelligence is yet to be found.  I rest my case ;)

Artificial coloring... Artificial flavors... Artificial intelligence... evolution never stops :)
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v3.2) on Windows 7 SP1 64bit.

dbannon

  • Hero Member
  • *****
  • Posts: 3156
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Has anyone used Free Pascal to connect with chatGPT (OpenAI)?
« Reply #76 on: April 04, 2023, 11:08:04 am »
Of course we can choose to ignore AI, and people who are interested in it.

Personally, I am not interested in it, don't want to work with it, won't contribute anything to it. But I sure know I cannot possibly afford to ignore it !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

Tomas Hajny

  • Moderator
  • New Member
  • *****
  • Posts: 45
Re: Has anyone used Free Pascal to connect with chatGPT (OpenAI)?
« Reply #77 on: April 04, 2023, 02:24:09 pm »
This discussion doesn't seem to be related to Free Pascal in its current form - please, don't continue it.

schuler

  • Full Member
  • ***
  • Posts: 242
Re: Has anyone used Free Pascal to connect with chatGPT (OpenAI)?
« Reply #78 on: December 01, 2023, 11:21:03 pm »
:) Hello Pascal Lovers! :)

In the case that the moderator allows me, I would like to go back to the page 3 of this thread regarding pascal (it was very interesting).

I had a problem last weekend when I needed to use very long string lists and it was slow to get the "delimited text". So, I asked GPT 4 to give me a solution. This was my question:

Code: Pascal  [Select][+][-]
  1. // I have this pascal method but it's too slow as the number of elements grow:
  2.  
  3. Function TStrings.GetDelimitedText: string;
  4. ...
  5. end;

This is what I got in the result:

Code: Pascal  [Select][+][-]
  1. // To optimize this, you can use a TStringBuilder object, which is designed for efficient string manipulations, especially when building a string in a loop. Here's how you can modify your function:
  2.  
  3. uses
  4.   SysUtils, StrUtils, Classes;
  5.  
  6. function TStrings.GetDelimitedText: string;
  7. var
  8.   I: Integer;
  9.   S: String;
  10.   BreakChars: set of Char;
  11.   DoQuote: Boolean;
  12.   StringBuilder: TStringBuilder;
  13. begin
  14.   CheckSpecialChars;
  15.   if StrictDelimiter then
  16.     BreakChars := [#0, QuoteChar, Delimiter]
  17.   else
  18.     BreakChars := [#0..' ', QuoteChar, Delimiter];
  19.  
  20.   StringBuilder := TStringBuilder.Create;
  21.   try
  22.     for I := 0 to Count - 1 do
  23.     begin
  24.       S := Strings[I];
  25.       DoQuote := FAlwaysQuote;
  26.       if not DoQuote then
  27.       begin
  28.         // Quote strings that include BreakChars
  29.         DoQuote := StrHasChars(S, True, BreakChars);
  30.       end;
  31.       if DoQuote and (QuoteChar <> #0) then
  32.         StringBuilder.Append(AnsiQuotedStr(S, QuoteChar))
  33.       else
  34.         StringBuilder.Append(S);
  35.  
  36.       if I < Count - 1 then
  37.         StringBuilder.Append(Delimiter);
  38.     end;
  39.  
  40.     // Quote empty string
  41.     if (StringBuilder.Length = 0) and (Count = 1) and (QuoteChar <> #0) then
  42.       StringBuilder.Append(QuoteChar).Append(QuoteChar);
  43.  
  44.     Result := StringBuilder.ToString;
  45.   finally
  46.     StringBuilder.Free;
  47.   end;
  48. end;
  49.  
  50. // Helper function to check if a string contains any character from a set
  51. function StrHasChars(const Str: string; Strict: Boolean; const Chars: TSysCharSet): Boolean;
  52. var
  53.   P: PChar;
  54. begin
  55.   P := PChar(Str);
  56.   while (P^ <> #0) and (not CharInSet(P^, Chars) or Strict) do Inc(P);
  57.   Result := P^ <> #0;
  58. end;
  59.  
  60.  

It's not perfect but looks like a very good reply to me...

 

TinyPortal © 2005-2018