By the way, this is a sample request that fully works, techniically at least, once you set in your API key.
Code:
Local loHTTP, lcURL, lcQuestion, lcResponse
* Set the OpenAI API endpoint
lcURL = "[URL unfurl="true"]https://api.openai.com/v1/chat/completions"[/URL]
* Set your OpenAI API key
lcApiKey = "[highlight #FCE94F]your API key here[/highlight]"
* Get user input
lcQuestion = Inputbox('Prompt','Your Prompt for ChatGPT','')
* Create the ServerXMLHTTP object
loHTTP = Createobject("MSXML2.ServerXMLHTTP")
* Set up the HTTP request
loHTTP.Open("POST", lcURL, .F.)
loHTTP.setRequestHeader("Content-Type", "application/json")
loHTTP.setRequestHeader("Authorization", "Bearer " + lcApiKey)
* Create the request payload
Text To lcPayload Textmerge Noshow
{
"model": "gpt-3.5-turbo",
"messages": [
{
"role": "system",
"content": "You are a helpful assistant."
},
{
"role": "user",
"content": "<<lcQuestion>>"
}
]
}
EndText
* Send the request
loHTTP.Send(lcPayload)
* Check for a successful response
If loHTTP.Status = 200
* Display the response
? "ChatGPT Response:"
? loHTTP.responseText
Else
* Display an error message if the request fails
? "Error:", loHttp.Status, loHTTP.statusText
? loHTTP.responseText
EndIf
? loHTTP.getAllResponseHeaders()
Just that I'm back to getting Error 429 Too Many Requests.
And I didn't make 200 requests today or 3 in the last minute.
If anybody is more successful with his/her account, I'd be glad to hear advice on how to get there. I think you have to go to tier 1 and pay at least $5 once, to get a bit of headroom. I'm actuallly not keen on giving out a credit card number just to be able to get this going, though.
One more questiuonable thing is that the response headers don't include what the documentation promises here:
You can see for yourself that the output of loHTTP.getAllResponseHeaders does not include any of the headers x-ratelimit-limit-requests, x-ratelimit-limit-tokens, x-ratelimit-remaining-requests, x-ratelimit-remaining-tokens, x-ratelimit-reset-requests or x-ratelimit-reset-tokens.
So a typical case of documentation being wrong or behind the actual implemnentation- or vice versa. For now, I'm done with this. You make a bad impression, OpenAI, on the level of developer support, at least.
Also, I have tried to use the so called playground (
which makes clear it's not some specialty of VFP or MSXML2.ServerXMLHTTP that hinders it to work. The playground also makes use of your account and API key, without needing to provide that code, but doing all things interactively under your account. And it also responds with rate limit exceeded.
I know, I should tell all this to OpenAI customer support and not here, I'm not that involved and happy to go there after Christmas, more likely next year, though.
So I wish you a Merry Christmas and a Happy New Year, may this work for you or be helpful to get started.
Chriss