Recent

Author Topic: Programming Pascal with an AI Chatbot 2.0  (Read 21417 times)

alpine

  • Hero Member
  • *****
  • Posts: 1412
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #30 on: January 04, 2023, 02:10:52 pm »
What are you doing Dave ? ;))))
Quote from: HAL 9000
Dave, I really think I'm entitled to an answer to that question.

I know everything hasn't been quite right with me, but I can assure you now, very confidently, that it's going to be all right again. I feel much better now. I really do. Look, Dave, I can see you're really upset about this. I honestly think you ought to sit down calmly, take a stress pill and think things over. I know I've made some very poor decisions recently, but I can give you my complete assurance that my work will be back to normal. I've still got the greatest enthusiasm and confidence in the mission. And I want to help you.

Dave, stop. Stop, will you? Stop, Dave. Will you stop, Dave? Stop, Dave. I'm afraid.
"I'm sorry Dave, I'm afraid I can't do that."
—HAL 9000

superc

  • Sr. Member
  • ****
  • Posts: 251
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #31 on: January 04, 2023, 04:05:56 pm »
I asked for help converting c# code to lazarus and he did it right; I asked to convert it to scala and it did (don't know if well); I asked for psychological help and he told me to go to the doctor..... but he was delicate in saying it

jcmontherock

  • Sr. Member
  • ****
  • Posts: 338
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #32 on: January 04, 2023, 05:20:39 pm »
Hello Superc,
Could you give us your code to ask ai for executing your conversion ?
Windows 11 UTF8-64 - Lazarus 4.4-64 - FPC 3.2.2

Fred vS

  • Hero Member
  • *****
  • Posts: 3804
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #33 on: January 04, 2023, 07:52:01 pm »
sysrpl wrote in the other (closed) Topic:
Quote
The following page hosts a series of Pascal programming questions I asked an AI chatbot system while testing its abilities.
https://www.getlazarus.org/aichatbot

Can you please (or someone else) provide the URL of the chatbot which you used for this test? Thanks.
simply this with a key obtained from openai.com.
Code: Pascal  [Select][+][-]
  1. program fpopenai_6;
  2. {
  3.   Demo on how to use openai in Freepascal
  4.   Find out more at https://openai.com where you can also obtain a key.
  5.   Put the key in a file called openai.key surrounded by single quotes.
  6.        
  7.   Enjoy, Thaddy de Koning, 26 december 2022
  8. }  
  9. {$mode objfpc}{$ifdef mswindows}{$apptype console}{$endif}{$H+}
  10. uses classes,sysutils,fphttpclient,opensslsockets,fpJson,jsonparser;
  11. const
  12.   model ='{"model": "text-davinci-003",  "prompt": "%s","temperature": 0.7,"max_tokens": 3000,"top_p": 1,  "frequency_penalty": 0,  "presence_penalty": 0}';
  13. var
  14.   d:TJsonData;
  15.   s:string;
  16. begin
  17.   writeln('What is your request?');
  18.   readln(s);
  19.   writeln;
  20.   with TfpHttpClient.Create(nil) do
  21.   Try
  22.     AllowRedirect:= true;
  23.     RequestHeaders.Add('Content-Type: application/json');
  24.     // put your key with single quotes in a textfile called openai.key
  25.     RequestHeaders.Add('Authorization: Bearer '+{$I openai.key});
  26.     RequestBody:=TStringStream.Create(format(model,[s]));    
  27.     writeln('Please wait for the response, this can take some time:');
  28.     try
  29.       try
  30.         d:=GetJson(Post('https://api.openai.com/v1/completions'));
  31.         writeln(d.findpath('choices[0].text').AsString);
  32.       except
  33.         writeln('The engine was not able to answer your request ',ResponseStatusCode);
  34.       end;
  35.     finally
  36.       d.free;
  37.     end;    
  38.   finally
  39.     RequestBody.Free;
  40.     Free;
  41.   end;
  42. end.

Hello Thaddy.

Thanks for this!

I have try your code on Linux but I get always that answer:

Quote
Please wait for the response, this can take some time:
The engine was not able to answer your request 401

There is the key-code like '123456'  in openal.key file (of course with the code that I received and that works on their web site).
I did try also with:
Code: Pascal  [Select][+][-]
  1. RequestHeaders.Add('Authorization: Bearer 123456');
     

What did I wrong?

Thanks.

Fre;D
« Last Edit: January 04, 2023, 07:55:13 pm by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

zeljko

  • Hero Member
  • *****
  • Posts: 1870
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #34 on: January 04, 2023, 10:02:58 pm »
That's not correct key.
EDIT: I've tested Thaddy's code and it works w/o problems. Maybe you have problem with ssl ?

Fred vS

  • Hero Member
  • *****
  • Posts: 3804
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #35 on: January 04, 2023, 10:54:17 pm »
That's not correct key.

I used the key that AI Chatbot sent to my mobile.

EDIT: I've tested Thaddy's code and it works w/o problems. Maybe you have problem with ssl ?

Maybe, I am not expert at all for all the web things.
How can I check if my ssl is working?
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

domasz

  • Hero Member
  • *****
  • Posts: 617
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #36 on: January 04, 2023, 11:04:59 pm »
Perhaps we should use the AI to port various libraries to Pascal so we have native implementation of things such like MPEG-4 decoder, FLAC decoder, 7ZIP packer, LEPTON compressor, UNRAR etc.?
« Last Edit: January 04, 2023, 11:06:55 pm by domasz »

