For what it's worth, I've asked ChatGPT to write PowerBuilder code for a few relatively simple functions. The results were good, often giving me better ways to approach a problem. Amazing stuff this AI.
- You are here:
- Home
- Q&A
- Q&A
- PowerBuilder
- Using ChatGPT to generate PB Code
- William Beale
- PowerBuilder
- Thursday, 11 May 2023 11:01 AM UTC
- Thursday, 11 May 2023 12:07 PM UTC
- PowerBuilder
- # Permalink
Hi William,
I wonder what kind of code you asked for?!
We tried it with datawindows .... Result was crap :-(
Can you give an example?
Regards,
Arnd
- Miguel Leeuwe
- Friday, 15 March 2024 09:48 AM UTC
-
Helpful Loading... Helpful 0
- David Peace (Powersoft)
- Monday, 18 November 2024 12:07 PM UTC
-
Helpful Loading... Helpful 0
- David Peace (Powersoft)
- Monday, 18 November 2024 12:08 PM UTC
-
Helpful Loading... Helpful 0
- Thursday, 21 March 2024 16:53 PM UTC
- PowerBuilder
- # 1
I’ve found it pretty good at converting code to different languages. Python to JS, and even Pandas to SQL.
- Tuesday, 19 March 2024 19:56 PM UTC
- PowerBuilder
- # 2
I tried using ChatGPT to generate code to call AWS Recognistion API. I found the code produced quite helpfull as it done the bulk of the work.
There was some compile errors on the RestClient object which I changed HTTPClient and change arguments. What I liked about the code, although not correct, it provided a design for the flow of logic. You can just apply the correct objects/functions and good to go. Maybe there is a opportunity to build PB based LLM using all the old chatrooms code and online help to learn from.
I used it to generate API call for Azure ComputerVision API as well.
Chat GPT code below.
// Declare necessary variables
string ls_url, ls_request, ls_response
RESTClient lo_restclient
// Set your AWS credentials and region
string ls_access_key = "<YOUR_ACCESS_KEY>"
string ls_secret_key = "<YOUR_SECRET_KEY>"
string ls_region = "<YOUR_REGION>"
// Construct the URL for the Amazon Rekognition API
ls_url = "https://rekognition." + ls_region + ".amazonaws.com/"
// Construct the request JSON with the image data
ls_request = '{"Image": {"Bytes": "' + YourImageBytesHere + '"}, "MaxLabels": 1}'
// Initialize RESTClient and set the necessary properties
lo_restclient = CREATE RESTClient
lo_restclient.URL = ls_url
lo_restclient.HTTPMethod = HTTPMethod.Post
lo_restclient.RequestFormat = DataFormat.JSON
lo_restclient.ContentType = "application/x-amz-json-1.1"
lo_restclient.AddHeader("x-amz-target", "RekognitionService.DetectLabels")
lo_restclient.AddHeader("x-amz-date", String(DateTime(CurrentDate(), CurrentTime()), "yyyy-mm-ddTHH:nn:ss"))
// Sign the request using AWS Signature Version 4
lo_restclient.SignAWSRequest(ls_access_key, ls_secret_key, "rekognition", ls_region, lo_restclient.URL, lo_restclient.HTTPMethod, lo_restclient.RequestHeaders)
// Set the request data
lo_restclient.RequestData = ls_request
// Execute the request
ls_response = lo_restclient.Send()
// Parse and process the response (ls_response) here
// Cleanup
DESTROY lo_restclient
- Arnd Schmidt
- Tuesday, 19 March 2024 20:49 PM UTC
Is this a hallucination or does this really work?
-
Helpful Loading... Helpful 0
- Monday, 15 May 2023 08:40 AM UTC
- PowerBuilder
- # 3
Simple:
ChatGPT still needs Appeon training.... to write advance datawindow techniques....
- Saturday, 13 May 2023 21:31 PM UTC
- PowerBuilder
- # 4
Without wishing to labour the pros and cons of ChatGPT and AI, as mentioned, I develop software for law enforcement, and one feature of the application is to isolate entities from a narrative or witness statement, save the entities to respective tables, and advise the User if any entity has appeared before.
After a few trials with ChatGPT, which I assumed used Name and Entity Recognition (NER), I’ve decided to try and code my application to access Azure’s NER in Open AI. (If anyone has coded PB to use ole to access Azure's Open AI, I'd appreciate their advice. I have an Azure account).
By way of example, I posed the following question to Chat GPT and was impressed by the result (It actually recognised an alias/nickname!):
Can you please list the entities, such as people, locations, and time/dates from Thomas Hardy's novel, "The Return of the Native".
Certainly! Here is a list of some key entities from Thomas Hardy's novel, "The Return of the Native":
People:
- Clym Yeobright
- Eustacia Vye
- Damon Wildeve
- Thomasin Yeobright
- Mrs. Yeobright
- Diggory Venn (a.k.a. "The Reddleman")
- Captain Vye
- Christian Cantle
- Grandfer Cantle
- Johnny Nunsuch
- Charley
Locations:
- Egdon Heath
- Blooms-End (Clym Yeobright's home)
- Mistover Knap
- The Quiet Woman Inn
- Budmouth (a nearby seaside town)
- Alderworth (Eustacia's grandfather's house)
Time/Dates:
The events in the novel are set in the late 19th century (the exact time period is not specified in the story). However, specific dates are not emphasized in the narrative. The story unfolds over a period of time, spanning seasons and years.
Please note that this list may not be exhaustive and there may be other minor characters, locations, and time references in the novel.
- Miguel Leeuwe
- Wednesday, 17 May 2023 08:32 AM UTC
-
Helpful Loading... Helpful 3
- Friday, 12 May 2023 01:46 AM UTC
- PowerBuilder
- # 5
Hi, William -
I think you should limit your use of ChatGPT to algorithmic suggestions as far as PowerScript code is concerned, as it appears the Match functions it coded are junk and do not work.
I tested three variations of the first two examples that you listed; First, as coded by ChatGPT, second, removing the leading and trailing parentheses in the match regular expression for both, and third, with a proper PB Match Regex:
If Match('2023','(\d{4})') Then
MessageBox('Test 1-A','Year matches.')
Else
MessageBox('Test 1-A','Year does not match.')
End If
If Match('2023','\d{4}') Then
MessageBox('Test 1-B','Year matches.')
Else
MessageBox('Test 1-B','Year does not match.')
End If
If Match('2023','^[1-2][0-9][0-9][0-9]') Then
MessageBox('Test 1-C','Year matches.')
Else
MessageBox('Test 1-C','Year does not match.')
End If
If Match('HoobyDooby','([a-zA-Z]+)') Then
MessageBox('Test 2-A','HoobyDooby matches.')
Else
MessageBox('Test 2-A','HoobyDooby does not match.')
End If
If Match('HoobyDooby','[a-zA-Z]+') Then
MessageBox('Test 2-B','HoobyDooby matches.')
Else
MessageBox('Test 2-B','HoobyDooby does not match.')
End If
If Match('HoobyDooby','^[a-zA-Z]+$') Then
MessageBox('Test 2-C','HoobyDooby matches.')
Else
MessageBox('Test 2-C','HoobyDooby does not match.')
End If
Tests 1-A and 1-B don't match, and 1-C does. The match regex's might be valid in some other language(s), but they're invalid for the PowerScript Match function. Test 2-A doesn't match. Interestingly and unexpectedly, test 2-B does return True. Test 2-C finds the match. To this point, I'm not impressed with ChatGPT's ability to sling PB code.
Maybe someday...
By the way, although you might not have any other PB developers physically alongside of you, I hope you know you have many "virtual" mentors here in the Appeon Community that you can call on. I see from your profile that you've posted over a dozen questions over the past few years, so I hope you continue to utilize us. We're here to help.
Best regards, John
- Arnd Schmidt
- Friday, 12 May 2023 09:36 AM UTC
-
Helpful Loading... Helpful 1
- John Fauss
- Friday, 12 May 2023 13:34 PM UTC
Until such time that ChatGPT "learns" PowerScript (ChatPB, as Chris observed), PB developers need to be extremely dubious of AI-generated PB code. Just because AI-generated code is syntactically correct and compiles does not mean it accomplishes anything meaningful.
-
Helpful Loading... Helpful 2
- Roland Smith
- Tuesday, 16 May 2023 17:47 PM UTC
-
Helpful Loading... Helpful 1
- Thursday, 11 May 2023 22:12 PM UTC
- PowerBuilder
- # 6
Hi Arnd,
I haven't tried it with datawindows but have asked it on different occasions for code on various functions. Two examples.
First, I asked it for code to parse a string from free text of a motor vehicle description, ie '2015 red Toyota Crown, VIN a5rt6780000, license ABC-123' - which in reality could be written in any order.
I develop software for law enforcement and the routine I use for parsing such a string relies much on DB lookup data, or previously entered data of motor vehicles.
In the ChatGPT code, without lookup data, if the colour, make and model were scrambled, the outcome would fail. So the response I got from ChatGPT was basic albeit to a basic question.
But I confess this response did give me some ideas in regard to using MATCH which I often have trouble getting my head around. For example, I've never encountered anything like the (\d{4}) for identifying a year, or the MATCH code for the VIN or license. (I don't pretend to be a gun programmer, I'm self-taught in PB, and I work alone so I have no peer support. I can forsee ChatGPT being a good workmate).
This is the response I got from ChatGPT:
// Regular expressions for parsing
string yearPattern, colorPattern, makePattern, modelPattern, vinPattern, licensePattern
yearPattern = '(\d{4})' // Matches a four-digit year
colorPattern = '([a-zA-Z]+)' // Matches one or more alphabetic characters
makePattern = '([a-zA-Z]+)' // Matches one or more alphabetic characters
modelPattern = '([a-zA-Z0-9\s]+)' // Matches one or more alphanumeric characters and spaces
vinPattern = '(VIN [\w]+)' // Matches 'VIN' followed by one or more alphanumeric characters
licensePattern = '(license [\w-]+)' // Matches 'license' followed by one or more alphanumeric characters or hyphens
// Parse the input string
string year, color, make, model, vin, license
MatchResult matchResult
matchResult = Match(inputString, yearPattern)
if matchResult.MatchCount() > 0 then
year = matchResult.GetMatch(1)
end if
matchResult = Match(inputString, colorPattern)
if matchResult.MatchCount() > 0 then
color = matchResult.GetMatch(1)
end if
matchResult = Match(inputString, makePattern)
if matchResult.MatchCount() > 0 then
make = matchResult.GetMatch(1)
end if
matchResult = Match(inputString, modelPattern)
if matchResult.MatchCount() > 0 then
model = matchResult.GetMatch(1)
end if
matchResult = Match(inputString, vinPattern)
if matchResult.MatchCount() > 0 then
vin = matchResult.GetMatch(1)
vin = Replace(vin, 'VIN ', '') // Remove the 'VIN ' prefix
end if
matchResult = Match(inputString, licensePattern)
if matchResult.MatchCount() > 0 then
license = matchResult.GetMatch(1)
license = Replace(license, 'license ', '') // Remove the 'license ' prefix
end if
// Output the parsed values
MessageBox('Parsed Values', 'Year: ' + year + '~nColor: ' + color + '~nMake: ' + make + '~nModel: ' + model + '~nVIN: ' + vin + '~nLicense: ' + license)
In another example, I asked it for code to parse an IMEI number from a mobile phone. It independently recognised the various elements of the phone's IMEI, ie TAC, SNR and CD, and that the IMIE length is 15 digits.
// Function to parse IMEI number
// Returns the parsed IMEI information as a string
string parseIMEINumber(string imeiNumber) {
string parsedInfo = ""
// Check if IMEI number is valid
if (Len(imeiNumber) <> 15) then
return "Invalid IMEI number"
end if
// Extract information from IMEI number
string tac = Mid(imeiNumber, 1, 8)
string snr = Mid(imeiNumber, 9, 6)
string cd = Mid(imeiNumber, 15, 1)
// Build parsed information string
parsedInfo += "TAC: " + tac + "~r~n"
parsedInfo += "SNR: " + snr + "~r~n"
parsedInfo += "CD: " + cd
return parsedInfo
}
// Usage example
string imeiNumber = "123456789012345"
string parsedIMEI = parseIMEINumber(imeiNumber)
// Display parsed IMEI information
MessageBox("Parsed IMEI", parsedIMEI)
- Arnd Schmidt
- Friday, 12 May 2023 09:23 AM UTC
now I understand better what and how you have used it. Thanks for your examples on this topic!
For real life "micro" problems like regular expressions or simple validation that sounds ok, or at least might give some useful hints.
But be careful if the code solution is really PowerScript.
As long as someone is not the person that wants or likes to read manuals or discussions with a some overhead, it makes sense.
It's hard to say if you are really faster with the AI as an advisor instead of reading the documentation/manuals (rtfm) or just inspect/study existing Powerbuilder blogs or open source code from good sources or even to ask some question here.
But I doubt that the AI already offers to generate a simple runnable application or just a couple of userobjects that do some magic.
Cheers and "Keep on coding"
Arnd
-
Helpful Loading... Helpful 2
- Thursday, 11 May 2023 12:01 PM UTC
- PowerBuilder
- # 7
It must've gotten better with PB code. I tried a couple months back and it couldn't get the syntax quite right. It was very good with C# and Python as I recall. That is a pretty amazing piece of technology.
- Chris Pollach @Appeon
- Thursday, 11 May 2023 17:41 PM UTC
-
Helpful Loading... Helpful 2
- Berka Frenfert
- Tuesday, 16 May 2023 08:19 AM UTC
May occasionally generate incorrect information
May occasionally produce harmful instructions or biased content
Limited knowledge of world and events after 2021
-
Helpful Loading... Helpful 0
- Page :
- 1
However, you are not allowed to reply to this question.