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.
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.
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
I’ve found it pretty good at converting code to different languages. Python to JS, and even Pandas to SQL.
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
Simple:
ChatGPT still needs Appeon training.... to write advance datawindow techniques....
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:
Locations:
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.
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
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)
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.