An AI RegEx generator for someone with time on their hands

This link

has a video of a very fast-talking woman describing how to use an AI API to generate RegEx strings.
It was posted on the Xojo development site. I’m guessing the same kind of interface could be done in Panorama.

It seemed the woman used some Java Script function and the user on Xojo posted an equivalent function using JSON.

Maybe it can be implemented in Panorama if similar tools are available. I’m posting this in case someone wants to play around with AI, Panorama, and Website interaction. If it can’t be done with Panorama tools, let me know and I’ll delete the post. Watch the video first to determine if this is Panorama doable.

Though the example was specific to RegEx string generation, maybe it could be tweaked for more general inquiries.

You will probably need to get a “key” from the OpenAI site. Anyone wanting to use the Panorama routine - if it can be written - should have to input their own key, one time, that would be saved.

The function in Xojo - to model in Panorama - is:

Function ConnectToOpenAI(apiKey As String, prompt As String) As String
// Define OpenAI API URL
Const openAIUrl As String = “https://api.openai.com/v1/engines/davinci-codex/completions

// Initialize HTTPSocket
Var http As New HTTPSocket

// Set request headers
http.SetRequestHeader(“Content-Type”, “application/json”)
http.SetRequestHeader(“Authorization”, "Bearer " + apiKey)

// Define request data
Var requestData As New Dictionary
requestData.Value(“prompt”) = prompt
requestData.Value(“max_tokens”) = 50
requestData.Value(“n”) = 1
requestData.Value(“stop”) = “”

// Send request
Var response As String
Try
response = http.PostJSON(openAIUrl, requestData)
Catch e As IOException
Return "Error: " + e.Message
End Try

// Parse response
Var jsonResponse As Dictionary
Try
jsonResponse = ParseJSON(response)
Catch e As JSONException
Return "Error: " + e.Message
End Try

// Get generated text
Var generatedText As String = “”
If jsonResponse.HasKey(“choices”) Then
Var choices As xojo.Core.Array = jsonResponse.Value(“choices”)
If choices.Count > 0 Then
Var choice As Dictionary = choices(0)
If choice.HasKey(“text”) Then
generatedText = choice.Value(“text”)
End If
End If
End If

Return generatedText
End Function

This may not be true in the future, but for now I think you would be better served to watch the talk I did about regular expressions. It’s really not as hard as people make it out to be.

I won’t continue updating this because it would involve jumping back and forth to the other site for corrections.

The quality of answers is so much better in the Panorama forum. Here, when a question is answered, most of the time, it’s Asked, Answered, and Done.

On other sites, someone posts an answer, then someone corrects that answer. Then someone corrects the previous correction. Eventually, there’s a convergence to a workable solution - but seldom after the first reply post.