Problem with ChatGPT and Xojo Web App and WebTextArea

I am creating a simple port scanning program for charitable purposes for children to use. It’s web address is http://www.codenamesonar.app. The app resets and disconnects often, but this is not the main issue. When attempting to use ChatGPT it will disconnect every time on the server, a lightsail amazon server, and when it is on my home computer it only dictates half the information, I am including the code and image of what the webtextarea is show. Thanks in advance for any help any of yo can give me. The program is running on the newest version of Ubuntu LTS.

AIWindow.Enabled = True

Var tcpPort As Integer = txtPort.Text.ToInteger

Try
  Var gpt As New ChatGPTConnection
  Var response As String = gpt.ReplyToPrompt("What are basic and more advanced port vulnerabilities of TCP port " + tcpPort.ToString + "?")
  AIWindow.AIText.Text = gpt.ReplyToPrompt(response.ToText)
Catch e As ChatGPTException
  MessageBox("Error: " + e.Message)
End Try

AIWindow.Show

I also need to know what I need to update to get rid of the disconnects in Ubuntu LTS. Here is the ldd information from my program:
linux-vdso.so.1 (0x00007fff83f09000)
XojoConsoleFramework64.so => /var/XojoApps/CodenameSonar/./CodenameSonar Libs/XojoConsoleFramework64.so (0x00007c41a6200000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007c41a5e00000)
libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007c41a8857000)
libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007c41a60b7000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007c41a8852000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007c41a884b000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007c41a8846000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007c41a5d17000)
libunwind.so.8 => /lib/x86_64-linux-gnu/libunwind.so.8 (0x00007c41a882b000)
libunwind-x86_64.so.8 => /lib/x86_64-linux-gnu/libunwind-x86_64.so.8 (0x00007c41a609b000)
libc++.so.1 => /var/XojoApps/CodenameSonar/./CodenameSonar Libs/libc++.so.1 (0x00007c41a5600000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007c41a606e000)
/lib64/ld-linux-x86-64.so.2 (0x00007c41a88c2000)
libffi.so.8 => /lib/x86_64-linux-gnu/libffi.so.8 (0x00007c41a6062000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007c41a5c7d000)
liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007c41a6030000)

As well as this I need to know how to subtract the following characters from a textbox, & and | because of security risks from executing server side shell commands.

Thanks in Advance!
Kent M Borgos

Hi Kent, and welcome! I see you are establishing a request/response (ChatGPTConnection) connection, and trying to extract the response on the line immediately following the request.

Typically you’ll submit a request and then turn the handling over to the communications object to ‘receive’ the data - in your scenario, from what I can tell, your ‘receiver’ is falling out of scope before it’s able to receive/process the response. This could explain why you see differing lengths of returned data.

Thanks William! I am a little lost at that, I haven’t been programming for a long time, how should I got about fixing this?

Thanks Again William!!

Apologies, I spoke too soon. The communications for ChatGPT appears to be using a ChatGPTConnection Class, one I’m totally unfamiliar with, and it’s even in their documentation yet from what I can tell.

I opened the example and the ChatGPTConnection Class doesn’t appear to have all the traditional stub-outs for Events, such as ‘Error’ or ‘DataReceived’… so my advice will be of no use. Sorry for the false alarm.

I ended up using a python file and a shell to get it to work, what I think the problem was, was the the number of tokens, here is the source code to the python code…

import sys
import json
import requests

# Replace with your OpenAI API key
API_KEY = "API_KEY"

def query_openai_for_port_vulnerabilities(port_number):
    # Define the prompt to query OpenAI
    prompt = f"Provide a detailed and advanced explanation of vulnerabilities associated with port {port_number}."

    # Set up the OpenAI API request
    url = "https://api.openai.com/v1/chat/completions"
    headers = {
        "Content-Type": "application/json",
        "Authorization": f"Bearer {API_KEY}"
    }
    data = {
        "model": "gpt-4",
        "messages": [
            {"role": "system", "content": "You are a knowledgeable security expert."},
            {"role": "user", "content": prompt}
        ],
        "max_tokens": 4000,
        "temperature": 0.7
    }

    # Make the API request using requests library
    response = requests.post(url, headers=headers, json=data)

    # Parse and display the response
    if response.status_code == 200:
        response_json = response.json()
        if "choices" in response_json and len(response_json["choices"]) > 0:
            print("Port Vulnerabilities :")
            print(response_json["choices"][0]["message"]["content"].strip())
        else:
            print("No response from OpenAI.")
    else:
        print(f"Error making API request: {response.status_code}")
        print(response.text)

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("Usage: python query_openai.py <PORT_NUMBER>")
        sys.exit(1)

    port_number = sys.argv[1]

    query_openai_for_port_vulnerabilities(port_number)