将 ChatGPT 接入 Excel 中当函数,不用再把自己的资料上传到网上;不用再总是打开 ChatGPT 网站提问,来回往返于 Excel 表格之间。
相关代码Function ChatGPT(prompt As String) As String
Dim url As String, apiKey As String
Dim response As Object, re As String
Dim midString As String
apiKey = "your_api_key"
url = "https://api.openai.com/v1/engines/text-davinci-003/completions"
Set response = CreateObject("MSXML2.XMLHTTP")
response.Open "POST", url, False
response.setRequestHeader "Content-Type", "application/json"
response.setRequestHeader "Authorization", "Bearer " + apiKey
response.Send "{""prompt"":""" & prompt & """,""max_tokens"":1024, ""temperature"":0.1}"
re = response.responseText
midString = Mid(re, InStr(re, """text"":""") + 8)
ChatGPT = Split(midString, """")(0)
ChatGPT = Replace(ChatGPT, "\n", "")
End Function
Function ChatGPT(prompt As String) As String
Dim url As String, apiKey As String
Dim response As Object, re As String
Dim midString As String
apiKey = "your_api_key"
url = "https://api.openai.com/v1/engines/text-davinci-003/completions"
Set response = CreateObject("MSXML2.XMLHTTP")
response.Open "POST", url, False
response.setRequestHeader "Content-Type", "application/json"
response.setRequestHeader "Authorization", "Bearer " + apiKey
response.Send "{""prompt"":""" & prompt & """,""max_tokens"":1024, ""temperature"":0.1}"
re = response.responseText
midString = Mid(re, InStr(re, """text"":""") + 8)
ChatGPT = Split(midString, """")(0)
ChatGPT = Replace(ChatGPT, "\n", "")
End Function