ChatGPT: something to play with over Christmas

Feel free to talk about non programming issues here.
Post Reply
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

ChatGPT: something to play with over Christmas

Post by stevedee »

ChatGPT is an AI chatbot. Basically you can ask it questions and it will (hopefully) come back with sensible answers.

For example, I asked: "How to cook rice" and this was its reply:-
There are many ways to cook rice, but one of the most basic methods is as follows:

Rinse the rice in a fine mesh strainer under cold running water. This removes excess starch and dirt from the grains.

Measure the rice and water. For most types of rice, you will need 1 1/2 to 2 cups of water for every cup of rice.

Place the rice and water in a pot with a tight-fitting lid. Bring the mixture to a boil over high heat.

Once the water is boiling, reduce the heat to low and cover the pot with the lid.

Let the rice simmer for 18-20 minutes or until it is tender and the water has been absorbed. Do not lift the lid or stir the rice during this time.

When the rice is finished cooking, remove the pot from the heat and let it sit, covered, for an additional 5 minutes. This allows the rice to steam and become fluffier.

Fluff the rice with a fork and serve.

Note: Some types of rice, such as basmati and jasmine, may require a different water-to-rice ratio and cooking time. Consult the package instructions for specific recommendations.
But its not just a cooking app. Try asking it a coding question: "Write Gambas code to sort list of names"
ChatAI_GambasSort.png
ChatAI_GambasSort.png (113.31 KiB) Viewed 208 times
The full code output looks like this:-

' Declare an array of strings
DIM names(10) AS STRING

' Initialize the array with some values
names(0) = "Alice"
names(1) = "Bob"
names(2) = "Charlie"
names(3) = "David"
names(4) = "Eve"
names(5) = "Frank"
names(6) = "Greta"
names(7) = "Henry"
names(8) = "Ida"
names(9) = "Jack"

' Perform bubble sort on the array
FOR i = 0 TO LEN(names) - 2
  FOR j = 0 TO LEN(names) - i - 2
    IF names(j) > names(j+1) THEN
      ' Swap the values
      DIM temp AS STRING
      temp = names(j)
      names(j) = names(j+1)
      names(j+1) = temp
    END IF
  NEXT
NEXT

' Print the sorted array
FOR i = 0 TO LEN(names) - 1
  PRINT names(i)
NEXT



Perhaps you want to see what this code would look like in PHP:-
"Rewrite this code in PHP"

...I'll leave you to imagine the possibilities for finding coding solutions, improving your coding skills and converting existing code to other languages.


Once you have registered, use https://chat.openai.com/chat to start asking questions.

Happy Christmas!
User avatar
BruceSteers
Posts: 1059
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: ChatGPT: something to play with over Christmas

Post by BruceSteers »

Looks interesting, i wonder how it works.
Gambas help looks kinda like a VB conversion and doesn't even work.
As i'd more simply sort an array like this..

' Declare an array of strings
Dim names AS String[] = ["Alice", "Bob", "Charlie", "David", "Eve", "Frank", "Greta", "Henry", "Ida", "Jack"]
 
' Print the sorted array
Print names.Sort(gb.Natural + gb.IgnoreCase).Join("\n")


I tried
Dim aStr(5) As String
as i thought this was a method i didn't know about but i got "Syntax error" lol
If at first you don't succeed , try something different.
BruceS
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: ChatGPT: something to play with over Christmas

Post by stevedee »

BruceSteers wrote: Friday 23rd December 2022 1:48pm Looks interesting, i wonder how it works...
...I tried
Dim aStr(5) As String
as i thought this was a method i didn't know about but i got "Syntax error" lol
Yes it is interesting.
This ChatBOT is very young and still has plenty to learn.

I started to chat to it earlier;

steve: do you understand gambas arrays
bot: Yes, I am familiar with arrays in Gambas. An array is a data structure that stores a collection of values that are all of the same data type...
steve: write gambas code to sort a list of names
bot:
[i]Here is an example of a bubble sort algorithm implemented in Gambas that can be used to sort a list of names:[/i]

' Declare an array of strings
Dim names As String[] = {"John", "Paul", "George", "Ringo"}

' Perform the bubble sort
For i As Integer = 0 To names.Ubound
    For j As Integer = 0 To names.Ubound - i - 1
        If names[j] > names[j + 1] Then
            ' Swap the names
            Dim temp As String = names[j]
            names[j] = names[j + 1]
            names[j + 1] = temp
        Endif
    Next
Next

' Print the sorted array
For Each name As String In names
    Print name
Next


Obviously this code still does not work, so the chat continued;
steve: that does not work because the {} should be []
bot: You are correct that the curly braces {} should be replaced with square brackets [] when declaring and initializing an array in Gambas. Here is the corrected version of the code that sorts a list of names using a bubble sort algorithm...

...still problems with the new code, the chat continues;
steve: I don't think Gambas uses UBound(), I think it uses Bounds()
bot: You are correct that in Gambas, the Bounds() function is used to get the lower and upper bounds of an array. Here is the corrected version of the code that sorts a list of names using a bubble sort algorithm...

...more problems, more chat;
steve: please recheck as I think the format is names.Bounds.Count
bot: I apologize for the errors in my previous responses. You are correct that in Gambas, you can use the Bounds() function to get the lower and upper bounds of an array, and you can then access the Count property of the Bounds object to get the number of elements in the array...

I assume that if anyone asks the exact question that I asked at the start of this chat, they should get a code example with these problems corrected if the AI bot is really learning from experience.
User avatar
Technopeasant
Posts: 90
Joined: Saturday 13th July 2019 6:50pm
Location: Stony Plain, Alberta, Canada
Contact:

Re: ChatGPT: something to play with over Christmas

Post by Technopeasant »

Funny. :lol:
Technical director,
Piga Software
http://icculus.org/piga/
PartierSP
Posts: 52
Joined: Tuesday 30th November 2021 12:14am
Location: Canada
Contact:

Re: ChatGPT: something to play with over Christmas

Post by PartierSP »

Looks like The Retro Hack Shack tried out your idea Steve, but on a Commodore 64 (video link).

I started to watch it last night before falling asleep. Yes I have a bad habit of watching tech in bed. (Now I'm going to have to try and finish watching it tonight :lol: ).
User avatar
stevedee
Posts: 518
Joined: Monday 20th March 2017 6:06pm

Re: ChatGPT: something to play with over Christmas

Post by stevedee »

The AI race is on: Enter The Bard!

Google are about to release "Bard" as their AI Chatbot alternative, and it looks like Microsoft will shortly be rolling out ChatGPT on Bing: https://www.bbc.co.uk/news/technology-64546299
Post Reply