Solution
Use a VB or C# function that calls an OpenAI service via a web call.
Example We want to give the user the option of improving their entered long text via OpenAI, for example the description text in a notification:
After entering the description, the user can press the button in the bottom right corner to improve the text, including correcting typos.
:
In most cases, pressing the “Improve” button again will result in a variant of the text that the user may like better:
It is reasonable to include an "Undo" button as well. While it's not implemented in this example,
since our focus is on the OpenAI interface, it can be added without much difficulty by saving and restoring the GuiXT text variables, see
Undo and Redo buttons.
// Customer complaint ?
if Q[Transaction=QM01] or Q[Transaction=QM02]
// notification type Q1 ?
Set V[QM_notification_type] "&F[RIWO00-QMARTE]"
if V[QM_notification_type=Q1]
// add button to improve text via OpenAI
PushButton X[Text]+(5,78) _
"@IY\QImprove the text via OpenAI@" _
process="qm_improve_text.txt" size=(1,2)
endif
endif
InputScript "qm_improve_text.txt":
GuiXT
CopyText fromScreen=X[Text] toText="QM_longtext"
CallVB result = openai.openaihelper.askGPT _
"Can you please improve the following notification text
and only return the new text? &text[QM_longtext]"
if V[result]
CopyText fromString="result" toText="QM_longtext"
CopyText fromText="QM_longtext" toScreen=X[Text]
endif
Return
VB implementation:
VB.NET
Imports System.Collections.Generic
Imports System.Net.Http
Imports System.Security.Authentication
Imports System.Text
Imports System.Web.Script.Serialization
Public Class OpenAIHelper
Public apiKey As String = "sk-proj-4drnVX..."
Public apiUrl As String = "https://api.openai.com/v1/chat/completions"
Public Function askGPT(question) As String
Dim myclient = New HttpClient _
(New HttpClientHandler With {.SslProtocols = SslProtocols.Tls12})
myclient.DefaultRequestHeaders.Add _
("Authorization", $"Bearer {apiKey}")
Dim webRequest = New HttpRequestMessage(HttpMethod.Post, apiUrl)
Dim jsonPayload As String = "
{
""model"": ""gpt-4.1-mini"",
""messages"": [
{
""role"": ""user"",
""content"": ""$$question""
}
]
}"
Dim questionstring As String = question.replace("""", """""")
questionstring = questionstring.
replace(vbCrLf, "\n").replace(vbLf, "\n")
webRequest.Content =
New StringContent(jsonPayload.Replace("$$question", questionstring),
Encoding.UTF8, "application/json")
Dim response As HttpResponseMessage =
myclient.SendAsync(webRequest).Result
Dim content As String = response.Content.ReadAsStringAsync().Result
Dim contentdict As Dictionary(Of String, Object) =
New JavaScriptSerializer().DeserializeObject(content)
Dim result = contentdict("choices")(0)("message")("content")
Return result
End Function
End Class