I have been trying to use a HTTPSecureSocket to make a URL post to GPT3 using the openai url
The reason I’m doing this is because URLConnection.send has a bug where the HandleURL session crashes when the ContentReceived event has content greater than 200 bytes. So I decided to experiment with sockets directly.
Unfortunately it’s not working, or at least I can’t tell.
Here is my code:
var x as string
var sendString as string = gptquery
sendString = sendString.ReplaceLineEndings(“\n”)
s = “{” + EndOfLine
s = s + q + “model” + q + “:” +q + “text-davinci-003” + q + “,” + EndofLine
s = s + q + “prompt” + q + “:” +q + sendString+ q + “,” + EndofLine
s = s + q + “temperature” + q + “:” + “0” + “,” + EndofLine
s = s + q + “max_tokens” + q + “:” + “2000” + EndofLine
s = s + “}”
var bearer as string = “sk-98398n98ndisnfiubva8” //key string
Dim socket1 As New ASocket
socket1.SSLConnectionType = SSLSocket.SSLConnectionTypes.TLSv1
socket1.SetRequestHeader(“Accept-Encoding”, “application/json; charset=utf-8”)
socket1.SetRequestHeader(“Authorization”, bearer)
socket1.SetRequestContent(s, “application/json”)
socket1.Post(“https://api.openai.com/v1/completions”)
Dim start As Double = Microseconds
Dim endTime As Double = start + (1000000 * 300) // 1 second in microseconds
socket1.returnString = “–”
while(socket1.completeURL = false AND Microseconds < endTime)
App.DoEvents
wend
//dim result as string = parseGPTResults(jsonData)
return socket1.returnString
I created a Socket Class with a parent of HTTPSecureSocket
I added a PageReceived event which includes:
me.returnString = content
try
if content.IndexOf(“doctype”)=-1 then
if content.IndexOf(Chr(34) + “error” + Chr(34) + “:”)=-1 then
var json as New JSONItem(content)
var j as JSONItem = json.Value(“choices”)
var result0 as JSONItem = j.ValueAt(0)
var s As String = result0.Value(“text”)
me.returnString = s
end if
else
end if
catch e as JSONException
me.completeURL = true
me.returnString = e.Message
end try
me.completeURL = true
But the PageReceived event is never called.
The Error event is called with a code of 102
Does anyone have any ideas?