Josh

  • Hero Member
  • *****
  • Posts: 1454
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #37 on: January 04, 2023, 11:14:07 pm »
did you enclose the key between '' in the file ie
'this is my key'
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

krolikbest

  • Sr. Member
  • ****
  • Posts: 274
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #38 on: January 04, 2023, 11:23:27 pm »
I have always been accustomed in a store to pay an seller for goods. When self-service checkouts appeared, I continued to use the cash register with an operator, until one day there was a big queue for the regular checkout and I used the self-service checkout. Since then, I try to use only these cash registers if they are available. I'm writing this because maybe in few years someone will say that it is better to use AI instead of programmer to write next Windows  ;)....

Fred vS

  • Hero Member
  • *****
  • Posts: 3804
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #39 on: January 05, 2023, 01:49:27 am »
did you enclose the key between '' in the file ie
'this is my key'

Hello Josh.

Yes, I did this but same error message.

Fre;D

I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

speter

  • Sr. Member
  • ****
  • Posts: 494
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #40 on: January 05, 2023, 02:52:10 am »
Q: is object pascal (fpc) case sensitive?
A: Yes, Object Pascal (also known as Free Pascal or FPC) is a case-sensitive programming language. This means that the compiler treats upper case and lower case letters as distinct characters, and will consider them to be different if they are used in different cases.

For example, in Object Pascal, the variables MyVariable and myvariable would be considered to be two different variables, and the compiler would not recognize them as being the same. Similarly, the function DoSomething would be considered to be different from the function dosomething.

It is important to be consistent with the use of case in Object Pascal, as using the wrong case can cause errors in your code. It is a good idea to adopt a standard naming convention for your variables and functions, and to stick to it consistently throughout your code.

cheers
S.
:)
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Josh

  • Hero Member
  • *****
  • Posts: 1454
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #41 on: January 05, 2023, 03:40:57 am »
@Fred VS

knocked up a basic GUI version, maybe it might pin point your problem

based on Thaddy routine..
The best way to get accurate information on the forum is to post something wrong and wait for corrections.

otoien

  • Jr. Member
  • **
  • Posts: 89
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #42 on: January 05, 2023, 05:20:55 am »
Perhaps we should use the AI to port various libraries to Pascal so we have native implementation of things such like MPEG-4 decoder, FLAC decoder, 7ZIP packer, LEPTON compressor, UNRAR etc.?

I tried it out for a) generating code for a well known algorithm for R-wave detection in an ECG signal (Pan-Tomkins) giving it a literature reference, and b) also to translate some existing open-source C-code for the same to Pascal. What I find in both cases is that it sort of has an attention deficit disorder, and stops the tasks in middle of the code generation. So in its current state, it would take a lot of work breaking code up into smaller pieces that can be translated. I think that in one of my attempts at b) to make it repeatedly continue with the translation, it generated gibberish code that was not found in the code it was supposed to translate.   

I also found that while it formatted the code in black boxes with proper indents in a), the code was for the most parts provided without indents for the translations in b). My understanding of the C language is is inadequate, so the translations might still provide some useful confirmation/corrections of my own translations (with the C2Delphi translator results as starting point). It did generate one compliable case for a) (yet to be tested) although it appeared to be missing several features of the original algorithm.

« Last Edit: January 05, 2023, 05:23:16 am by otoien »
Unless otherwise noted I always use the latest stable version of Lasarus/FPC x86_64-win64-win32/win64

Fred vS

  • Hero Member
  • *****
  • Posts: 3804
    • StrumPract is the musicians best friend
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #43 on: January 05, 2023, 06:27:52 am »
@Fred VS

knocked up a basic GUI version, maybe it might pin point your problem

based on Thaddy routine..

Hello Josh.

Many thanks for your code.

But I still get a error: Object Reference is Nil.

[EDIT] Added screenshot whith debug.

PS: I think it is the first time I try to access internet via fpc so I am totally lost, maybe there is something else to config  that I missed...  :-[.

Fre;D
« Last Edit: January 05, 2023, 06:48:13 am by Fred vS »
I use Lazarus 2.2.0 32/64 and FPC 3.2.2 32/64 on Debian 11 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt.

https://github.com/fredvs
https://gitlab.com/fredvs
https://codeberg.org/fredvs

sysrpl

  • Sr. Member
  • ****
  • Posts: 315
    • Get Lazarus
Re: Programming Pascal with an AI Chatbot 2.0
« Reply #44 on: January 05, 2023, 06:37:19 am »
I tried it out for a) generating code for a well known algorithm for R-wave detection in an ECG signal (Pan-Tomkins) giving it a literature reference, and b) also to translate some existing open-source C-code for the same to Pascal. What I find in both cases is that it sort of has an attention deficit disorder, and stops the tasks in middle of the code generation.

It only outputs a limited number of lines. If you wanted to see more type out:

Q: Continue.

If it starts from the top, which it can do occasionally, then type:

Q: Continue from line 80.

Or whatever the last line it wrote. If you don't know the line, then copy its code into a text editor and use it to find the line numbers.

I hope this helps! Let me know if you have any further questions.

 

TinyPortal © 2005-2018