Page 1 of 1

ChatGPT: something to play with over Christmas

Posted: Friday 23rd December 2022 12:40pm
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 17238 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!

Re: ChatGPT: something to play with over Christmas

Posted: Friday 23rd December 2022 1:48pm
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

Re: ChatGPT: something to play with over Christmas

Posted: Friday 23rd December 2022 7:23pm
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.

Re: ChatGPT: something to play with over Christmas

Posted: Monday 26th December 2022 5:19am
by Technopeasant
Funny. :lol:

Re: ChatGPT: something to play with over Christmas

Posted: Friday 27th January 2023 5:00am
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: ).

Re: ChatGPT: something to play with over Christmas

Posted: Monday 6th February 2023 8:13pm
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

Re: ChatGPT: something to play with over Christmas

Posted: Friday 3rd March 2023 3:14pm
by cogier
I now have access to the Bing AI. Here is my first question and the answer. The code works without modification!

Image

This is the code: -
Public Sub Button1_Click()

  Dim i As Integer
  Dim s As String

  s = ""

  For i = Asc("A") To Asc("Z")
    s &= Chr(i) & " = " & Str(i) & "\n"
  Next

  TextArea1.Text = s

End

Re: ChatGPT: something to play with over Christmas

Posted: Friday 1st September 2023 3:43pm
by Bigfooter
Agreed, ChatGPT makes learning and exploring various subject matters really fun and interactive, like having a smart assistant at your disposal. It's incredible how it can explain how to cook a basic meal or translate a code snippet into a different language. I've used it to brush up on a few programming languages, and it elaborates complex procedures into simple instructions. The possibilities are endless and indeed make for a fantastic learning pastime.

I've been giving Special Character AI a go recently. This free AI tool has simplified working with special characters in my projects. It's especially useful when dealing with strings and needing specific character sets. Just thought it might be worth mentioning as another neat AI-powered tool to try out.

Re: ChatGPT: something to play with over Christmas

Posted: Monday 4th September 2023 7:11pm
by cage
So when are we going to get AI on the board. Just think you won't have to have any human interaction or have to even learn how to program in Gambas. AI will be able to do it all. Have a problem with your program, or have a question AI will do it all for you.