Programming with Chatgpt

General discussion for topics related to the FreeBASIC project or its community.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Programming with Chatgpt

Post by BasicCoder2 »

Just finished viewing this presentation on ChatGPT and found it easy to follow and interesting.
https://dronebotworkshop.com/chatgpt/
Wonder if it can also write a FreeBASIC program from a text description.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

I asked this: tell me about melissa o'neil's pcg32 prng

The response was concise but spot on.

I then requested this: write code in freebasic using pcg32 prng

The code generated used Uint64 and Uint32, so I included windows.bi. It also used C's bitwise shifts >> and << so I replaced them with shr and shl respectively.

A Quick Run in WinFBE worked fine, and it generated 10 random Ulongs as a test.

I checked the code and could not fault it apart from the include and bitwise shifts.

Considering Chatgpt is a prototype of only a few months, it is impressive.
BasicCoder2
Posts: 3906
Joined: Jan 01, 2009 7:03
Location: Australia

Re: Programming with Chatgpt

Post by BasicCoder2 »

@deltarho[1859]

Wow. Thanks for letting us know what you found about Chatgpt's abilities.
What if you ask it a simple beginner problem like:
"Write a FreeBASIC program to print out the nine times multiplication table."
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

"Write a FreeBASIC program to print out the nine times multiplication table."

I got this:

Code: Select all

for i = 1 to 9
  for j = 1 to 9
    print using "##"; i * j;
  next j
  print
next i
with

This program uses two nested for loops to iterate over the numbers 1 to 9. The inner loop performs the multiplication and uses the print statement with a format string of "##" to print out the result with two digits. The outer loop then prints a newline character to separate the rows.

The output was:

Code: Select all

  1 2 3 4 5 6 7 8 9
 2 4 6 81012141618
 3 6 9121518212427
 4 812162024283236
 
 51015202530354045
 61218243036424854
 71421283542495663
 81624324048566472
 91827364554637281
Which is not what we asked for.

I had to add declarations.

I clicked 'Regenerate response' and got this:

Code: Select all

FOR i = 1 TO 9
    FOR j = 1 TO 9
        PRINT i; " * "; j; " = "; i * j
    NEXT j
    PRINT
NEXT i
END
with

This program uses two FOR loops to iterate over the numbers 1 to 9, and within the inner loop, it calculates and prints the product of the current values of i and j. The semicolons are used to separate the elements printed on each line. The final PRINT statement adds a blank line after each row of the multiplication table.

The output, after replacing END with SLEEP was:

Code: Select all

1 *  1 =  1
 1 *  2 =  2
 1 *  3 =  3
 1 *  4 =  4
 1 *  5 =  5
 1 *  6 =  6
 1 *  7 =  7
 1 *  8 =  8
 1 *  9 =  9

 2 *  1 =  2
 2 *  2 =  4
 2 *  3 =  6
 2 *  4 =  8
 2 *  5 =  10
 2 *  6 =  12
 2 *  7 =  14
 2 *  8 =  16
 2 *  9 =  18

 3 *  1 =  3
 3 *  2 =  6
 3 *  3 =  9
 3 *  4 =  12
 3 *  5 =  15
 3 *  6 =  18
 3 *  7 =  21
 3 *  8 =  24
 3 *  9 =  27

 4 *  1 =  4
 4 *  2 =  8
 4 *  3 =  12
 4 *  4 =  16
 4 *  5 =  20
 4 *  6 =  24
 4 *  7 =  28
 4 *  8 =  32
 4 *  9 =  36

 5 *  1 =  5
 5 *  2 =  10
 5 *  3 =  15
 5 *  4 =  20
 5 *  5 =  25
 5 *  6 =  30
 5 *  7 =  35
 5 *  8 =  40
 5 *  9 =  45

 6 *  1 =  6
 6 *  2 =  12
 6 *  3 =  18
 6 *  4 =  24
 6 *  5 =  30
 6 *  6 =  36
 6 *  7 =  42
 6 *  8 =  48
 6 *  9 =  54

 7 *  1 =  7
 7 *  2 =  14
 7 *  3 =  21
 7 *  4 =  28
 7 *  5 =  35
 7 *  6 =  42
 7 *  7 =  49
 7 *  8 =  56
 7 *  9 =  63

 8 *  1 =  8
 8 *  2 =  16
 8 *  3 =  24
 8 *  4 =  32
 8 *  5 =  40
 8 *  6 =  48
 8 *  7 =  56
 8 *  8 =  64
 8 *  9 =  72

 9 *  1 =  9
 9 *  2 =  18
 9 *  3 =  27
 9 *  4 =  36
 9 *  5 =  45
 9 *  6 =  54
 9 *  7 =  63
 9 *  8 =  72
 9 *  9 =  81
