Macro excel for creat function chatGPT

Why does the following code not work in Excel and gives an error?

Function ChatGPT(prompt As String) As String
Dim http As Object
Set http = CreateObject(“MSXML2.XMLHTTP”)

Dim apiKey As String
apiKey = "sk-xxxxxxx"  ' API Key 

http.Open "POST", "https://api.openai.com/v1/chat/completions", False
http.setRequestHeader "Content-Type", "application/json"
http.setRequestHeader "Authorization", "Bearer " & apiKey

Dim requestBody As String
requestBody = "{""model"":""gpt-3.5-turbo"",""messages"":[{""role"":""user"",""content"":""" & prompt & """}]}"

http.send requestBody

ChatGPT = http.responseText

End Function

2 Likes