I want to utilise Excel to send questions to ChatGPT and receive answers in a different cell. The API I have is shown in cell "A1." The answer should go in "A6," and the question should be removed from "A3":
Sub SendQuestionToGPT3()
'Declare variables
Dim request As Object
Dim response As String
Dim API As String
API = Worksheets("API").Range("A1").Value
'Set the question in a variable
Dim question As String
question = Range("A3").Value
'Create an HTTP request object
Set request = CreateObject("MSXML2.XMLHTTP")
'Set the API endpoint and make the request
request.Open "POST", "https://api.openai.com/v1/engines/davinci/jobs", False
request.setRequestHeader "Content-Type", "application/json"
request.setRequestHeader "Authorization", "Bearer " & API
request.send "{""prompt"":""" & question & """,""max_tokens"":1000}"
'Get the response and parse it into a string
response = request.responseText
response = Replace(response, ",""choices"":[]", "")
response = Replace(response, """text"":""", "")
response = Replace(response, """}", "")
'Display the response in a cell
Range("A6").Value = response
'Clean up the object
Set request = Nothing
End Sub
But I get this error back:
{ "error": { "message": "Unknown endpoint for this model.", "type": "invalid_request_error", "param": null, "code": null } }
What's wrong with this code?