It is still not getting it. The last block only is what we should be getting.

Regenerating again and got this.

Code: Select all

FOR i = 1 TO 9
    PRINT "9 x "; i; " = "; 9 * i
NEXT i
END
The output, after replacing END with SLEEP, was:

Code: Select all

9 x  1 =  9
9 x  2 =  18
9 x  3 =  27
9 x  4 =  36
9 x  5 =  45
9 x  6 =  54
9 x  7 =  63
9 x  8 =  72
9 x  9 =  81
It finally got there.

It obviously got embarrassed because it didn't explain the code this time.

So, it was making a right dog's dinner out of a simple job.

The secret is to force it to rethink if you dislike what you are looking at.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

I am working on a project which requires a 128-bit counter. FreeBASIC has not got a 128-bit datatype. There are a few ways to do this so I got Chatgpt to look at it.

The first attempt used a 16 byte array and was cumbersome, so I forced it to think again. The second attempt was not much better.

The third attempt started with:

Code: Select all

Type UInt128
  LowPart As Longlong
  HighPart As Longlong
End Type

Now we are getting somewhere because that is what I would do. I had to use windows.bi for LongLong; which is MSDN speak.

The rest of the code was respectable and failing any improvements by yours truly may end up in my project.

For FreeBASIC coding purposes Chatgpt works, but it is lazy and will churn out the fastest response it can get away with. To get the best out of it, we may have to lean on it by clicking on the 'Regenerate response' button.

It is not infallible, so DO NOT use in your code without getting your fine tooth comb out. :)
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

During testing, the logic wasn't quite right, so I went back and tried a few more regenerate tasks.

It just couldn't get it right.

It seems to fail with simple requests, which is a pity because it did a remarkable job with pcg32 prng.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

I went back to the third attempt and used:

Code: Select all

Type UInt128
  LowPart As Ulongint
  HighPart As Ulongint
End Type
with Ulongint replacing LongLong.

I'll do a few tests, but it seems to be working.

It doesn't understand that when we overflow signed, we go negative, but when we overflow unsigned, we go back to zero.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

It is worth pointing out that if you register, you will not get your Inbox bombarded with emails. I have not heard from openai.com since I registered. At some point, they may contact me about a commercial version, but I have no objection to that. I have no idea why they waned my mobile number – perhaps it is a security issue.

So go ahead and register.

Added: The Pro version is likely to cost $42 (34.08 GBP) per month. Chatgpt costs a lot to run. Perhaps the free version will be phased out. The Pro version will see much less 'At capacity notifications' and will be faster, but even so I won't be buying into it.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: Programming with Chatgpt

Post by srvaldez »

I don't understand what the fuzz is all about, it seems that the whole world is going gaga over this Chatgpt, before you know it people will deify Chatgpt and treat as a superior intelligent entity :roll:
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming with Chatgpt

Post by dodicat »

I'm starting on some hymns.
I'll try them out at closing time.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

srvaldez wrote:people will deify Chatgpt and treat as a superior intelligent entity, :roll:
I think I have shown that it isn't. On the one we have the wow factor with pcg32 prng for example and on the hand we have “Oh boy are you struggling with this one.”
Last edited by deltarho[1859] on Jan 31, 2023 17:36, edited 2 times in total.
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

It is worth mentioning that my only experience with Chatgpt is with coding. I have seen a few videos describing other uses. I can imagine many professions more than happy to part with 42 dollars a month.

Of course, criticism not evidence based doesn't cost anything. :)
deltarho[1859]
Posts: 4292
Joined: Jan 02, 2017 0:34
Location: UK
Contact:

Re: Programming with Chatgpt

Post by deltarho[1859] »

I have just read about someone who didn't ask for code, but presented code which was not working. Chagpt came back with working code, and it explained why his was not working.

Chatgpt as a debugger? That had not occurred to me. :)
marcov
Posts: 3454
Joined: Jun 16, 2005 9:45
Location: Netherlands
Contact:

Re: Programming with Chatgpt

Post by marcov »

deltarho[1859] wrote: Feb 01, 2023 16:09 I have just read about someone who didn't ask for code, but presented code which was not working. Chagpt came back with working code, and it explained why his was not working.
A single event doesn't help much, it must be somewhat reliable. Even a broken clock is shows the right time twice a day.

I only half followed the noise about chatgpt, but it seems mostly demonstration, and running own instances seems to be difficult (much more massive machinery required for training than for running)
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Programming with Chatgpt

Post by dodicat »

It was on the TV a couple of days ago as well.
Another money spinner coming up the ranks.
But if you like it, fair enough.
Post Reply