I'm trying to connect Excel (via VBA) to our Azure OpenAI instance. Since there isn't an OpenAI library, I'm trying to manually set things like api_type, api_version, model, etc manually without much luck. Has anyone successfully accomplished this?
Here's my code with private info redacted.
Function myAI(thePrompt As String)
Dim MAX_TOKENS As String
Dim TEMPERATURE As String
Dim MODEL As String
Dim apiEndpoint
Dim apiKey
Dim response As String
apiEndpoint = <redacted>
apiKey = <redacted>
MAX_TOKENS = 800
TEMPERATURE = 0
MODEL = <redacted>
Dim requestBody As String
requestBody = "{" & _
"""model"": " & MODEL & "," & _
"""prompt"": """ & thePrompt & """," & _
"""max_tokens"": " & MAX_TOKENS & "," & _
"""temperature"": " & TEMPERATURE & _
"}"
Set httpObj = CreateObject("WinHttp.WinHttpRequest.5.1")
httpObj.SetTimeouts 90000, 90000, 90000, 90000
httpObj.Option(4) = 13056
httpObj.Open "POST", apiEndpoint, False
httpObj.setRequestHeader "Content-type", "application/json"
httpObj.setRequestHeader "Authorization", "Bearer " & apiKey
httpObj.Send requestBody
myAI = httpObj.responseText
End Function